summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2022-02-24 14:19:11 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2022-02-24 14:19:11 +0000
commitcdd6f1391c8e24686526cb9ad5c7128c104a0ffa (patch)
tree087b4c8f2cc9297bf8857cb8f4ca18a8d544e357 /sys
parente5fcc4620849f80aa5abd822c4ab402d28a3b659 (diff)
Fix kernel stack alignment on riscv64
Pad trapframe and switchframe structs so that their size is a multiple of 16 bytes. This makes context switching and exception handlers keep kernel stack properly aligned. OK kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/riscv64/include/frame.h4
-rw-r--r--sys/arch/riscv64/riscv64/vm_machdep.c6
2 files changed, 8 insertions, 2 deletions
diff --git a/sys/arch/riscv64/include/frame.h b/sys/arch/riscv64/include/frame.h
index ab34499a366..bfce36b52ae 100644
--- a/sys/arch/riscv64/include/frame.h
+++ b/sys/arch/riscv64/include/frame.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: frame.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: frame.h,v 1.3 2022/02/24 14:19:10 visa Exp $ */
/*
* Copyright (c) 2019 Brian Bamsch <bbamsch@google.com>
@@ -64,6 +64,7 @@ typedef struct trapframe {
register_t tf_sstatus;
register_t tf_stval;
register_t tf_scause;
+ register_t tf_pad;
} trapframe_t;
/*
@@ -85,6 +86,7 @@ struct sigframe {
struct switchframe {
register_t sf_s[12];
register_t sf_ra;
+ register_t sf_pad;
};
struct callframe {
diff --git a/sys/arch/riscv64/riscv64/vm_machdep.c b/sys/arch/riscv64/riscv64/vm_machdep.c
index f94b7c2777b..fd4caec1d6d 100644
--- a/sys/arch/riscv64/riscv64/vm_machdep.c
+++ b/sys/arch/riscv64/riscv64/vm_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vm_machdep.c,v 1.9 2022/02/24 14:16:53 visa Exp $ */
+/* $OpenBSD: vm_machdep.c,v 1.10 2022/02/24 14:19:10 visa Exp $ */
/*-
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
@@ -62,6 +62,10 @@ cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb,
struct trapframe *tf;
struct switchframe *sf;
+ /* Ensure proper stack alignment. */
+ CTASSERT((sizeof(struct trapframe) & STACKALIGNBYTES) == 0);
+ CTASSERT((sizeof(struct switchframe) & STACKALIGNBYTES) == 0);
+
/* Save FPU state to PCB if necessary. */
if (pcb1->pcb_flags & PCB_FPU)
fpu_save(p1, pcb1->pcb_tf);