public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] hurd: libgcc unwinding support over signal trampolines
@ 2020-05-29 11:46 Samuel Thibault
  2020-06-06 21:42 ` Samuel Thibault
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Samuel Thibault @ 2020-05-29 11:46 UTC (permalink / raw)
  To: gcc-patches, bug-hurd

[-- Attachment #1: Type: text/plain, Size: 141 bytes --]

Hello,

libgcc is currently missing the support for unwinding over signal
trampolines on GNU/Hurd. The attached patch implements it.

Samuel

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 5456 bytes --]

hurd: libgcc unwinding support over signal trampolines

* libgcc/config.host (md_unwind_header): Set to i386/gnu-unwind.h on
i[34567]86-*-gnu*.
* src/libgcc/config/i386/gnu-unwind.h: New file.

diff --git a/libgcc/config.host b/libgcc/config.host
index 2cd42097167..044b34d53cc 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -734,11 +734,17 @@ i[34567]86-*-linux*)
 	tm_file="${tm_file} i386/elf-lib.h"
 	md_unwind_header=i386/linux-unwind.h
 	;;
-i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
+i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
 	tm_file="${tm_file} i386/elf-lib.h"
 	;;
+i[34567]86-*-gnu*)
+	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
+	tm_file="${tm_file} i386/elf-lib.h"
+	md_unwind_header=i386/gnu-unwind.h
+	;;
 x86_64-*-linux*)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff --git a/src/libgcc/config/i386/gnu-unwind.h b/src/libgcc/config/i386/gnu-unwind.h
new file mode 100644
index 00000000000..db47f0ac1d4
--- /dev/null
+++ b/src/libgcc/config/i386/gnu-unwind.h
@@ -0,0 +1,107 @@
+/* DWARF2 EH unwinding support for GNU Hurd: x86.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Do code reading to identify a signal frame, and set the frame
+   state data appropriately.  See unwind-dw2.c for the structs. */
+
+#ifndef inhibit_libc
+
+#include <signal.h>
+
+#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)
+{
+  struct handler_args {
+    int signo;
+    int sigcode;
+    struct sigcontext *scp;
+  } *handler_args;
+  struct sigcontext *scp;
+  unsigned long usp;
+
+/*
+ * i386 sigtramp frame we are looking for follows.
+ * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
+ *
+ * rpc_wait_trampoline:
+ *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
+ *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
+ *  12:	89 01                	movl   %eax, (%ecx)
+ *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
+ *
+ * trampoline:
+ *  16:	ff d2                	call   *%edx           call the handler function
+ * RA HERE
+ *  18:	83 c4 0c             	addl   $12, %esp       pop its args
+ *  21:	c3                   	ret                    return to sigreturn
+ *
+ * firewall:
+ *  22:	f4                   	hlt
+ */
+
+  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
+        && *(unsigned char  *)(context->ra +  4) ==       0xf4
+
+        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
+        && *(unsigned int   *)(context->ra -  8) == 0x01890007
+        && *(unsigned int   *)(context->ra - 12) == 0x00000000
+        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
+        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
+    return _URC_END_OF_STACK;
+
+  handler_args = context->cfa;
+  scp = handler_args->scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.cfa_how = CFA_REG_OFFSET;
+  fs->regs.cfa_reg = 4;
+  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
+
+  fs->regs.reg[0].how = REG_SAVED_OFFSET;
+  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+  fs->regs.reg[1].how = REG_SAVED_OFFSET;
+  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+  fs->regs.reg[2].how = REG_SAVED_OFFSET;
+  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+  fs->regs.reg[3].how = REG_SAVED_OFFSET;
+  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+  fs->regs.reg[5].how = REG_SAVED_OFFSET;
+  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+  fs->regs.reg[6].how = REG_SAVED_OFFSET;
+  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+  fs->regs.reg[7].how = REG_SAVED_OFFSET;
+  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+  fs->regs.reg[8].how = REG_SAVED_OFFSET;
+  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+  fs->retaddr_column = 8;
+  fs->signal_frame = 1;
+
+  return _URC_NO_REASON;
+}
+
+#endif /* ifndef inhibit_libc */

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding support over signal trampolines
  2020-05-29 11:46 [PATCH] hurd: libgcc unwinding support over signal trampolines Samuel Thibault
@ 2020-06-06 21:42 ` Samuel Thibault
  2020-06-08 10:15 ` Thomas Schwinge
  2020-12-21 14:09 ` [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO Samuel Thibault
  2 siblings, 0 replies; 12+ messages in thread
From: Samuel Thibault @ 2020-06-06 21:42 UTC (permalink / raw)
  To: gcc-patches, bug-hurd

Hello,

Any news on this?

Samuel

Samuel Thibault, le ven. 29 mai 2020 13:46:50 +0200, a ecrit:
> Hello,
> 
> libgcc is currently missing the support for unwinding over signal
> trampolines on GNU/Hurd. The attached patch implements it.
> 
> Samuel

> hurd: libgcc unwinding support over signal trampolines
> 
> * libgcc/config.host (md_unwind_header): Set to i386/gnu-unwind.h on
> i[34567]86-*-gnu*.
> * src/libgcc/config/i386/gnu-unwind.h: New file.
> 
> diff --git a/libgcc/config.host b/libgcc/config.host
> index 2cd42097167..044b34d53cc 100644
> --- a/libgcc/config.host
> +++ b/libgcc/config.host
> @@ -734,11 +734,17 @@ i[34567]86-*-linux*)
>  	tm_file="${tm_file} i386/elf-lib.h"
>  	md_unwind_header=i386/linux-unwind.h
>  	;;
> -i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
> +i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
>  	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
>  	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
>  	tm_file="${tm_file} i386/elf-lib.h"
>  	;;
> +i[34567]86-*-gnu*)
> +	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
> +	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
> +	tm_file="${tm_file} i386/elf-lib.h"
> +	md_unwind_header=i386/gnu-unwind.h
> +	;;
>  x86_64-*-linux*)
>  	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
>  	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
> diff --git a/src/libgcc/config/i386/gnu-unwind.h b/src/libgcc/config/i386/gnu-unwind.h
> new file mode 100644
> index 00000000000..db47f0ac1d4
> --- /dev/null
> +++ b/src/libgcc/config/i386/gnu-unwind.h
> @@ -0,0 +1,107 @@
> +/* DWARF2 EH unwinding support for GNU Hurd: x86.
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +Under Section 7 of GPL version 3, you are granted additional
> +permissions described in the GCC Runtime Library Exception, version
> +3.1, as published by the Free Software Foundation.
> +
> +You should have received a copy of the GNU General Public License and
> +a copy of the GCC Runtime Library Exception along with this program;
> +see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Do code reading to identify a signal frame, and set the frame
> +   state data appropriately.  See unwind-dw2.c for the structs. */
> +
> +#ifndef inhibit_libc
> +
> +#include <signal.h>
> +
> +#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)
> +{
> +  struct handler_args {
> +    int signo;
> +    int sigcode;
> +    struct sigcontext *scp;
> +  } *handler_args;
> +  struct sigcontext *scp;
> +  unsigned long usp;
> +
> +/*
> + * i386 sigtramp frame we are looking for follows.
> + * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
> + *
> + * rpc_wait_trampoline:
> + *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
> + *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
> + *  12:	89 01                	movl   %eax, (%ecx)
> + *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
> + *
> + * trampoline:
> + *  16:	ff d2                	call   *%edx           call the handler function
> + * RA HERE
> + *  18:	83 c4 0c             	addl   $12, %esp       pop its args
> + *  21:	c3                   	ret                    return to sigreturn
> + *
> + * firewall:
> + *  22:	f4                   	hlt
> + */
> +
> +  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
> +        && *(unsigned char  *)(context->ra +  4) ==       0xf4
> +
> +        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
> +        && *(unsigned int   *)(context->ra -  8) == 0x01890007
> +        && *(unsigned int   *)(context->ra - 12) == 0x00000000
> +        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
> +        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
> +    return _URC_END_OF_STACK;
> +
> +  handler_args = context->cfa;
> +  scp = handler_args->scp;
> +  usp = scp->sc_uesp;
> +
> +  fs->regs.cfa_how = CFA_REG_OFFSET;
> +  fs->regs.cfa_reg = 4;
> +  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
> +
> +  fs->regs.reg[0].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
> +  fs->regs.reg[1].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
> +  fs->regs.reg[2].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
> +  fs->regs.reg[3].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
> +  fs->regs.reg[5].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
> +  fs->regs.reg[6].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
> +  fs->regs.reg[7].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
> +  fs->regs.reg[8].how = REG_SAVED_OFFSET;
> +  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
> +  fs->retaddr_column = 8;
> +  fs->signal_frame = 1;
> +
> +  return _URC_NO_REASON;
> +}
> +
> +#endif /* ifndef inhibit_libc */


