[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] linux-user/riscv: fix up struct target_ucontext definition
From: |
LIU Zhiwei |
Subject: |
Re: [PATCH] linux-user/riscv: fix up struct target_ucontext definition |
Date: |
Wed, 22 Apr 2020 10:34:11 +0800 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
Ping.
When I port RISU, I find this bug. I can't get the correct registers
from the
struct ucontext_t parameter in the signal handler.
If you want to reproduce it, just register a signal handler for
SIGILL,
and output an illegal instruction, such as
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <signal.h>
#include <ucontext.h>
void sigill(int sig, siginfo_t *si, void *uc)
{
printf("Illegal pc: %016" PRIx64 "\n",
((ucontext_t *)uc)->uc_mcontext.__gregs[0]);
}
static void set_sigill_handler(void (*fn) (int, siginfo_t *, void *))
{
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = fn;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGILL, &sa, 0) != 0) {
perror("sigaction");
exit(1);
}
}
int main()
{
set_sigill_handler(sigill);
asm(".dword 0x0000006b");
return 0;
}
~
Zhiwei
On 2020/4/12 10:08, LIU Zhiwei wrote:
As struct target_ucontext will be transfered to signal handler, it
must keep pace with struct ucontext_t defined in Linux kernel.
Signed-off-by: LIU Zhiwei <address@hidden>
---
linux-user/riscv/signal.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c
index 83ecc6f799..67a95dbc7b 100644
--- a/linux-user/riscv/signal.c
+++ b/linux-user/riscv/signal.c
@@ -40,8 +40,9 @@ struct target_ucontext {
unsigned long uc_flags;
struct target_ucontext *uc_link;
target_stack_t uc_stack;
- struct target_sigcontext uc_mcontext;
target_sigset_t uc_sigmask;
+ uint8_t __unused[1024 / 8 - sizeof(target_sigset_t)];
+ struct target_sigcontext uc_mcontext QEMU_ALIGNED(16);
};
struct target_rt_sigframe {