Skip to content

Commit 0f4d234

Browse files
committed
feat: add kernel-stack feature to allow disabling switching stacks on syscalls
1 parent 1e3225d commit 0f4d234

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ name = "measure_startup_time"
4545
harness = false
4646

4747
[features]
48-
default = ["pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fuse", "virtio-net", "vsock"]
48+
default = ["kernel-stack", "pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fuse", "virtio-net", "vsock"]
4949
acpi = []
5050
common-os = []
5151
console = ["virtio"]
@@ -56,6 +56,7 @@ fsgsbase = []
5656
fuse = ["virtio", "pci", "dep:fuse-abi", "fuse-abi/num_enum"]
5757
gem-net = ["tcp", "dep:tock-registers"]
5858
idle-poll = []
59+
kernel-stack = []
5960
log-target = []
6061
net = []
6162
mman = []

hermit-macro/src/system.rs

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,16 @@ fn emit_func(func: ItemFn, sig: &ParsedSig, errno: bool) -> Result<ItemFn> {
174174

175175
#kernel_func
176176

177-
#[cfg(not(any(
178-
target_arch = "riscv64",
179-
feature = "common-os"
180-
)))]
181-
unsafe { crate::arch::kernel::kernel_stack::#kernel_function_ident(#kernel_ident, #(#args),*) }
182-
183-
#[cfg(any(
184-
target_arch = "riscv64",
185-
feature = "common-os"
186-
))]
187-
#unsafety { #kernel_ident(#(#args),*) }
177+
cfg_if::cfg_if! {
178+
if #[cfg(all(
179+
feature = "kernel-stack",
180+
not(any(target_arch = "riscv64", feature = "common-os"))
181+
))] {
182+
unsafe { crate::arch::kernel::kernel_stack::#kernel_function_ident(#kernel_ident, #(#args),*) }
183+
} else {
184+
#unsafety { #kernel_ident(#(#args),*) }
185+
}
186+
}
188187
}},
189188
..func
190189
};
@@ -255,17 +254,16 @@ mod tests {
255254
ret
256255
}
257256

258-
#[cfg(not(any(
259-
target_arch = "riscv64",
260-
feature = "common-os"
261-
)))]
262-
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
263-
264-
#[cfg(any(
265-
target_arch = "riscv64",
266-
feature = "common-os"
267-
))]
268-
{ _sys_test(a, b) }
257+
cfg_if::cfg_if! {
258+
if #[cfg(all(
259+
feature = "kernel-stack",
260+
not(any(target_arch = "riscv64", feature = "common-os"))
261+
))] {
262+
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
263+
} else {
264+
{ _sys_test(a, b) }
265+
}
266+
}
269267
}
270268
};
271269

@@ -324,17 +322,16 @@ mod tests {
324322
ret
325323
}
326324

327-
#[cfg(not(any(
328-
target_arch = "riscv64",
329-
feature = "common-os"
330-
)))]
331-
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
332-
333-
#[cfg(any(
334-
target_arch = "riscv64",
335-
feature = "common-os"
336-
))]
337-
unsafe { _sys_test(a, b) }
325+
cfg_if::cfg_if! {
326+
if #[cfg(all(
327+
feature = "kernel-stack",
328+
not(any(target_arch = "riscv64", feature = "common-os"))
329+
))] {
330+
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
331+
} else {
332+
unsafe { _sys_test(a, b) }
333+
}
334+
}
338335
}
339336
};
340337

@@ -395,17 +392,16 @@ mod tests {
395392
ret
396393
}
397394

398-
#[cfg(not(any(
399-
target_arch = "riscv64",
400-
feature = "common-os"
401-
)))]
402-
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
403-
404-
#[cfg(any(
405-
target_arch = "riscv64",
406-
feature = "common-os"
407-
))]
408-
{ _sys_test(a, b) }
395+
cfg_if::cfg_if! {
396+
if #[cfg(all(
397+
feature = "kernel-stack",
398+
not(any(target_arch = "riscv64", feature = "common-os"))
399+
))] {
400+
unsafe { crate::arch::kernel::kernel_stack::kernel_function2(_sys_test, a, b) }
401+
} else {
402+
{ _sys_test(a, b) }
403+
}
404+
}
409405
}
410406
};
411407

src/arch/aarch64/kernel/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod core_local;
22
pub mod interrupts;
3+
#[cfg(feature = "kernel-stack")]
34
pub mod kernel_stack;
45
#[cfg(all(
56
not(feature = "pci"),

src/arch/x86_64/kernel/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod apic;
1616
pub mod core_local;
1717
pub mod gdt;
1818
pub mod interrupts;
19+
#[cfg(feature = "kernel-stack")]
1920
pub mod kernel_stack;
2021
#[cfg(all(
2122
not(feature = "pci"),

0 commit comments

Comments
 (0)