-- 
Samuel
<c> xlnt comme sujet de stage je peux essayer de donner une description formelle de automake
 -+- #ens-mim -+-

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding support over signal trampolines
  2020-05-29 11:46 [PATCH] hurd: libgcc unwinding support over signal trampolines Samuel Thibault
  2020-06-06 21:42 ` Samuel Thibault
@ 2020-06-08 10:15 ` Thomas Schwinge
  2020-06-08 11:36   ` Samuel Thibault
  2020-12-21 14:09 ` [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO Samuel Thibault
  2 siblings, 1 reply; 12+ messages in thread
From: Thomas Schwinge @ 2020-06-08 10:15 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: gcc-patches, bug-hurd

Hi Samuel!

On 2020-05-29T13:46:50+0200, Samuel Thibault <samuel.thibault@gnu.org> wrote:
> libgcc is currently missing the support for unwinding over signal
> trampolines on GNU/Hurd.

ACK.  Has been on my long TODO list for a long time.  ;-)

> The attached patch implements it.

Thanks!

I'm not intimately familiar with the unwinding implementation, but your
changes look quite what I'd have guessed they'd look like, and also
somewhat similar to 'libgcc/config/i386/linux-unwind.h'.  (I'll get
there, eventually, again..., but) I'm not currently set up to test this,
but I'll assume you have.

Which GCC branches would you like this on?

