aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-02-07 00:36:44 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-02-09 17:57:00 +0000
commit97ce8f7d2b8eff42460f60e8c49d9849b58b6e81 (patch)
tree9c13cb8f606233b6678f00158dcb5eed9c14cd69
parent30988d0a7bd7ebd5f5825b9b7aa04ff0af788aa7 (diff)
amd64: define and use STACKALIGN and REDZONE_SZ
Reviewed by: brooks, emaste, jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55151
-rw-r--r--sys/amd64/amd64/exec_machdep.c4
-rw-r--r--sys/amd64/amd64/machdep.c6
-rw-r--r--sys/amd64/amd64/mp_machdep.c4
-rw-r--r--sys/amd64/include/param.h3
4 files changed, 10 insertions, 7 deletions
diff --git a/sys/amd64/amd64/exec_machdep.c b/sys/amd64/amd64/exec_machdep.c
index 6752b716deb5..b5eda6f83d46 100644
--- a/sys/amd64/amd64/exec_machdep.c
+++ b/sys/amd64/amd64/exec_machdep.c
@@ -151,7 +151,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
- sp = (char *)regs->tf_rsp - 128;
+ sp = (char *)regs->tf_rsp - REDZONE_SZ;
if (xfpusave != NULL) {
sp -= xfpusave_len;
sp = (char *)((unsigned long)sp & ~0x3Ful);
@@ -159,7 +159,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
}
sp -= sizeof(struct sigframe);
/* Align to 16 bytes. */
- sfp = (struct sigframe *)((unsigned long)sp & ~0xFul);
+ sfp = (struct sigframe *)STACKALIGN(sp);
/* Build the argument list for the signal handler. */
regs->tf_rdi = sig; /* arg 1 in %rdi */
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index ae5df475f046..b0da0b763b22 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -1216,8 +1216,8 @@ amd64_bsp_pcpu_init2(uint64_t rsp0)
{
PCPU_SET(rsp0, rsp0);
- PCPU_SET(pti_rsp0, ((vm_offset_t)PCPU_PTR(pti_stack) +
- PC_PTI_STACK_SZ * sizeof(uint64_t)) & ~0xful);
+ PCPU_SET(pti_rsp0, STACKALIGN((vm_offset_t)PCPU_PTR(pti_stack) +
+ PC_PTI_STACK_SZ * sizeof(uint64_t)));
PCPU_SET(curpcb, thread0.td_pcb);
}
@@ -1585,7 +1585,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
/* make an initial tss so cpu can get interrupt stack on syscall! */
rsp0 = thread0.td_md.md_stack_base;
/* Ensure the stack is aligned to 16 bytes */
- rsp0 &= ~0xFul;
+ rsp0 = STACKALIGN(rsp0);
PCPU_PTR(common_tss)->tss_rsp0 = rsp0;
amd64_bsp_pcpu_init2(rsp0);
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 61f1bdb6f942..05e4109e73bb 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -217,8 +217,8 @@ init_secondary(void)
pc->pc_curthread = 0;
pc->pc_tssp = &pc->pc_common_tss;
pc->pc_rsp0 = 0;
- pc->pc_pti_rsp0 = (((vm_offset_t)&pc->pc_pti_stack +
- PC_PTI_STACK_SZ * sizeof(uint64_t)) & ~0xful);
+ pc->pc_pti_rsp0 = STACKALIGN(((vm_offset_t)&pc->pc_pti_stack +
+ PC_PTI_STACK_SZ * sizeof(uint64_t)));
gdt = pc->pc_gdt;
pc->pc_tss = (struct system_segment_descriptor *)&gdt[GPROC0_SEL];
pc->pc_fs32p = &gdt[GUFS32_SEL];
diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h
index 642a031d8841..079937d9f53a 100644
--- a/sys/amd64/include/param.h
+++ b/sys/amd64/include/param.h
@@ -43,6 +43,9 @@
#include <sys/_align.h>
+#define STACKALIGNBYTES (16 - 1)
+#define REDZONE_SZ 128
+
/*
* Machine dependent constants for AMD64.
*/