Skip to content

Commit f341b0d

Browse files
riastradhriastradh
authored andcommitted
mips _lwp_makecontext: Align sp.
PR kern/59327: user stack pointer is not aligned properly
1 parent 1823265 commit f341b0d

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: _lwp.c,v 1.10 2025/04/24 23:56:50 riastradh Exp $ */
1+
/* $NetBSD: _lwp.c,v 1.11 2025/04/25 01:18:24 riastradh Exp $ */
22

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

3232
#include <sys/cdefs.h>
3333
#if defined(LIBC_SCCS) && !defined(lint)
34-
__RCSID("$NetBSD: _lwp.c,v 1.10 2025/04/24 23:56:50 riastradh Exp $");
34+
__RCSID("$NetBSD: _lwp.c,v 1.11 2025/04/25 01:18:24 riastradh Exp $");
3535
#endif /* LIBC_SCCS and not lint */
3636

3737
#include "namespace.h"
3838

39+
#include <sys/param.h>
3940
#include <sys/types.h>
4041

4142
#include <lwp.h>
@@ -69,7 +70,7 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *),
6970
gr[_REG_T9] = (uintptr_t) start; /* required for .abicalls */
7071
gr[_REG_RA] = (uintptr_t) _lwp_exit;
7172
gr[_REG_A0] = (uintptr_t) arg;
72-
gr[_REG_SP] = (uintptr_t) sp;
73+
gr[_REG_SP] = (uintptr_t) sp & ~STACK_ALIGNBYTES;
7374
u->uc_mcontext._mc_tlsbase =
7475
(uintptr_t)tcb + TLS_TP_OFFSET + sizeof(struct tls_tcb);
7576
u->uc_flags |= _UC_TLSBASE;

tests/kernel/t_signal_and_sp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: t_signal_and_sp.c,v 1.16 2025/04/25 00:59:27 riastradh Exp $ */
1+
/* $NetBSD: t_signal_and_sp.c,v 1.17 2025/04/25 01:18:24 riastradh Exp $ */
22

33
/*
44
* Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <sys/cdefs.h>
30-
__RCSID("$NetBSD: t_signal_and_sp.c,v 1.16 2025/04/25 00:59:27 riastradh Exp $");
30+
__RCSID("$NetBSD: t_signal_and_sp.c,v 1.17 2025/04/25 01:18:24 riastradh Exp $");
3131

3232
#include <sys/wait.h>
3333

@@ -496,10 +496,6 @@ ATF_TC_BODY(threadsp, tc)
496496
atf_tc_expect_signal(SIGBUS, "PR kern/59327:"
497497
" user stack pointer is not aligned properly");
498498
#endif
499-
#ifdef __mips__
500-
atf_tc_expect_fail("PR kern/59327:"
501-
" user stack pointer is not aligned properly");
502-
#endif
503499

504500
RZ(pthread_create(&t, NULL, &threadspfunc, NULL));
505501

0 commit comments

Comments
 (0)