> --- /dev/null
> +++ b/src/libgcc/config/i386/gnu-unwind.h
> @@ -0,0 +1,107 @@

> + * i386 sigtramp frame we are looking for follows.
> + * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
> + *
> + * rpc_wait_trampoline:
> + *   0:      b8 e7 ff ff ff          mov    $-25,%eax       mach_msg_trap
> + *   5:      9a 00 00 00 00 07 00    lcall  $7,$0
> + *  12:      89 01                   movl   %eax, (%ecx)
> + *  14:      89 dc                   movl   %ebx, %esp      switch to signal stack
> + *
> + * trampoline:
> + *  16:      ff d2                   call   *%edx           call the handler function
> + * RA HERE
> + *  18:      83 c4 0c                addl   $12, %esp       pop its args
> + *  21:      c3                      ret                    return to sigreturn
> + *
> + * firewall:
> + *  22:      f4                      hlt
> + */
> +
> +  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
> +        && *(unsigned char  *)(context->ra +  4) ==       0xf4
> +
> +        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
> +        && *(unsigned int   *)(context->ra -  8) == 0x01890007
> +        && *(unsigned int   *)(context->ra - 12) == 0x00000000
> +        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
> +        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
> +    return _URC_END_OF_STACK;

Once we've got this in GCC, please then also cross-reference GCC's
'libgcc/config/i386/gnu-unwind.h' file in glibc's
'sysdeps/mach/hurd/i386/trampoline.c' file.


Grüße
 Thomas
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding support over signal trampolines
  2020-06-08 10:15 ` Thomas Schwinge
@ 2020-06-08 11:36   ` Samuel Thibault
  2020-06-08 11:49     ` Samuel Thibault
  0 siblings, 1 reply; 12+ messages in thread
From: Samuel Thibault @ 2020-06-08 11:36 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: gcc-patches, bug-hurd

Thomas Schwinge, le lun. 08 juin 2020 12:15:12 +0200, a ecrit:
> I'm not currently set up to test this, but I'll assume you have.

Sure :)

> Which GCC branches would you like this on?

Ideally it's be backported to gcc 9 and 10, so that it lands naturally
in the Debian packages without having to bother doko.

> Once we've got this in GCC, please then also cross-reference GCC's
> 'libgcc/config/i386/gnu-unwind.h' file in glibc's
> 'sysdeps/mach/hurd/i386/trampoline.c' file.

Ah, yes, I thought about it and forgot, will do.

Samuel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding support over signal trampolines
  2020-06-08 11:36   ` Samuel Thibault
@ 2020-06-08 11:49     ` Samuel Thibault
  2020-06-17 22:10       ` Thomas Schwinge
  0 siblings, 1 reply; 12+ messages in thread
From: Samuel Thibault @ 2020-06-08 11:49 UTC (permalink / raw)
  To: Thomas Schwinge, gcc-patches, bug-hurd

Samuel Thibault, le lun. 08 juin 2020 13:36:55 +0200, a ecrit:
> Thomas Schwinge, le lun. 08 juin 2020 12:15:12 +0200, a ecrit:
> > Which GCC branches would you like this on?
> 
> Ideally it's be backported to gcc 9 and 10, so that it lands naturally
> in the Debian packages without having to bother doko.

Actually only gcc 10 would be needed.

Samuel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding support over signal trampolines
  2020-06-08 11:49     ` Samuel Thibault
@ 2020-06-17 22:10       ` Thomas Schwinge
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Schwinge @ 2020-06-17 22:10 UTC (permalink / raw)
  To: Samuel Thibault, gcc-patches, bug-hurd

[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]

Hi!

On 2020-06-08T13:49:55+0200, Samuel Thibault <samuel.thibault@gnu.org> wrote:
> Samuel Thibault, le lun. 08 juin 2020 13:36:55 +0200, a ecrit:
>> Thomas Schwinge, le lun. 08 juin 2020 12:15:12 +0200, a ecrit:
>> > Which GCC branches would you like this on?
>>
>> Ideally it's be backported to gcc 9 and 10, so that it lands naturally
>> in the Debian packages without having to bother doko.
>
> Actually only gcc 10 would be needed.

Well, it was easy enough to just put it onto all active branches, so I've
now pushed "hurd: libgcc unwinding support over signal trampolines" to
master branch in commit 5e2eebc80d6eeca24745c27a925afdb64292ed22,
releases/gcc-10 branch in commit
a2b187c13919987ca0444ab7c701f9f93ee536c2, releases/gcc-9 branch in commit
cd32b2c51b913eed517e9503009fb3f0822d9cab, releases/gcc-8 branch in commit
9c5787ea072e16f26c9950139c00ae28fddadd72, see attached.


Grüße
 Thomas


-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-hurd-libgcc-unwinding-support-over-signal-trampoline.patch --]
[-- Type: text/x-diff, Size: 5908 bytes --]

From 5e2eebc80d6eeca24745c27a925afdb64292ed22 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Fri, 29 May 2020 13:46:50 +0200
Subject: [PATCH] hurd: libgcc unwinding support over signal trampolines

	libgcc/
	* config.host (md_unwind_header) <i[34567]86-*-gnu*>: Set to
	'i386/gnu-unwind.h'
	* config/i386/gnu-unwind.h: New file.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
