bsd-user: Define TARGET_SIGSTACK_ALIGN and use it to round stack
authorWarner Losh <imp@bsdimp.com>
Sun, 23 Jun 2024 21:29:42 +0000 (15:29 -0600)
committerWarner Losh <imp@bsdimp.com>
Tue, 23 Jul 2024 16:56:30 +0000 (10:56 -0600)
Most (all?) targets require stacks to be properly aligned. Rather than a
series of ifdefs in bsd-user/signal.h, instead use a manditory #define
for all architectures.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
bsd-user/aarch64/target_arch_signal.h
bsd-user/arm/target_arch_signal.h
bsd-user/i386/target_arch_signal.h
bsd-user/signal.c
bsd-user/x86_64/target_arch_signal.h

index bff752a67ab31b71493c2664208ffb57ce08ec21..b72ba7aa50437af2d7ea935310730d142e1b2d3c 100644 (file)
@@ -77,4 +77,6 @@ struct target_sigframe {
     target_ucontext_t   sf_uc;  /* saved ucontext */
 };
 
+#define TARGET_SIGSTACK_ALIGN 16
+
 #endif /* TARGET_ARCH_SIGNAL_H */
index 02b2b33e07aba370f1a01b81a218a46408f3af07..10f96b8bfc931f9691a06e0c9658cab06d0d0c23 100644 (file)
@@ -86,4 +86,6 @@ struct target_sigframe {
     target_mcontext_vfp_t sf_vfp; /* actual saved VFP context */
 };
 
+#define TARGET_SIGSTACK_ALIGN 8
+
 #endif /* TARGET_ARCH_SIGNAL_H */
index 279dadc22c765efbb35e94ae27bae68373b60caf..2c14153ab6b94c6efdbadf5f26f173d717c79c8e 100644 (file)
@@ -88,4 +88,6 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+#define TARGET_SIGSTACK_ALIGN 8
+
 #endif /* TARGET_ARCH_SIGNAL_H */
index 8b6654b91dacd5e3a059b64a136916eaae1a0834..da49b9bffc1faa086ab4a979d69fdcd9fa2d5d05 100644 (file)
@@ -728,14 +728,7 @@ static inline abi_ulong get_sigframe(struct target_sigaction *ka,
         sp = ts->sigaltstack_used.ss_sp + ts->sigaltstack_used.ss_size;
     }
 
-/* TODO: make this a target_arch function / define */
-#if defined(TARGET_ARM)
-    return (sp - frame_size) & ~7;
-#elif defined(TARGET_AARCH64)
-    return (sp - frame_size) & ~15;
-#else
-    return sp - frame_size;
-#endif
+    return ROUND_DOWN(sp - frame_size, TARGET_SIGSTACK_ALIGN);
 }
 
 /* compare to $M/$M/exec_machdep.c sendsig and sys/kern/kern_sig.c sigexit */
index ca24bf1e7f705b0c05198741ba26fbf1c2411fdb..f833ee66cef98ded491f52517b860291199798cd 100644 (file)
@@ -97,4 +97,6 @@ struct target_sigframe {
     uint32_t    __spare__[2];
 };
 
+#define TARGET_SIGSTACK_ALIGN 16
+
 #endif /* TARGET_ARCH_SIGNAL_H */