Skip to content

Commit 23f073d

Browse files
riastradhriastradh
authored andcommitted
mips __resumecontext: Align private stack frame size.
On mips64, UCONTEXT_SIZE is 664=0x298 (n32) or 744=0x2e8 (n64), but sp is required to have 16-byte alignment in the ABI, so we need to round the stack frame allocation up to 0x2a0 or 0x2f0. No functional change intended on mips o32. Unlikely to have a practical change on mips n32/n64, but possible if signal delivery wins a race -- until we fix sp alignment in signal handler calls, coming soon. Based on a patch by rin@. PR kern/59327: user stack pointer is not aligned properly
1 parent e16d328 commit 23f073d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

lib/libc/arch/mips/gen/_resumecontext.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: _resumecontext.S,v 1.13 2020/10/15 05:27:53 skrll Exp $ */
1+
/* $NetBSD: _resumecontext.S,v 1.14 2025/04/25 00:08:38 riastradh Exp $ */
22

33
/*-
44
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,17 +30,22 @@
3030
*/
3131

3232
#include <machine/asm.h>
33+
#include <machine/param.h>
3334

3435
#include "SYS.h"
3536
#include "assym.h"
3637

3738
#if defined(SYSLIBC_SCCS) && !defined(lint)
38-
RCSID("$NetBSD: _resumecontext.S,v 1.13 2020/10/15 05:27:53 skrll Exp $")
39+
RCSID("$NetBSD: _resumecontext.S,v 1.14 2025/04/25 00:08:38 riastradh Exp $")
3940
#endif /* SYSLIBC_SCCS && !lint */
4041

4142
.set reorder
4243
.hidden _C_LABEL(__resumecontext)
4344

45+
#define UCONTEXT_SIZE_ALIGNED \
46+
(((UCONTEXT_SIZE + STACK_ALIGNBYTES)/(STACK_ALIGNBYTES + 1)) \
47+
* (STACK_ALIGNBYTES + 1))
48+
4449
LEAF_NOPROFILE(__resumecontext)
4550
/*
4651
* We get here not by a call through $t9 but thru $ra after the
@@ -57,7 +62,7 @@ LEAF_NOPROFILE(__resumecontext)
5762
.cpsetup ra, t3, __resumecontext
5863
#endif
5964

60-
PTR_SUBU sp, sp, UCONTEXT_SIZE # get space for ucontext
65+
PTR_SUBU sp, sp, UCONTEXT_SIZE_ALIGNED # get space for ucontext
6166
move a0, sp # arg0 for getcontext
6267
PTR_S zero, _UC_LINK(a0) # make sure uc_link is 0
6368
SYSTRAP(getcontext) # get context

0 commit comments

Comments
 (0)