linux-user/signal.c: Generate opcode data for restorer in setup_rt_frame
PATCH 1/1 linux-user/signal.c: Generate opcode data for restorer in setup_rt_frame
From: Chen Gang <[email protected]>
Original implementation uses do_rt_sigreturn directly in host space, when a guest program is in unwind procedure in guest space, it will get an incorrect restore address, then causes unwind failure.
Also cleanup the original incorrect indentation.
--- linux-user/signal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
linux-user/signal.c +10 -2
@@ -5566,8 +5566,13 @@ struct target_rt_sigframe {unsigned char save_area[16 ];/* caller save area */ struct target_siginfo info;struct target_ucontext uc; +abi_ulong retcode[2 ]; }; +#define INSN_MOVELI_R10_139 0x00045fe551483000ULL/* { moveli r10, 139 } */ +#define INSN_SWINT1 0x286b180051485000ULL/* { swint1 } */ + +static void setup_sigcontext (struct target_sigcontext *sc,CPUArchState *env,int signo) {
@@ -5643,9 +5648,12 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,__put_user (target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);setup_sigcontext (&frame->uc.tuc_mcontext, env, info->si_signo); - restorer = (unsigned long ) do_rt_sigreturn;if (ka->sa_flags &TARGET_SA_RESTORER ) { - restorer = (unsigned long ) ka->sa_restorer; + restorer = (unsigned long ) ka->sa_restorer; + }else { +__put_user (INSN_MOVELI_R10_139 , &frame->retcode[0 ]); +__put_user (INSN_SWINT1 , &frame->retcode[1 ]); + restorer = (unsigned long )frame->retcode; } env->pc = (unsigned long ) ka->_sa_handler; env->regs[TILEGX_R_SP ] = (unsigned long ) frame;
Signature · 1 line
1.9.3
Hello All:
Please help check this patch when you have time.
After this patch, we can let gcc testsuite cleanup-10 run successfully.
Next, I shall continue to implement floating point instructions: remove (u)int64_to_float64 from fdouble implementation.
Thanks.
Quoted 47 lines · On 3/15/16 05:51, [email protected] wrote:
From: Chen Gang <[email protected]>
Original implementation uses
do_rt_sigreturndirectly in host space, when a guest program is in unwind procedure in guest space, it will get an incorrect restore address, then causes unwind failure.Also cleanup the original incorrect indentation.
Signed-off-by Chen Gang <[email protected]>--- linux-user/signal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)linux-user/signal.c +10
-2@@ -5566,8 +5566,13 @@ struct target_rt_sigframe {unsigned char save_area[16 ];/* caller save area */ struct target_siginfo info;struct target_ucontext uc; +abi_ulong retcode[2 ]; }; +#define INSN_MOVELI_R10_139 0x00045fe551483000ULL/* { moveli r10, 139 } */ +#define INSN_SWINT1 0x286b180051485000ULL/* { swint1 } */ + +static void setup_sigcontext (struct target_sigcontext *sc,CPUArchState *env,int signo) {@@ -5643,9 +5648,12 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,__put_user (target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);setup_sigcontext (&frame->uc.tuc_mcontext, env, info->si_signo); - restorer = (unsigned long ) do_rt_sigreturn;if (ka->sa_flags &TARGET_SA_RESTORER ) { - restorer = (unsigned long ) ka->sa_restorer; + restorer = (unsigned long ) ka->sa_restorer; + }else { +__put_user (INSN_MOVELI_R10_139 , &frame->retcode[0 ]); +__put_user (INSN_SWINT1 , &frame->retcode[1 ]); + restorer = (unsigned long )frame->retcode; } env->pc = (unsigned long ) ka->_sa_handler; env->regs[TILEGX_R_SP ] = (unsigned long ) frame;
Signature · 3 lines
Chen Gang (陈刚) Managing Natural Environments is the Duty of Human Beings.
Quoted 48 lines · Chen Gang
Hello All:
Please help check this patch when you have time.
After this patch, we can let gcc testsuite cleanup-10 run successfully.
Next, I shall continue to implement floating point instructions: remove (u)int64_to_float64 from fdouble implementation.
Thanks.
Quoted 35 lines · On 3/15/16 05:51, [email protected] wrote:
From: Chen Gang <[email protected]>
Original implementation uses
do_rt_sigreturndirectly in host space, when a guest program is in unwind procedure in guest space, it will get an incorrect restore address, then causes unwind failure.Also cleanup the original incorrect indentation.
Signed-off-by Chen Gang <[email protected]>--- linux-user/signal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)linux-user/signal.c +5
-0@@ -5566,8 +5566,13 @@ struct target_rt_sigframe {unsigned char save_area[16 ];/* caller save area */ struct target_siginfo info;struct target_ucontext uc; +abi_ulong retcode[2 ]; }; +#define INSN_MOVELI_R10_139 0x00045fe551483000ULL/* { moveli r10, 139 } */ +#define INSN_SWINT1 0x286b180051485000ULL/* { swint1 } */ + +static void setup_sigcontext (struct target_sigcontext *sc,CPUArchState *env,int signo) {@@ -5643,9 +5648,12 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,__put_user (target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);setup_sigcontext (&frame->uc.tuc_mcontext, env, info->si_signo);
Quoted 8 lines
linux-user/signal.c static void setup_rt_frame(int sig, struct target_sigaction *ka, · line 5656
Quoted 8 lines
linux-user/signal.c +5
-2- restorer = (unsigned long ) do_rt_sigreturn;if (ka->sa_flags &TARGET_SA_RESTORER ) { - restorer = (unsigned long ) ka->sa_restorer; + restorer = (unsigned long ) ka->sa_restorer; + }else { +__put_user (INSN_MOVELI_R10_139 , &frame->retcode[0 ]); +__put_user (INSN_SWINT1 , &frame->retcode[1 ]); + restorer = (unsigned long )frame->retcode;
The address of retcode in host and guest can differ. You need something like:
restorer = (unsigned long)(frame_addr + offsetof(structtarget_rt_sigframe, retcode));
I've experienced this on sh4 (see commit 2a0fa68)
Quoted 5 lines
linux-user/signal.c static void setup_rt_frame(int sig, struct target_sigaction *ka, · line 5659
Quoted 4 lines
linux-user/signal.c +0
-0} env->pc = (unsigned long ) ka->_sa_handler; env->regs[TILEGX_R_SP ] = (unsigned long ) frame;
Laurent
Quoted 47 lines · Laurent Vivier
Quoted 35 lines · On 3/15/16 05:51, [email protected] wrote:
Quoted 34 lines
Original implementation uses
do_rt_sigreturndirectly in host space, when a guest program is in unwind procedure in guest space, it will get an incorrect restore address, then causes unwind failure.Also cleanup the original incorrect indentation.
Signed-off-by Chen Gang <[email protected]>--- linux-user/signal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)linux-user/signal.c +5
-0@@ -5566,8 +5566,13 @@ struct target_rt_sigframe {unsigned char save_area[16 ];/* caller save area */ struct target_siginfo info;struct target_ucontext uc; +abi_ulong retcode[2 ]; }; +#define INSN_MOVELI_R10_139 0x00045fe551483000ULL/* { moveli r10, 139 } */ +#define INSN_SWINT1 0x286b180051485000ULL/* { swint1 } */ + +static void setup_sigcontext (struct target_sigcontext *sc,CPUArchState *env,int signo) {@@ -5643,9 +5648,12 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,__put_user (target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);setup_sigcontext (&frame->uc.tuc_mcontext, env, info->si_signo);Quoted 8 lines
linux-user/signal.c static void setup_rt_frame(int sig, struct target_sigaction *ka, · line 5656
Quoted 8 lines
linux-user/signal.c +5
-2- restorer = (unsigned long ) do_rt_sigreturn;if (ka->sa_flags &TARGET_SA_RESTORER ) { - restorer = (unsigned long ) ka->sa_restorer; + restorer = (unsigned long ) ka->sa_restorer; + }else { +__put_user (INSN_MOVELI_R10_139 , &frame->retcode[0 ]); +__put_user (INSN_SWINT1 , &frame->retcode[1 ]); + restorer = (unsigned long )frame->retcode;The address of retcode in host and guest can differ. You need something like:
Quoted 5 lines
restorer = (unsigned long)(frame_addr + offsetof(struct
target_rt_sigframe, retcode));I've experienced this on sh4 (see commit 2a0fa68)
OK, thanks. What you said above sounds reasonable to me. :-)
I shall send patch v2 for it (although tilegx is a pure 64-bit target, with this patch, I guess, tilegx target should still run correctly under 32-bit host).
By the way, it looks that s390x and microblaze targets also have the same issue.
Thanks.
Signature · 3 lines
Chen Gang (陈刚) Managing Natural Environments is the Duty of Human Beings.
Quoted 11 lines · Chen Gang
Quoted 9 lines · Laurent Vivier
The address of retcode in host and guest can differ. You need something like:
restorer = (unsigned long)(frame_addr + offsetof(struct
target_rt_sigframe, retcode));I've experienced this on sh4 (see commit 2a0fa68)
Quoted 8 lines
OK, thanks. What you said above sounds reasonable to me. :-)
I shall send patch v2 for it (although tilegx is a pure 64-bit target, with this patch, I guess, tilegx target should still run correctly under 32-bit host).
By the way, it looks that s390x and microblaze targets also have the same issue.
It looks the alpha target may also need consider about retcode, for "r26 = frame_addr" in setup_rt_frame().
Thanks.
Signature · 3 lines
Chen Gang (陈刚) Managing Natural Environments is the Duty of Human Beings.