---
 libgcc/config.host              |   8 ++-
 libgcc/config/i386/gnu-unwind.h | 107 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 libgcc/config/i386/gnu-unwind.h

diff --git a/libgcc/config.host b/libgcc/config.host
index 2cd420971675..044b34d53ccd 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -734,11 +734,17 @@ i[34567]86-*-linux*)
 	tm_file="${tm_file} i386/elf-lib.h"
 	md_unwind_header=i386/linux-unwind.h
 	;;
-i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
+i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
 	tm_file="${tm_file} i386/elf-lib.h"
 	;;
+i[34567]86-*-gnu*)
+	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
+	tm_file="${tm_file} i386/elf-lib.h"
+	md_unwind_header=i386/gnu-unwind.h
+	;;
 x86_64-*-linux*)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
new file mode 100644
index 000000000000..db47f0ac1d4b
--- /dev/null
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -0,0 +1,107 @@
+/* DWARF2 EH unwinding support for GNU Hurd: x86.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Do code reading to identify a signal frame, and set the frame
+   state data appropriately.  See unwind-dw2.c for the structs. */
+
+#ifndef inhibit_libc
+
+#include <signal.h>
+
+#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)
+{
+  struct handler_args {
+    int signo;
+    int sigcode;
+    struct sigcontext *scp;
+  } *handler_args;
+  struct sigcontext *scp;
+  unsigned long usp;
+
+/*
+ * i386 sigtramp frame we are looking for follows.
+ * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
+ *
+ * rpc_wait_trampoline:
+ *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
+ *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
+ *  12:	89 01                	movl   %eax, (%ecx)
+ *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
+ *
+ * trampoline:
+ *  16:	ff d2                	call   *%edx           call the handler function
+ * RA HERE
+ *  18:	83 c4 0c             	addl   $12, %esp       pop its args
+ *  21:	c3                   	ret                    return to sigreturn
+ *
+ * firewall:
+ *  22:	f4                   	hlt
+ */
+
+  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
+        && *(unsigned char  *)(context->ra +  4) ==       0xf4
+
+        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
+        && *(unsigned int   *)(context->ra -  8) == 0x01890007
+        && *(unsigned int   *)(context->ra - 12) == 0x00000000
+        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
+        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
+    return _URC_END_OF_STACK;
+
+  handler_args = context->cfa;
+  scp = handler_args->scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.cfa_how = CFA_REG_OFFSET;
+  fs->regs.cfa_reg = 4;
+  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
+
+  fs->regs.reg[0].how = REG_SAVED_OFFSET;
+  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+  fs->regs.reg[1].how = REG_SAVED_OFFSET;
+  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+  fs->regs.reg[2].how = REG_SAVED_OFFSET;
+  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+  fs->regs.reg[3].how = REG_SAVED_OFFSET;
+  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+  fs->regs.reg[5].how = REG_SAVED_OFFSET;
+  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+  fs->regs.reg[6].how = REG_SAVED_OFFSET;
+  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+  fs->regs.reg[7].how = REG_SAVED_OFFSET;
+  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+  fs->regs.reg[8].how = REG_SAVED_OFFSET;
+  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+  fs->retaddr_column = 8;
+  fs->signal_frame = 1;
+
+  return _URC_NO_REASON;
+}
+
+#endif /* ifndef inhibit_libc */
-- 
2.27.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-hurd-libgcc-unwinding-support-over-signal-trampo.g10.patch --]
[-- Type: text/x-diff, Size: 5977 bytes --]

From a2b187c13919987ca0444ab7c701f9f93ee536c2 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Fri, 29 May 2020 13:46:50 +0200
Subject: [PATCH] hurd: libgcc unwinding support over signal trampolines

	libgcc/
	* config.host (md_unwind_header) <i[34567]86-*-gnu*>: Set to
	'i386/gnu-unwind.h'
	* config/i386/gnu-unwind.h: New file.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
(cherry picked from commit 5e2eebc80d6eeca24745c27a925afdb64292ed22)
---
 libgcc/config.host              |   8 ++-
 libgcc/config/i386/gnu-unwind.h | 107 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 libgcc/config/i386/gnu-unwind.h

diff --git a/libgcc/config.host b/libgcc/config.host
index 1ff41592337e..c529cc40f0c8 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -743,11 +743,17 @@ i[34567]86-*-linux*)
 	tm_file="${tm_file} i386/elf-lib.h"
 	md_unwind_header=i386/linux-unwind.h
 	;;
-i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
+i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
 	tm_file="${tm_file} i386/elf-lib.h"
 	;;
+i[34567]86-*-gnu*)
+	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
+	tm_file="${tm_file} i386/elf-lib.h"
+	md_unwind_header=i386/gnu-unwind.h
+	;;
 x86_64-*-linux*)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
