linux-user/m68k: Implement setup_sigtramp

Create and record the two signal trampolines.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210929130553.121567-13-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2021-09-29 09:05:39 -04:00 committed by Laurent Vivier
parent db20554159
commit 5125aced7c
2 changed files with 24 additions and 25 deletions

View File

@ -39,7 +39,6 @@ struct target_sigframe
int sig; int sig;
int code; int code;
abi_ulong psc; abi_ulong psc;
char retcode[8];
abi_ulong extramask[TARGET_NSIG_WORDS-1]; abi_ulong extramask[TARGET_NSIG_WORDS-1];
struct target_sigcontext sc; struct target_sigcontext sc;
}; };
@ -76,7 +75,6 @@ struct target_rt_sigframe
int sig; int sig;
abi_ulong pinfo; abi_ulong pinfo;
abi_ulong puc; abi_ulong puc;
char retcode[8];
struct target_siginfo info; struct target_siginfo info;
struct target_ucontext uc; struct target_ucontext uc;
}; };
@ -130,7 +128,6 @@ void setup_frame(int sig, struct target_sigaction *ka,
{ {
struct target_sigframe *frame; struct target_sigframe *frame;
abi_ulong frame_addr; abi_ulong frame_addr;
abi_ulong retcode_addr;
abi_ulong sc_addr; abi_ulong sc_addr;
int i; int i;
@ -152,16 +149,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
} }
/* Set up to return from userspace. */ /* Set up to return from userspace. */
__put_user(default_sigreturn, &frame->pretcode);
retcode_addr = frame_addr + offsetof(struct target_sigframe, retcode);
__put_user(retcode_addr, &frame->pretcode);
/* moveq #,d0; trap #0 */
__put_user(0x70004e40 + (TARGET_NR_sigreturn << 16),
(uint32_t *)(frame->retcode));
/* Set up to return from userspace */
env->aregs[7] = frame_addr; env->aregs[7] = frame_addr;
env->pc = ka->_sa_handler; env->pc = ka->_sa_handler;
@ -288,7 +276,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
{ {
struct target_rt_sigframe *frame; struct target_rt_sigframe *frame;
abi_ulong frame_addr; abi_ulong frame_addr;
abi_ulong retcode_addr;
abi_ulong info_addr; abi_ulong info_addr;
abi_ulong uc_addr; abi_ulong uc_addr;
int err = 0; int err = 0;
@ -325,17 +312,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
} }
/* Set up to return from userspace. */ /* Set up to return from userspace. */
__put_user(default_rt_sigreturn, &frame->pretcode);
retcode_addr = frame_addr + offsetof(struct target_sigframe, retcode);
__put_user(retcode_addr, &frame->pretcode);
/* moveq #,d0; notb d0; trap #0 */
__put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16),
(uint32_t *)(frame->retcode + 0));
__put_user(0x4e40, (uint16_t *)(frame->retcode + 4));
/* Set up to return from userspace */
env->aregs[7] = frame_addr; env->aregs[7] = frame_addr;
env->pc = ka->_sa_handler; env->pc = ka->_sa_handler;
@ -411,3 +388,23 @@ badframe:
force_sig(TARGET_SIGSEGV); force_sig(TARGET_SIGSEGV);
return -TARGET_QEMU_ESIGRETURN; return -TARGET_QEMU_ESIGRETURN;
} }
void setup_sigtramp(abi_ulong sigtramp_page)
{
void *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 4 + 6, 0);
assert(tramp != NULL);
default_sigreturn = sigtramp_page;
/* moveq #,d0; trap #0 */
__put_user(0x70004e40 + (TARGET_NR_sigreturn << 16), (uint32_t *)tramp);
default_rt_sigreturn = sigtramp_page + 4;
/* moveq #,d0; notb d0; trap #0 */
__put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16),
(uint32_t *)(tramp + 4));
__put_user(0x4e40, (uint16_t *)(tramp + 8));
unlock_user(tramp, sigtramp_page, 4 + 6);
}

View File

@ -22,4 +22,6 @@ typedef struct target_sigaltstack {
#include "../generic/signal.h" #include "../generic/signal.h"
#define TARGET_ARCH_HAS_SETUP_FRAME #define TARGET_ARCH_HAS_SETUP_FRAME
#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
#endif /* M68K_TARGET_SIGNAL_H */ #endif /* M68K_TARGET_SIGNAL_H */