From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYdZl-00026p-0I for qemu-devel@nongnu.org; Fri, 11 Apr 2014 11:41:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYdZe-000416-DH for qemu-devel@nongnu.org; Fri, 11 Apr 2014 11:41:08 -0400 Received: from mail-qc0-x236.google.com ([2607:f8b0:400d:c01::236]:61671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYdZe-00040A-9l for qemu-devel@nongnu.org; Fri, 11 Apr 2014 11:41:02 -0400 Received: by mail-qc0-f182.google.com with SMTP id e16so6170328qcx.27 for ; Fri, 11 Apr 2014 08:41:01 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Fri, 11 Apr 2014 08:40:03 -0700 Message-Id: <1397230827-24222-2-git-send-email-rth@twiddle.net> In-Reply-To: <1397230827-24222-1-git-send-email-rth@twiddle.net> References: <1397230827-24222-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH v4 01/25] tcg-aarch64: Properly detect SIGSEGV writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: claudio.fontana@huawei.com Since the kernel doesn't pass any info on the reason for the fault, disassemble the instruction to detect a store. Signed-off-by: Richard Henderson --- user-exec.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/user-exec.c b/user-exec.c index bc58056..c7106a6 100644 --- a/user-exec.c +++ b/user-exec.c @@ -465,16 +465,33 @@ int cpu_signal_handler(int host_signum, void *pinfo, #elif defined(__aarch64__) -int cpu_signal_handler(int host_signum, void *pinfo, - void *puc) +int cpu_signal_handler(int host_signum, void *pinfo, void *puc) { siginfo_t *info = pinfo; struct ucontext *uc = puc; - uint64_t pc; - int is_write = 0; /* XXX how to determine? */ + uintptr_t pc = uc->uc_mcontext.pc; + uint32_t insn = *(uint32_t *)pc; + bool is_write; - pc = uc->uc_mcontext.pc; - return handle_cpu_signal(pc, (uint64_t)info->si_addr, + /* XXX: need kernel patch to get write flag faster. */ + /* XXX: several of these could be combined. */ + is_write = ( (insn & 0xbfff0000) == 0x0c000000 /* C3.3.1 */ + || (insn & 0xbfe00000) == 0x0c800000 /* C3.3.2 */ + || (insn & 0xbfdf0000) == 0x0d000000 /* C3.3.3 */ + || (insn & 0xbfc00000) == 0x0d800000 /* C3.3.4 */ + || (insn & 0x3f400000) == 0x08000000 /* C3.3.6 */ + || (insn & 0x3bc00000) == 0x28000000 /* C3.3.7 */ + || (insn & 0x3be00c00) == 0x38000400 /* C3.3.8 */ + || (insn & 0x3be00c00) == 0x38000c00 /* C3.3.9 */ + || (insn & 0x3be00c00) == 0x38200800 /* C3.3.10 */ + || (insn & 0x3be00c00) == 0x38000800 /* C3.3.11 */ + || (insn & 0x3be00c00) == 0x38000000 /* C3.3.12 */ + || (insn & 0x3bc00000) == 0x39000000 /* C3.3.13 */ + || (insn & 0x3bc00000) == 0x29000000 /* C3.3.14 */ + || (insn & 0x3bc00000) == 0x28800000 /* C3.3.15 */ + || (insn & 0x3bc00000) == 0x29800000); /* C3.3.16 */ + + return handle_cpu_signal(pc, (uintptr_t)info->si_addr, is_write, &uc->uc_sigmask, puc); } -- 1.9.0