new file mode 100644
index 000000000000..db47f0ac1d4b
--- /dev/null
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -0,0 +1,107 @@
+/* DWARF2 EH unwinding support for GNU Hurd: x86.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Do code reading to identify a signal frame, and set the frame
+   state data appropriately.  See unwind-dw2.c for the structs. */
+
+#ifndef inhibit_libc
+
+#include <signal.h>
+
+#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)
+{
+  struct handler_args {
+    int signo;
+    int sigcode;
+    struct sigcontext *scp;
+  } *handler_args;
+  struct sigcontext *scp;
+  unsigned long usp;
+
+/*
+ * i386 sigtramp frame we are looking for follows.
+ * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
+ *
+ * rpc_wait_trampoline:
+ *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
+ *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
+ *  12:	89 01                	movl   %eax, (%ecx)
+ *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
+ *
+ * trampoline:
+ *  16:	ff d2                	call   *%edx           call the handler function
+ * RA HERE
+ *  18:	83 c4 0c             	addl   $12, %esp       pop its args
+ *  21:	c3                   	ret                    return to sigreturn
+ *
+ * firewall:
+ *  22:	f4                   	hlt
+ */
+
+  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
+        && *(unsigned char  *)(context->ra +  4) ==       0xf4
+
+        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
+        && *(unsigned int   *)(context->ra -  8) == 0x01890007
+        && *(unsigned int   *)(context->ra - 12) == 0x00000000
+        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
+        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
+    return _URC_END_OF_STACK;
+
+  handler_args = context->cfa;
+  scp = handler_args->scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.cfa_how = CFA_REG_OFFSET;
+  fs->regs.cfa_reg = 4;
+  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
+
+  fs->regs.reg[0].how = REG_SAVED_OFFSET;
+  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+  fs->regs.reg[1].how = REG_SAVED_OFFSET;
+  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+  fs->regs.reg[2].how = REG_SAVED_OFFSET;
+  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+  fs->regs.reg[3].how = REG_SAVED_OFFSET;
+  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+  fs->regs.reg[5].how = REG_SAVED_OFFSET;
+  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+  fs->regs.reg[6].how = REG_SAVED_OFFSET;
+  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+  fs->regs.reg[7].how = REG_SAVED_OFFSET;
+  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+  fs->regs.reg[8].how = REG_SAVED_OFFSET;
+  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+  fs->retaddr_column = 8;
+  fs->signal_frame = 1;
+
+  return _URC_NO_REASON;
+}
+
+#endif /* ifndef inhibit_libc */
-- 
2.27.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-hurd-libgcc-unwinding-support-over-signal-trampol.g9.patch --]
[-- Type: text/x-diff, Size: 5977 bytes --]

From cd32b2c51b913eed517e9503009fb3f0822d9cab Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Fri, 29 May 2020 13:46:50 +0200
Subject: [PATCH] hurd: libgcc unwinding support over signal trampolines

	libgcc/
	* config.host (md_unwind_header) <i[34567]86-*-gnu*>: Set to
	'i386/gnu-unwind.h'
	* config/i386/gnu-unwind.h: New file.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
(cherry picked from commit 5e2eebc80d6eeca24745c27a925afdb64292ed22)
---
 libgcc/config.host              |   8 ++-
 libgcc/config/i386/gnu-unwind.h | 107 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 libgcc/config/i386/gnu-unwind.h

diff --git a/libgcc/config.host b/libgcc/config.host
index 18e306b48a52..bdbf77a3e629 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -679,11 +679,17 @@ i[34567]86-*-linux*)
 	tm_file="${tm_file} i386/elf-lib.h"
 	md_unwind_header=i386/linux-unwind.h
 	;;
-i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
+i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
 	tm_file="${tm_file} i386/elf-lib.h"
 	;;
+i[34567]86-*-gnu*)
+	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
+	tm_file="${tm_file} i386/elf-lib.h"
+	md_unwind_header=i386/gnu-unwind.h
+	;;
 x86_64-*-linux*)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
new file mode 100644
index 000000000000..db47f0ac1d4b
--- /dev/null
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -0,0 +1,107 @@
+/* DWARF2 EH unwinding support for GNU Hurd: x86.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Do code reading to identify a signal frame, and set the frame
+   state data appropriately.  See unwind-dw2.c for the structs. */
+
+#ifndef inhibit_libc
+
+#include <signal.h>
+
+#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)
+{
+  struct handler_args {
+    int signo;
+    int sigcode;
+    struct sigcontext *scp;
+  } *handler_args;
+  struct sigcontext *scp;
+  unsigned long usp;
+
+/*
+ * i386 sigtramp frame we are looking for follows.
+ * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
+ *
+ * rpc_wait_trampoline:
+ *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
+ *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
+ *  12:	89 01                	movl   %eax, (%ecx)
+ *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
+ *
+ * trampoline:
+ *  16:	ff d2                	call   *%edx           call the handler function
+ * RA HERE
+ *  18:	83 c4 0c             	addl   $12, %esp       pop its args
+ *  21:	c3                   	ret                    return to sigreturn
+ *
+ * firewall:
+ *  22:	f4                   	hlt
+ */
+
+  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
+        && *(unsigned char  *)(context->ra +  4) ==       0xf4
+
+        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
+        && *(unsigned int   *)(context->ra -  8) == 0x01890007
+        && *(unsigned int   *)(context->ra - 12) == 0x00000000
+        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
+        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
+    return _URC_END_OF_STACK;
+
+  handler_args = context->cfa;
+  scp = handler_args->scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.cfa_how = CFA_REG_OFFSET;
+  fs->regs.cfa_reg = 4;
+  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
+
+  fs->regs.reg[0].how = REG_SAVED_OFFSET;
+  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+  fs->regs.reg[1].how = REG_SAVED_OFFSET;
+  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+  fs->regs.reg[2].how = REG_SAVED_OFFSET;
+  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+  fs->regs.reg[3].how = REG_SAVED_OFFSET;
+  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+  fs->regs.reg[5].how = REG_SAVED_OFFSET;
+  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+  fs->regs.reg[6].how = REG_SAVED_OFFSET;
+  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+  fs->regs.reg[7].how = REG_SAVED_OFFSET;
+  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+  fs->regs.reg[8].how = REG_SAVED_OFFSET;
+  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+  fs->retaddr_column = 8;
+  fs->signal_frame = 1;
+
+  return _URC_NO_REASON;
+}
+
+#endif /* ifndef inhibit_libc */
-- 
2.27.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0001-hurd-libgcc-unwinding-support-over-signal-trampol.g8.patch --]
[-- Type: text/x-diff, Size: 5977 bytes --]

