From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fencepost.gnu.org (fencepost.gnu.org [IPv6:2001:470:142:3::e]) by sourceware.org (Postfix) with ESMTPS id 5EA5D3858D34 for ; Fri, 1 Mar 2024 01:33:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EA5D3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5EA5D3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709256795; cv=none; b=nCew4iaEShEONiOK/nVZxgYIavOCVZPcjhfHt77/iYr0/5I1oI2wXEztS0L/j5EWmRT05sxk4GYm2gZr1g25Xgicelqw6B8IsTWJx/+WLNIjWiidjeXOmEo2UazBRVMsObrLFgpIC6qLsXZ2r/a2SyRzjUKH6lw4wW4qqR0RFqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709256795; c=relaxed/simple; bh=WYGWo42T/jOxVbJj1CwrPU7wXjXzzu+9sckaIP1hBVo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=QFyfHCA4uP7W3xBdAlPgewQgzeCr9LWjD3WTHo6ioEe2N5Vs59oxiCHNZ/c4JnON06H/FLlHRZ43RAzMkp6MTtXDA5XscyfYbpj201KgWAakkuqr5CeFEu0K46MuoR8oP5EaszxEKADdR3d7RjEpDi1tlwNS5DNcxRlf7OTgaaE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=vcu3/TRRE1OWZRMu5u+66T1XwAUCWe3PZAejwB6I1Fs=; b=cfZMHKYbvc4sznO/Ufzf DS16wjowyHhUzWXCJg1rlrWdDd9LorLQkSnxh2o5CvVQhDlIbWUOaG06xWy4pMupu+FnEPqB7nHZV TbsigupWrZodReZsjM+94U8jiZgYXLojGRJiCLHttr1asWvm1Fmzg3GEMMfeamZqGNnl5/RjWjLPF 0FxmsHYltcMPYZDahpKEu2SG8MBHcB8NaYr/JpVr7qdQhrWjgCAKoaYbuPuOAEc06D9FJpX7gdvab tQueaabMyxO0xQtwk1qoJicpeKf9/FuzjBno/77HPg+bNyom0BlKGTx37ZRk2OypBRF/zDTDuSAva bDU9SYE9qwtRgg==; Date: Fri, 1 Mar 2024 02:33:10 +0100 From: Samuel Thibault To: Flavio Cruz Cc: bug-hurd@gnu.org, gcc-patches@gcc.gnu.org, thomas@codesourcery.com Subject: Re: [PATCH gcc] Hurd x86_64: add unwind support for signal trampoline code Message-ID: <20240301013310.rqpolnjwcxxqdtm6@begin> Mail-Followup-To: Flavio Cruz , bug-hurd@gnu.org, gcc-patches@gcc.gnu.org, thomas@codesourcery.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Flavio Cruz, le mer. 28 févr. 2024 22:59:09 -0500, a ecrit: > Tested with some simple toy examples where an exception is thrown in the > signal handler. > > libgcc/ChangeLog: > * config/i386/gnu-unwind.h: Support unwinding x86_64 signal frames. > > Signed-off-by: Flavio Cruz Reviewed-by: Samuel Thibault Thanks!! > --- > libgcc/config/i386/gnu-unwind.h | 97 ++++++++++++++++++++++++++++++++- > 1 file changed, 94 insertions(+), 3 deletions(-) > > diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h > index 0751b5593d4..02b060ab4a5 100644 > --- a/libgcc/config/i386/gnu-unwind.h > +++ b/libgcc/config/i386/gnu-unwind.h > @@ -32,9 +32,100 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see > > #ifdef __x86_64__ > > -/* > - * TODO: support for 64 bits needs to be implemented. > - */ > +#define MD_FALLBACK_FRAME_STATE_FOR x86_gnu_fallback_frame_state > + > +static _Unwind_Reason_Code > +x86_gnu_fallback_frame_state > +(struct _Unwind_Context *context, _Unwind_FrameState *fs) > +{ > + static const unsigned char gnu_sigtramp_code[] = > + { > + /* rpc_wait_trampoline: */ > + 0x48, 0xc7, 0xc0, 0xe7, 0xff, 0xff, 0xff, /* mov $-25,%rax */ > + 0x0f, 0x05, /* syscall */ > + 0x49, 0x89, 0x04, 0x24, /* mov %rax,(%r12) */ > + 0x48, 0x89, 0xdc, /* mov %rbx,%rsp */ > + > + /* trampoline: */ > + 0x5f, /* pop %rdi */ > + 0x5e, /* pop %rsi */ > + 0x5a, /* pop %rdx */ > + 0x48, 0x83, 0xc4, 0x08, /* add $0x8,%rsp */ > + 0x41, 0xff, 0xd5, /* call *%r13 */ > + > + /* RA HERE */ > + 0x48, 0x8b, 0x7c, 0x24, 0x10, /* mov 0x10(%rsp),%rdi */ > + 0xc3, /* ret */ > + > + /* firewall: */ > + 0xf4, /* hlt */ > + }; > + > + const size_t gnu_sigtramp_len = sizeof gnu_sigtramp_code; > + const size_t gnu_sigtramp_tail = 7; /* length of tail after RA */ > + > + struct stack_contents { > + void *sigreturn_addr; > + void *sigreturn_returns_here; > + struct sigcontext *return_scp; > + } *stack_contents; > + struct sigcontext *scp; > + unsigned long usp; > + > + unsigned char *adjusted_pc = (unsigned char*)(context->ra) + > + gnu_sigtramp_tail - gnu_sigtramp_len; > + if (memcmp (adjusted_pc, gnu_sigtramp_code, gnu_sigtramp_len)) > + return _URC_END_OF_STACK; > + > + stack_contents = context->cfa; > + > + scp = stack_contents->return_scp; > + usp = scp->sc_ursp; > + > + fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_rax - usp; > + fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_rdx - usp; > + fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_rcx - usp; > + fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_rbx - usp; > + fs->regs.reg[4].loc.offset = (unsigned long)&scp->sc_rsi - usp; > + fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_rdi - usp; > + fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_rbp - usp; > + fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_r8 - usp; > + fs->regs.reg[9].loc.offset = (unsigned long)&scp->sc_r9 - usp; > + fs->regs.reg[10].loc.offset = (unsigned long)&scp->sc_r10 - usp; > + fs->regs.reg[11].loc.offset = (unsigned long)&scp->sc_r11 - usp; > + fs->regs.reg[12].loc.offset = (unsigned long)&scp->sc_r12 - usp; > + fs->regs.reg[13].loc.offset = (unsigned long)&scp->sc_r13 - usp; > + fs->regs.reg[14].loc.offset = (unsigned long)&scp->sc_r14 - usp; > + fs->regs.reg[15].loc.offset = (unsigned long)&scp->sc_r15 - usp; > + fs->regs.reg[16].loc.offset = (unsigned long)&scp->sc_rip - usp; > + > + /* Register 7 is rsp */ > + fs->regs.cfa_how = CFA_REG_OFFSET; > + fs->regs.cfa_reg = 7; > + fs->regs.cfa_offset = usp - (unsigned long) context->cfa; > + > + fs->regs.how[0] = REG_SAVED_OFFSET; > + fs->regs.how[1] = REG_SAVED_OFFSET; > + fs->regs.how[2] = REG_SAVED_OFFSET; > + fs->regs.how[3] = REG_SAVED_OFFSET; > + fs->regs.how[4] = REG_SAVED_OFFSET; > + fs->regs.how[5] = REG_SAVED_OFFSET; > + fs->regs.how[6] = REG_SAVED_OFFSET; > + fs->regs.how[8] = REG_SAVED_OFFSET; > + fs->regs.how[9] = REG_SAVED_OFFSET; > + fs->regs.how[10] = REG_SAVED_OFFSET; > + fs->regs.how[11] = REG_SAVED_OFFSET; > + fs->regs.how[12] = REG_SAVED_OFFSET; > + fs->regs.how[13] = REG_SAVED_OFFSET; > + fs->regs.how[14] = REG_SAVED_OFFSET; > + fs->regs.how[15] = REG_SAVED_OFFSET; > + fs->regs.how[16] = REG_SAVED_OFFSET; > + > + fs->retaddr_column = 16; > + fs->signal_frame = 1; > + > + return _URC_NO_REASON; > +} > > #else /* ifdef __x86_64__ */ > > -- > 2.43.0 > > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.