Skip to content

Commit

Permalink
linux-user: Move tswap_siginfo out of target code
Browse files Browse the repository at this point in the history
Move tswap_siginfo from target code to handle_pending_signal. This will
allow some cleanups and having the siginfo ready to be used in gdbstub.

Signed-off-by: Gustavo Romero <[email protected]>
Suggested-by: Richard Henderson <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
  • Loading branch information
gromero authored and stsquad committed Mar 13, 2024
1 parent b6617e9 commit 4d6d8a0
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion linux-user/aarch64/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
aarch64_set_svcr(env, 0, R_SVCR_SM_MASK | R_SVCR_ZA_MASK);

if (info) {
tswap_siginfo(&frame->info, info);
frame->info = *info;
env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
env->xregs[2] = frame_addr + offsetof(struct target_rt_sigframe, uc);
}
Expand Down
2 changes: 1 addition & 1 deletion linux-user/alpha/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}

tswap_siginfo(&frame->info, info);
frame->info = *info;

__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
Expand Down
2 changes: 1 addition & 1 deletion linux-user/arm/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void setup_rt_frame(int usig, struct target_sigaction *ka,

info_addr = frame_addr + offsetof(struct rt_sigframe, info);
uc_addr = frame_addr + offsetof(struct rt_sigframe, sig.uc);
tswap_siginfo(&frame->info, info);
frame->info = *info;

setup_sigframe(&frame->sig.uc, set, env);

Expand Down
2 changes: 1 addition & 1 deletion linux-user/hexagon/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}

setup_ucontext(&frame->uc, env, set);
tswap_siginfo(&frame->info, info);
frame->info = *info;
/*
* The on-stack signal trampoline is no longer executed;
* however, the libgcc signal frame unwinding code checks
Expand Down
2 changes: 1 addition & 1 deletion linux-user/hppa/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}

tswap_siginfo(&frame->info, info);
frame->info = *info;
frame->uc.tuc_flags = 0;
frame->uc.tuc_link = 0;

Expand Down
6 changes: 3 additions & 3 deletions linux-user/i386/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0],
frame_addr + offsetof(struct sigframe, fpstate));

for(i = 1; i < TARGET_NSIG_WORDS; i++) {
for (i = 1; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->extramask[i - 1]);
}

Expand Down Expand Up @@ -490,7 +490,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(addr, &frame->puc);
#endif
if (ka->sa_flags & TARGET_SA_SIGINFO) {
tswap_siginfo(&frame->info, info);
frame->info = *info;
}

/* Create the ucontext. */
Expand All @@ -504,7 +504,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env,
set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate));

for(i = 0; i < TARGET_NSIG_WORDS; i++) {
for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion linux-user/loongarch64/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
extctx.end.haddr = (void *)frame + (extctx.end.gaddr - frame_addr);
}

tswap_siginfo(&frame->rs_info, info);
frame->rs_info = *info;

__put_user(0, &frame->rs_uc.tuc_flags);
__put_user(0, &frame->rs_uc.tuc_link);
Expand Down
4 changes: 2 additions & 2 deletions linux-user/m68k/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);
__put_user(uc_addr, &frame->puc);

tswap_siginfo(&frame->info, info);
frame->info = *info;

/* Create the ucontext */

Expand All @@ -307,7 +307,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
if (err)
goto give_sigsegv;

for(i = 0; i < TARGET_NSIG_WORDS; i++) {
for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion linux-user/microblaze/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
return;
}

tswap_siginfo(&frame->info, info);
frame->info = *info;

__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
Expand Down
4 changes: 2 additions & 2 deletions linux-user/mips/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}

tswap_siginfo(&frame->rs_info, info);
frame->rs_info = *info;

__put_user(0, &frame->rs_uc.tuc_flags);
__put_user(0, &frame->rs_uc.tuc_link);
target_save_altstack(&frame->rs_uc.tuc_stack, env);

setup_sigcontext(env, &frame->rs_uc.tuc_mcontext);