From 9c5787ea072e16f26c9950139c00ae28fddadd72 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Fri, 29 May 2020 13:46:50 +0200
Subject: [PATCH] hurd: libgcc unwinding support over signal trampolines

	libgcc/
	* config.host (md_unwind_header) <i[34567]86-*-gnu*>: Set to
	'i386/gnu-unwind.h'
	* config/i386/gnu-unwind.h: New file.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
(cherry picked from commit 5e2eebc80d6eeca24745c27a925afdb64292ed22)
---
 libgcc/config.host              |   8 ++-
 libgcc/config/i386/gnu-unwind.h | 107 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 libgcc/config/i386/gnu-unwind.h

diff --git a/libgcc/config.host b/libgcc/config.host
index e436ade1a68c..677173eee432 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -651,11 +651,17 @@ i[34567]86-*-linux*)
 	tm_file="${tm_file} i386/elf-lib.h"
 	md_unwind_header=i386/linux-unwind.h
 	;;
-i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
+i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
 	tm_file="${tm_file} i386/elf-lib.h"
 	;;
+i[34567]86-*-gnu*)
+	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
+	tm_file="${tm_file} i386/elf-lib.h"
+	md_unwind_header=i386/gnu-unwind.h
+	;;
 x86_64-*-linux*)
 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
 	tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules"
diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
new file mode 100644
index 000000000000..db47f0ac1d4b
--- /dev/null
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -0,0 +1,107 @@
+/* DWARF2 EH unwinding support for GNU Hurd: x86.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Samuel Thibault <samuel.thibault@gnu.org>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Do code reading to identify a signal frame, and set the frame
+   state data appropriately.  See unwind-dw2.c for the structs. */
+
+#ifndef inhibit_libc
+
+#include <signal.h>
+
+#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)
+{
+  struct handler_args {
+    int signo;
+    int sigcode;
+    struct sigcontext *scp;
+  } *handler_args;
+  struct sigcontext *scp;
+  unsigned long usp;
+
+/*
+ * i386 sigtramp frame we are looking for follows.
+ * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
+ *
+ * rpc_wait_trampoline:
+ *   0:	b8 e7 ff ff ff       	mov    $-25,%eax       mach_msg_trap
+ *   5:	9a 00 00 00 00 07 00 	lcall  $7,$0
+ *  12:	89 01                	movl   %eax, (%ecx)
+ *  14:	89 dc                	movl   %ebx, %esp      switch to signal stack
+ *
+ * trampoline:
+ *  16:	ff d2                	call   *%edx           call the handler function
+ * RA HERE
+ *  18:	83 c4 0c             	addl   $12, %esp       pop its args
+ *  21:	c3                   	ret                    return to sigreturn
+ *
+ * firewall:
+ *  22:	f4                   	hlt
+ */
+
+  if (!(   *(unsigned int   *)(context->ra     ) == 0xc30cc483
+        && *(unsigned char  *)(context->ra +  4) ==       0xf4
+
+        && *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
+        && *(unsigned int   *)(context->ra -  8) == 0x01890007
+        && *(unsigned int   *)(context->ra - 12) == 0x00000000
+        && *(unsigned int   *)(context->ra - 16) == 0x9affffff
+        && *(unsigned short *)(context->ra - 18) ==     0xe7b8))
+    return _URC_END_OF_STACK;
+
+  handler_args = context->cfa;
+  scp = handler_args->scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.cfa_how = CFA_REG_OFFSET;
+  fs->regs.cfa_reg = 4;
+  fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
+
+  fs->regs.reg[0].how = REG_SAVED_OFFSET;
+  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+  fs->regs.reg[1].how = REG_SAVED_OFFSET;
+  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+  fs->regs.reg[2].how = REG_SAVED_OFFSET;
+  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+  fs->regs.reg[3].how = REG_SAVED_OFFSET;
+  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+  fs->regs.reg[5].how = REG_SAVED_OFFSET;
+  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+  fs->regs.reg[6].how = REG_SAVED_OFFSET;
+  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+  fs->regs.reg[7].how = REG_SAVED_OFFSET;
+  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+  fs->regs.reg[8].how = REG_SAVED_OFFSET;
+  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+  fs->retaddr_column = 8;
+  fs->signal_frame = 1;
+
+  return _URC_NO_REASON;
+}
+
+#endif /* ifndef inhibit_libc */
-- 
2.27.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO
  2020-05-29 11:46 [PATCH] hurd: libgcc unwinding support over signal trampolines Samuel Thibault
  2020-06-06 21:42 ` Samuel Thibault
  2020-06-08 10:15 ` Thomas Schwinge
