diff mbox series

[2/4] hurd: Align signal stack pointer after allocating stackframe

Message ID 20230515083323.1358039-3-bugaevc@gmail.com
State New
Headers show
Series x86_64-gnu signal fixes | expand

Commit Message

Sergey Bugaev May 15, 2023, 8:33 a.m. UTC
sizeof (*stackframe) appears to be divisible by 16, but we should not
rely on that. So make sure to leave enough space for the stackframe
first, and then align the final pointer at 16 bytes.

Checked on x86_64-gnu.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 sysdeps/mach/hurd/x86/trampoline.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Samuel Thibault May 15, 2023, 4:27 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev via Libc-alpha, le lun. 15 mai 2023 11:33:21 +0300, a ecrit:
> sizeof (*stackframe) appears to be divisible by 16, but we should not
> rely on that. So make sure to leave enough space for the stackframe
> first, and then align the final pointer at 16 bytes.
> 
> Checked on x86_64-gnu.
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
>  sysdeps/mach/hurd/x86/trampoline.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/mach/hurd/x86/trampoline.c b/sysdeps/mach/hurd/x86/trampoline.c
> index 19bddad8..1f92064e 100644
> --- a/sysdeps/mach/hurd/x86/trampoline.c
> +++ b/sysdeps/mach/hurd/x86/trampoline.c
> @@ -196,15 +196,14 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action
>  #endif
>      }
>  
> +  /* Push the arguments to call `trampoline' on the stack.  */
> +  sigsp -= sizeof (*stackframe);
>  #ifdef __x86_64__
>    /* Align SP at 16 bytes.  Coupled with the fact that sigreturn_addr is
>       16-byte aligned within the stackframe struct, this ensures that it ends
>       up on a 16-byte aligned address, as required by the ABI.  */
>    sigsp = (void *) ((uintptr_t) sigsp & ~15UL);
>  #endif
> -
> -  /* Push the arguments to call `trampoline' on the stack.  */
> -  sigsp -= sizeof (*stackframe);
>    stackframe = sigsp;
>  
>    if (_hurdsig_catch_memory_fault (stackframe))
> -- 
> 2.40.1
>
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/x86/trampoline.c b/sysdeps/mach/hurd/x86/trampoline.c
index 19bddad8..1f92064e 100644
--- a/sysdeps/mach/hurd/x86/trampoline.c
+++ b/sysdeps/mach/hurd/x86/trampoline.c
@@ -196,15 +196,14 @@  _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action
 #endif
     }
 
+  /* Push the arguments to call `trampoline' on the stack.  */
+  sigsp -= sizeof (*stackframe);
 #ifdef __x86_64__
   /* Align SP at 16 bytes.  Coupled with the fact that sigreturn_addr is
      16-byte aligned within the stackframe struct, this ensures that it ends
      up on a 16-byte aligned address, as required by the ABI.  */
   sigsp = (void *) ((uintptr_t) sigsp & ~15UL);
 #endif
-
-  /* Push the arguments to call `trampoline' on the stack.  */
-  sigsp -= sizeof (*stackframe);
   stackframe = sigsp;
 
   if (_hurdsig_catch_memory_fault (stackframe))