Date: Mon, 09 Feb 2026 17:57:18 +0000 From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 97ce8f7d2b8e - main - amd64: define and use STACKALIGN and REDZONE_SZ Message-ID: <698a1ffe.26e3c.47182d66@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=97ce8f7d2b8eff42460f60e8c49d9849b58b6e81 commit 97ce8f7d2b8eff42460f60e8c49d9849b58b6e81 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-02-07 00:36:44 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-02-09 17:57:00 +0000 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 --- sys/amd64/amd64/exec_machdep.c | 4 ++-- sys/amd64/amd64/machdep.c | 6 +++--- sys/amd64/amd64/mp_machdep.c | 4 ++-- sys/amd64/include/param.h | 3 +++ 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. */home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?698a1ffe.26e3c.47182d66>