@ 2020-12-21 14:09 ` Samuel Thibault
  2020-12-21 14:21   ` Jessica Clarke
  2 siblings, 1 reply; 12+ messages in thread
From: Samuel Thibault @ 2020-12-21 14:09 UTC (permalink / raw)
  To: gcc-patches, Thomas Schwinge; +Cc: bug-hurd

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

libgcc/
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the posix
siginfo case to struct handler_args. Detect between legacy and siginfo from
the second parameter, which is a small sigcode in the legacy case, and a
pointer in the siginfo case.

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..3eefe7de7e5 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO
  2020-12-21 14:09 ` [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO Samuel Thibault
@ 2020-12-21 14:21   ` Jessica Clarke
  2020-12-21 14:25     ` Samuel Thibault
  0 siblings, 1 reply; 12+ messages in thread
From: Jessica Clarke @ 2020-12-21 14:21 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: gcc-patches, Thomas Schwinge, bug-hurd

On 21 Dec 2020, at 14:09, Samuel Thibault <samuel.thibault@gnu.org> wrote:
> @@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
>     return _URC_END_OF_STACK;
> 
>   handler_args = context->cfa;
> -  scp = handler_args->scp;
> -  usp = scp->sc_uesp;
> +  sigcode = handler_args->legacy.sigcode;
> +  if (sigcode < 4096)

Do you not need >= 0 to handle the 3/1 split correctly?

Jess


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO
  2020-12-21 14:21   ` Jessica Clarke
@ 2020-12-21 14:25     ` Samuel Thibault
  2020-12-21 14:36       ` [PATCHv2] " Samuel Thibault
  0 siblings, 1 reply; 12+ messages in thread
From: Samuel Thibault @ 2020-12-21 14:25 UTC (permalink / raw)
  To: Jessica Clarke; +Cc: gcc-patches, Thomas Schwinge, bug-hurd

Jessica Clarke, le lun. 21 déc. 2020 14:21:39 +0000, a ecrit:
> On 21 Dec 2020, at 14:09, Samuel Thibault <samuel.thibault@gnu.org> wrote:
> > @@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
> >     return _URC_END_OF_STACK;
> > 
> >   handler_args = context->cfa;
> > -  scp = handler_args->scp;
> > -  usp = scp->sc_uesp;
> > +  sigcode = handler_args->legacy.sigcode;
> > +  if (sigcode < 4096)
> 
> Do you not need >= 0 to handle the 3/1 split correctly?

Ah, right, that's an signed integer, I'll add that.

Thanks,
Samuel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCHv2] hurd: libgcc unwinding over signal trampolines with SIGINFO
@ 2020-12-21 14:36       ` Samuel Thibault
  2021-01-11  0:00         ` Samuel Thibault
  2021-01-13 11:02         ` Thomas Schwinge
  0 siblings, 2 replies; 12+ messages in thread
From: Samuel Thibault @ 2020-12-21 14:36 UTC (permalink / raw)
  To: gcc-patches, Thomas Schwinge; +Cc: bug-hurd

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

libgcc/
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the posix
siginfo case to struct handler_args. Detect between legacy and siginfo from
the second parameter, which is a small sigcode in the legacy case, and a
pointer in the siginfo case.

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv2] hurd: libgcc unwinding over signal trampolines with SIGINFO
  2020-12-21 14:36       ` [PATCHv2] " Samuel Thibault
@ 2021-01-11  0:00         ` Samuel Thibault
  2021-01-13 11:02         ` Thomas Schwinge
  1 sibling, 0 replies; 12+ messages in thread
From: Samuel Thibault @ 2021-01-11  0:00 UTC (permalink / raw)
  To: gcc-patches, Thomas Schwinge, bug-hurd

Ping?

Samuel Thibault, le lun. 21 déc. 2020 15:36:30 +0100, a ecrit:

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

libgcc/
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the posix
siginfo case to struct handler_args. Detect between legacy and siginfo from
the second parameter, which is a small sigcode in the legacy case, and a
pointer in the siginfo case.

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv2] hurd: libgcc unwinding over signal trampolines with SIGINFO
  2020-12-21 14:36       ` [PATCHv2] " Samuel Thibault
  2021-01-11  0:00         ` Samuel Thibault
