Skip to content

Commit d9cfd12

Browse files
riastradhriastradh
authored andcommitted
mips/makecontext.c: Use STACK_ALIGNBYTES for clarity.
No functional change intended. Tidying to make stack alignment more obvious, prompted by: PR kern/59327: user stack pointer is not aligned properly Part of a patch by rin@.
1 parent b025040 commit d9cfd12

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

lib/libc/arch/mips/gen/makecontext.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: makecontext.c,v 1.9 2025/04/24 23:51:43 riastradh Exp $ */
1+
/* $NetBSD: makecontext.c,v 1.10 2025/04/24 23:54:13 riastradh Exp $ */
22

33
/*-
44
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,9 +31,11 @@
3131

3232
#include <sys/cdefs.h>
3333
#if defined(LIBC_SCCS) && !defined(lint)
34-
__RCSID("$NetBSD: makecontext.c,v 1.9 2025/04/24 23:51:43 riastradh Exp $");
34+
__RCSID("$NetBSD: makecontext.c,v 1.10 2025/04/24 23:54:13 riastradh Exp $");
3535
#endif
3636

37+
#include <sys/param.h>
38+
3739
#include <inttypes.h>
3840
#include <stdarg.h>
3941
#include <stddef.h>
@@ -54,16 +56,13 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
5456
/* LINTED uintptr_t is safe */
5557
sp = (__greg_t *)
5658
((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
57-
/* LINTED uintptr_t is safe */
5859
#if defined(__mips_o32) || defined(__mips_o64)
5960
sp -= (argc >= 4 ? argc : 4); /* Make room for >=4 arguments. */
60-
sp = (__greg_t *)
61-
((uintptr_t)sp & ~0x7); /* Align on double-word boundary. */
6261
#elif defined(__mips_n32) || defined(__mips_n64)
6362
sp -= (argc > 8 ? argc - 8 : 0); /* Make room for > 8 arguments. */
64-
sp = (__greg_t *)
65-
((uintptr_t)sp & ~0xf); /* Align on quad-word boundary. */
6663
#endif
64+
/* LINTED uintptr_t is safe */
65+
sp = (__greg_t *)((uintptr_t)sp & ~STACK_ALIGNBYTES);
6766

6867
gr[_REG_SP] = (intptr_t)sp;
6968
gr[_REG_RA] = (intptr_t)__resumecontext;

0 commit comments

Comments
 (0)