Ensure that the stack is always 16-byte aligned by rounding sizes as needed.

All changes from rin@ except swapcontext.S, which is from me (added
symbolic constants to make the code clearer).
This commit is contained in:
thorpej 2021-07-06 12:38:40 +00:00
parent 897ac01663
commit 276edc129d
5 changed files with 32 additions and 25 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: __setjmp14.S,v 1.8 2020/10/21 01:24:05 thorpej Exp $ */
/* $NetBSD: __setjmp14.S,v 1.9 2021/07/06 12:38:40 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
@ -68,12 +68,12 @@ LEAF(__setjmp14, 1)
lda a2, SC_MASK(s0) /* point to mask in sc */
CALL(__sigprocmask14)
lda sp, -24(sp) /* sizeof struct sigaltstack */
lda sp, -32(sp) /* roundup(sizeof(struct sigaltstack), 16) */
mov zero, a0
mov sp, a1
CALL(__sigaltstack14)
ldl t0, 16(sp) /* offset of ss_flags */
lda sp, 24(sp) /* sizeof struct sigaltstack */
lda sp, 32(sp) /* pop the sigaltstack */
ldq ra, (SC_REGS+_REG_RA*8)(s0) /* restore return address */
blt v0, botch /* check for error */
and t0, 0x1, t0 /* get SA_ONSTACK flag */

View File

@ -1,4 +1,4 @@
/* $NetBSD: _lwp.c,v 1.7 2012/09/12 14:13:43 manu Exp $ */
/* $NetBSD: _lwp.c,v 1.8 2021/07/06 12:38:40 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _lwp.c,v 1.7 2012/09/12 14:13:43 manu Exp $");
__RCSID("$NetBSD: _lwp.c,v 1.8 2021/07/06 12:38:40 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -58,7 +58,7 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *),
gr[_REG_T12] = (unsigned long) start;
gr[_REG_RA] = (unsigned long) _lwp_exit;
gr[_REG_A0] = (unsigned long) arg;
gr[_REG_SP] = ((unsigned long) (stack_base + stack_size)) & ~0x7;
gr[_REG_SP] = ((unsigned long) (stack_base + stack_size)) & ~0xfUL;
gr[_REG_S6] = 0;
gr[_REG_UNIQUE] = (unsigned long)private;

View File

@ -1,4 +1,4 @@
/* $NetBSD: makecontext.c,v 1.6 2011/09/20 08:42:29 joerg Exp $ */
/* $NetBSD: makecontext.c,v 1.7 2021/07/06 12:38:40 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: makecontext.c,v 1.6 2011/09/20 08:42:29 joerg Exp $");
__RCSID("$NetBSD: makecontext.c,v 1.7 2021/07/06 12:38:40 thorpej Exp $");
#endif
#include <stddef.h>
@ -51,12 +51,14 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
unsigned long *sp;
va_list ap;
/* Compute and align stack pointer. */
/* Compute stack pointer. */
sp = (unsigned long *)
(((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~0x7);
((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
/* Allocate necessary stack space for arguments exceeding a0-5. */
if (argc > 6)
sp -= (argc - 6);
/* Align stack pointer. */
sp = (unsigned long *)((uintptr_t)sp & ~0xfUL);
gr[_REG_SP] = (__greg_t)sp;
/* Arrange for return via the trampoline code. */
gr[_REG_RA] = (__greg_t)__resumecontext;

View File

@ -1,4 +1,4 @@
/* $NetBSD: swapcontext.S,v 1.4 2020/10/21 01:24:05 thorpej Exp $ */
/* $NetBSD: swapcontext.S,v 1.5 2021/07/06 12:38:40 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -32,25 +32,30 @@
#include "SYS.h"
#include "assym.h"
NESTED(swapcontext, 2, 24, ra, IM_RA|IM_A0|IM_A1, 0)
#define FRAME_SIZE 32
#define FRAME_RA (32-16)
#define FRAME_OUCP (32-24)
#define FRAME_UCP (32-32)
NESTED(swapcontext, 2, FRAME_SIZE, ra, IM_RA|IM_A0|IM_A1, 0)
LDGP(pv)
lda sp, -24(sp)
stq ra, (24- 8)(sp) /* must save ra, oucp, ucp */
stq a0, (24-16)(sp)
stq a1, (24-24)(sp)
lda sp, -FRAME_SIZE(sp)
stq ra, FRAME_RA(sp) /* must save ra, oucp, ucp */
stq a0, FRAME_OUCP(sp)
stq a1, FRAME_UCP(sp)
CALL(_getcontext) /* getcontext(oucp) */
ldq t0, (24-16)(sp)
ldq t0, FRAME_OUCP(sp)
bne v0, Lerr
ldq t1, (24- 8)(sp)
ldq t1, FRAME_RA(sp)
stq t1, (UC_GREGS + _REG_RA*8)(t0) /* Adjust saved RA */
stq t1, (UC_GREGS + _REG_PC*8)(t0) /* Adjust saved PC */
lda t1, 24(sp)
lda t1, FRAME_SIZE(sp)
stq t1, (UC_GREGS + _REG_SP*8)(t0) /* Adjust saved SP */
ldq a0, (24-24)(sp)
ldq a0, FRAME_UCP(sp)
CALL(setcontext) /* setcontext(ucp) */
Lerr:
ldq ra, (24- 8)(sp)
lda sp, 24(sp)
ldq ra, FRAME_RA(sp)
lda sp, FRAME_SIZE(sp)
RET
END(swapcontext)

View File

@ -1,4 +1,4 @@
/* $NetBSD: lrint.S,v 1.3 2004/10/13 15:18:31 drochner Exp $ */
/* $NetBSD: lrint.S,v 1.4 2021/07/06 12:38:40 thorpej Exp $ */
/*
* Written by Matthias Drochner <drochner@NetBSD.org>.
@ -12,10 +12,10 @@ LEAF(lrint, 1)
#if 0
ftoit ft0,v0
#else
lda sp,-8(sp)
lda sp,-16(sp)
stt ft0,0(sp)
ldq v0,0(sp)
lda sp,8(sp)
lda sp,16(sp)
#endif
ret
END(lrint)