@ 2021-01-13 11:02         ` Thomas Schwinge
  1 sibling, 0 replies; 12+ messages in thread
From: Thomas Schwinge @ 2021-01-13 11:02 UTC (permalink / raw)
  To: Samuel Thibault, gcc-patches; +Cc: bug-hurd, Jessica Clarke

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

Hi!

On 2020-12-21T15:36:30+0100, Samuel Thibault <samuel.thibault@gnu.org> wrote:
> When the application sets SA_SIGINFO, the signal trampoline parameters
> are different to follow POSIX.

Thanks (and sorry for the delay), pushed "hurd: libgcc unwinding over
signal trampolines with SIGINFO" to master branch in commit
2b356e689c334ca4765a9ffd95a76cf715447200, and cherry-picked into
releases/gcc-10 branch in commit
2c4d3e6db8583c83f4252bb0c78b85f174420a90, releases/gcc-9 branch in commit
23b1bb7b22aa23a1f096448c319856cbeb720082, releases/gcc-8 branch in commit
c6c6d1d33533a3107bec0bf6f149761b4084d8b4, see attached.


Grüße
 Thomas


-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-hurd-libgcc-unwinding-over-signal-trampolines-with-S.patch --]
[-- Type: text/x-diff, Size: 4268 bytes --]

From 2b356e689c334ca4765a9ffd95a76cf715447200 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Mon, 21 Dec 2020 15:36:30 +0100
Subject: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

	libgcc/
	* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the
	posix siginfo case to struct handler_args. Detect between legacy
	and siginfo from the second parameter, which is a small sigcode in
	the legacy case, and a pointer in the siginfo case.
---
 libgcc/config/i386/gnu-unwind.h | 60 ++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index d69d07c1c80..0632348d4cd 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 
-- 
2.17.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-hurd-libgcc-unwinding-over-signal-trampolines-wi.g10.patch --]
[-- Type: text/x-diff, Size: 4338 bytes --]

From 2c4d3e6db8583c83f4252bb0c78b85f174420a90 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Mon, 21 Dec 2020 15:36:30 +0100
Subject: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

	libgcc/
	* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the
	posix siginfo case to struct handler_args. Detect between legacy
	and siginfo from the second parameter, which is a small sigcode in
	the legacy case, and a pointer in the siginfo case.

(cherry picked from commit 2b356e689c334ca4765a9ffd95a76cf715447200)
---
 libgcc/config/i386/gnu-unwind.h | 60 ++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 
-- 
2.17.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-hurd-libgcc-unwinding-over-signal-trampolines-wit.g9.patch --]
[-- Type: text/x-diff, Size: 4338 bytes --]

From 23b1bb7b22aa23a1f096448c319856cbeb720082 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Mon, 21 Dec 2020 15:36:30 +0100
Subject: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

	libgcc/
	* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the
	posix siginfo case to struct handler_args. Detect between legacy
	and siginfo from the second parameter, which is a small sigcode in
	the legacy case, and a pointer in the siginfo case.

(cherry picked from commit 2b356e689c334ca4765a9ffd95a76cf715447200)
---
 libgcc/config/i386/gnu-unwind.h | 60 ++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 
-- 
2.17.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0001-hurd-libgcc-unwinding-over-signal-trampolines-wit.g8.patch --]
[-- Type: text/x-diff, Size: 4338 bytes --]

From c6c6d1d33533a3107bec0bf6f149761b4084d8b4 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@gnu.org>
Date: Mon, 21 Dec 2020 15:36:30 +0100
Subject: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

	libgcc/
	* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the
	posix siginfo case to struct handler_args. Detect between legacy
	and siginfo from the second parameter, which is a small sigcode in
	the legacy case, and a pointer in the siginfo case.

(cherry picked from commit 2b356e689c334ca4765a9ffd95a76cf715447200)
---
 libgcc/config/i386/gnu-unwind.h | 60 ++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
     int signo;
-    int sigcode;
-    struct sigcontext *scp;
+    union
+      {
+	struct
+	  {
+	    long int sigcode;
+	    struct sigcontext *scp;
+	  } legacy;
+	struct
+	  {
+	    siginfo_t *siginfop;
+	    ucontext_t *uctxp;
+	  } posix;
+      };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
     return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+    {
+      /* This cannot be a SIGINFO pointer, assume legacy.  */
+      struct sigcontext *scp = handler_args->legacy.scp;
+      usp = scp->sc_uesp;
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+    }
+  else
+    {
+      /* This is not a valid sigcode, assume SIGINFO.  */
+      ucontext_t *uctxp = handler_args->posix.uctxp;
+      gregset_t *gregset = &uctxp->uc_mcontext.gregs;
+      usp = (*gregset)[REG_UESP];
+
+      fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+      fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+      fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+      fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+      fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+      fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+      fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+      fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+    }
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-01-13 11:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 11:46 [PATCH] hurd: libgcc unwinding support over signal trampolines Samuel Thibault
2020-06-06 21:42 ` Samuel Thibault
2020-06-08 10:15 ` Thomas Schwinge
2020-06-08 11:36   ` Samuel Thibault
2020-06-08 11:49     ` Samuel Thibault
2020-06-17 22:10       ` Thomas Schwinge
2020-12-21 14:09 ` [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO Samuel Thibault
2020-12-21 14:21   ` Jessica Clarke
2020-12-21 14:25     ` Samuel Thibault
2020-12-21 14:36       ` [PATCHv2] " Samuel Thibault
2021-01-11  0:00         ` Samuel Thibault
2021-01-13 11:02         ` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).