aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/mips
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2018-01-31 17:36:39 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2018-01-31 17:36:39 +0000
commitec56d650618142bbc161980470d02ca3fa6394ab (patch)
tree3286c6bff7050fb8be5e255f7713f78c92ebc0d0 /lib/libc/mips
parentf7f14d9deadef3d217a838f5d220d986d6528779 (diff)
downloadsrc-ec56d650618142bbc161980470d02ca3fa6394ab.tar.gz
src-ec56d650618142bbc161980470d02ca3fa6394ab.zip
Consistently use 16-byte alignment for MIPS N32 and N64.
- Add a new <machine/abi.h> header to hold constants shared between C and assembly such as CALLFRAME_SZ. - Add a new STACK_ALIGN constant to <machine/abi.h> and use it to replace hardcoded constants in the kernel and makecontext(). As a result of this, ensure the stack pointer on N32 and N64 is 16-byte aligned for N32 and N64 after exec(), after pthread_create(), and when sending signals rather than 8-byte aligned. Reviewed by: jmallett Sponsored by: DARPA / AFRL Differential Revision: https://reviews.freebsd.org/D13875
Notes
Notes: svn path=/head/; revision=328629
Diffstat (limited to 'lib/libc/mips')
-rw-r--r--lib/libc/mips/gen/makecontext.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/libc/mips/gen/makecontext.c b/lib/libc/mips/gen/makecontext.c
index 1f79c50bcda4..d15f1c991b92 100644
--- a/lib/libc/mips/gen/makecontext.c
+++ b/lib/libc/mips/gen/makecontext.c
@@ -38,6 +38,7 @@ __RCSID("$NetBSD: makecontext.c,v 1.5 2009/12/14 01:07:42 matt Exp $");
#endif
#include <sys/param.h>
+#include <machine/abi.h>
#include <machine/regnum.h>
#include <stdarg.h>
@@ -75,13 +76,10 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
#if defined(__mips_o32) || defined(__mips_o64)
sp -= (argc >= 4 ? argc : 4); /* Make room for >=4 arguments. */
- sp = (register_t *)
- ((uintptr_t)sp & ~0x7); /* Align on double-word boundary. */
#elif defined(__mips_n32) || defined(__mips_n64)
sp -= (argc > 8 ? argc - 8 : 0); /* Make room for > 8 arguments. */
- sp = (register_t *)
- ((uintptr_t)sp & ~0xf); /* Align on quad-word boundary. */
#endif
+ sp = (register_t *)((uintptr_t)sp & ~(STACK_ALIGN - 1));
mc->mc_regs[SP] = (intptr_t)sp;
mc->mc_regs[S0] = (intptr_t)ucp;