for(i = 0; i < TARGET_NSIG_WORDS; i++) {
for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->rs_uc.tuc_sigmask.sig[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion linux-user/nios2/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
return;
}

tswap_siginfo(&frame->info, info);
frame->info = *info;

/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
Expand Down
2 changes: 1 addition & 1 deletion linux-user/openrisc/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}

if (ka->sa_flags & SA_SIGINFO) {
tswap_siginfo(&frame->info, info);
frame->info = *info;
}

__put_user(0, &frame->uc.tuc_flags);
Expand Down
4 changes: 2 additions & 2 deletions linux-user/ppc/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
if (!lock_user_struct(VERIFY_WRITE, rt_sf, rt_sf_addr, 1))
goto sigsegv;

tswap_siginfo(&rt_sf->info, info);
rt_sf->info = *info;

__put_user(0, &rt_sf->uc.tuc_flags);
__put_user(0, &rt_sf->uc.tuc_link);
Expand All @@ -502,7 +502,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(h2g (&rt_sf->uc.tuc_mcontext),
&rt_sf->uc.tuc_regs);
#endif
for(i = 0; i < TARGET_NSIG_WORDS; i++) {
for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &rt_sf->uc.tuc_sigmask.sig[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion linux-user/riscv/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}

setup_ucontext(&frame->uc, env, set);
tswap_siginfo(&frame->info, info);
frame->info = *info;

env->pc = ka->_sa_handler;
env->gpr[xSP] = frame_addr;
Expand Down
2 changes: 1 addition & 1 deletion linux-user/s390x/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}

/* Create siginfo on the signal stack. */
tswap_siginfo(&frame->info, info);
frame->info = *info;

/* Create ucontext on the signal stack. */
uc_flags = 0;
Expand Down
2 changes: 1 addition & 1 deletion linux-user/sh4/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}

tswap_siginfo(&frame->info, info);
frame->info = *info;

/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
Expand Down
2 changes: 0 additions & 2 deletions linux-user/signal-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ void host_to_target_sigset_internal(target_sigset_t *d,
const sigset_t *s);
void target_to_host_sigset_internal(sigset_t *d,
const target_sigset_t *s);
void tswap_siginfo(target_siginfo_t *tinfo,
const target_siginfo_t *info);
void set_sigmask(const sigset_t *set);
void force_sig(int sig);
void force_sigsegv(int oldsig);
Expand Down
10 changes: 8 additions & 2 deletions linux-user/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
tinfo->si_code = deposit32(si_code, 16, 16, si_type);
}

void tswap_siginfo(target_siginfo_t *tinfo,
const target_siginfo_t *info)
static void tswap_siginfo(target_siginfo_t *tinfo,
const target_siginfo_t *info)
{
int si_type = extract32(info->si_code, 16, 16);
int si_code = sextract32(info->si_code, 0, 16);
Expand Down Expand Up @@ -1178,6 +1178,12 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
/* dequeue signal */
k->pending = 0;

/*
* Writes out siginfo values byteswapped, accordingly to the target. It also
* cleans the si_type from si_code making it correct for the target.
*/
tswap_siginfo(&k->info, &k->info);

sig = gdb_handlesig(cpu, sig, NULL);
if (!sig) {
sa = NULL;
Expand Down
2 changes: 1 addition & 1 deletion linux-user/sparc/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,

__put_user(0, &sf->rwin_save); /* TODO: save_rwin_state */

tswap_siginfo(&sf->info, info);
sf->info = *info;
tswap_sigset(&sf->mask, set);
target_save_altstack(&sf->stack, env);

Expand Down
2 changes: 1 addition & 1 deletion linux-user/xtensa/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}

if (ka->sa_flags & SA_SIGINFO) {
tswap_siginfo(&frame->info, info);
frame->info = *info;
}

__put_user(0, &frame->uc.tuc_flags);
Expand Down

0 comments on commit 4d6d8a0

Please sign in to comment.