From 5f35189a51ebc54298ea2cb0e4d53afe4e4e75eb Mon Sep 17 00:00:00 2001 From: Ruize Tang <1466040111@qq.com> Date: Thu, 21 Nov 2024 19:14:52 +0800 Subject: [PATCH] Add compile flags to disable the red zone optimization --- osdk/src/commands/build/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osdk/src/commands/build/mod.rs b/osdk/src/commands/build/mod.rs index 7f680b214..2a3176be0 100644 --- a/osdk/src/commands/build/mod.rs +++ b/osdk/src/commands/build/mod.rs @@ -213,6 +213,11 @@ fn build_kernel_elf( // This is to let rustc know that "cfg(ktest)" is our well-known configuration. // See the [Rust Blog](https://blog.rust-lang.org/2024/05/06/check-cfg.html) for details. "--check-cfg cfg(ktest)", + // The red zone is a small area below the stack pointer for optimization, primarily in + // user-space applications. This optimization can be problematic in the kernel, as the CPU + // or exception handlers may overwrite kernel data in the red zone. Therefore, we disable + // this optimization. + "-C no-redzone=y", ]); if matches!(arch, Arch::X86_64) {