Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack overflow during unwinding for some default configurations #203

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/private/tests/root-task/panicking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sel4_root_task::{debug_println, panicking, root_task};

static F1_DROPPED: AtomicBool = AtomicBool::new(false);

#[root_task(stack_size = 4096 * 64, heap_size = 4096 * 16)] // TODO decrease stack size
#[root_task(heap_size = 4096 * 16)]
fn main(_: &sel4::BootInfoPtr) -> ! {
let _ = panicking::catch_unwind(|| {
f1();
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-backtrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sel4-backtrace-types = { path = "types" }
serde = { version = "1.0.147", default-features = false, optional = true }

[dependencies.unwinding]
version = "0.1.6"
version = "0.2.1"
default-features = false
features = ["unwinder", "fde-custom", "hide-trace"]
optional = true
2 changes: 1 addition & 1 deletion crates/sel4-backtrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cfg_if::cfg_if! {
}

extern "C" fn callback<F1: FnMut(Entry) -> Result<(), E1>, E1>(
unwind_ctx: &mut UnwindContext,
unwind_ctx: &UnwindContext,
arg: *mut c_void,
) -> UnwindReasonCode {
let data = unsafe { &mut *(arg as *mut CallbackData<F1>) };
Expand Down
3 changes: 3 additions & 0 deletions crates/sel4-generate-target-specs/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ mk {
build-dependencies = {
inherit (versions) rustc_version;
};
package.metadata.rust-analyzer = {
rustc_private = true;
};
}
3 changes: 3 additions & 0 deletions crates/sel4-generate-target-specs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"]
edition = "2021"
license = "BSD-2-Clause"

[package.metadata.rust-analyzer]
rustc_private = true

[dependencies]
clap = "4.4.6"
serde_json = "1.0.87"
Expand Down
1 change: 1 addition & 0 deletions crates/sel4-generate-target-specs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl Context {
}

fn builtin(triple: &str) -> Target {
#[cfg_attr(not(target_spec_has_metadata), allow(unused_mut))]
let mut target = Target::expect_builtin(&TargetTriple::from_triple(triple));
#[cfg(target_spec_has_metadata)]
{
Expand Down
7 changes: 6 additions & 1 deletion crates/sel4-microkit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ macro_rules! declare_protection_domain {
}

#[doc(hidden)]
pub const DEFAULT_STACK_SIZE: usize = 0x10000;
pub const DEFAULT_STACK_SIZE: usize = 1024
* if cfg!(panic = "unwind") && cfg!(debug_assertions) {
128
} else {
64
};

// For macros
#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-panicking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sel4-panicking-env = { path = "env" }
rustc_version = "0.4.0"

[target."cfg(not(target_arch = \"arm\"))".dependencies.unwinding]
version = "0.1.6"
version = "0.2.1"
default-features = false
features = ["unwinder", "fde-custom", "hide-trace", "personality"]
optional = true
7 changes: 6 additions & 1 deletion crates/sel4-root-task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ macro_rules! declare_root_task {
}

#[doc(hidden)]
pub const DEFAULT_STACK_SIZE: usize = 0x10000;
pub const DEFAULT_STACK_SIZE: usize = 1024
* if cfg!(panic = "unwind") && cfg!(debug_assertions) {
128
} else {
64
};

// For macros
#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sel4-panicking-env = { path = "../sel4-panicking/env" }
sel4-stack = { path = "../sel4-stack" }

[target."cfg(not(target_arch = \"arm\"))".dependencies.unwinding]
version = "0.1.6"
version = "0.2.1"
default-features = false
features = ["unwinder", "fde-custom", "hide-trace"]
optional = true
2 changes: 1 addition & 1 deletion crates/sel4-runtime-common/src/unwinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ unsafe impl EhFrameFinder for EhFrameFinderImpl {
})?;

Some(FrameInfo {
text_base,
text_base: Some(text_base),
kind: FrameInfoKind::EhFrameHdr(eh_frame_hdr),
})
}
Expand Down
2 changes: 1 addition & 1 deletion hacking/cargo-manifest-management/manifest-scope.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ in rec {
synstructure = "0.12.6";
thiserror = "1.0";
tock-registers = "0.8.1";
unwinding = "0.1.6";
unwinding = "0.2.1";
virtio-drivers = "0.7.2";
webpki-roots = "0.26";
zerocopy = "0.7.32";
Expand Down
19 changes: 11 additions & 8 deletions hacking/nix/scope/plat-utils/qemu/automate_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ def main():
def run(args):
child = pexpect.spawn(args.simulate, encoding='utf-8')
child.logfile = sys.stdout
ix = child.expect(['TEST_PASS', 'TEST_FAIL', pexpect.TIMEOUT], timeout=args.timeout)
print()
if ix != 0:
if ix == 1:
sys.exit('> test reported failure')
if ix == 2:
sys.exit('> test timed out')
assert False
try:
ix = child.expect(['TEST_PASS', 'TEST_FAIL', pexpect.TIMEOUT], timeout=args.timeout)
print()
if ix != 0:
if ix == 1:
sys.exit('> test reported failure')
if ix == 2:
sys.exit('> test timed out')
assert False
except KeyboardInterrupt:
sys.exit('> interrupted')

if __name__ == '__main__':
main()
76 changes: 46 additions & 30 deletions hacking/nix/scope/world/instances/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ in rec {
tests.root-task.config
tests.root-task.tls
tests.root-task.backtrace
tests.root-task.panicking.byConfig.abort.withAlloc
tests.root-task.panicking.byConfig.abort.withoutAlloc
tests.root-task.panicking.byConfig.unwind.withAlloc
tests.root-task.panicking.byConfig.unwind.withoutAlloc
# tests.root-task.panicking
tests.root-task.c
tests.root-task.verus
tests.root-task.dafny
Expand Down Expand Up @@ -179,41 +176,60 @@ in rec {
abort = null;
};

profile = {
release = true;
debug = false;
};

byConfig = lib.flip lib.mapAttrs panicStrategy
(panicStrategyName: _:
lib.flip lib.mapAttrs alloc
(_: allocFeatures: maybe (haveFullRuntime && haveUnwindingSupport) (mkInstance {
rootTask = mkTask {
rootCrate = crates.tests-root-task-panicking;
release = false;
features = allocFeatures ++ [ "panic-${panicStrategyName}" ];
extraProfile = {
panic = panicStrategyName;
};
};
extraPlatformArgs = lib.optionalAttrs canSimulate {
canAutomateSimply = panicStrategyName == "unwind";
};
})));

paths = [
[ "abort" "withAlloc" ]
[ "abort" "withoutAlloc" ]
[ "unwind" "withAlloc" ]
[ "unwind" "withoutAlloc" ]
];

automate = mkRunTests "run-all-panicking-tests" (lib.forEach paths (path: {
name = lib.concatStringsSep "." path;
value = (lib.attrByPath path (throw "x") byConfig).automate;
}));
(_: allocFeatures:
lib.flip lib.mapAttrs profile
(_: release:
maybe (haveFullRuntime && haveUnwindingSupport) (mkInstance {
rootTask = mkTask {
rootCrate = crates.tests-root-task-panicking;
inherit release;
features = allocFeatures ++ [ "panic-${panicStrategyName}" ];
extraProfile = {
panic = panicStrategyName;
};
};
extraPlatformArgs = lib.optionalAttrs canSimulate {
canAutomateSimply = panicStrategyName == "unwind";
};
}))));

paths = lib.mapCartesianProduct
({ panicStrategyName, allocName, profileName }: [ panicStrategyName allocName profileName ])
(lib.mapAttrs (lib.const lib.attrNames) {
panicStrategyName = panicStrategy;
allocName = alloc;
profileName = profile;
});

automate = mkRunTests "run-all-panicking-tests"
(lib.forEach
(lib.filter
(config: config != null)
(lib.forEach paths (path: lib.attrByPath path (throw "x") byConfig)))
(config: {
name = "test"; # TODO
value = config.automate;
}));

simulate = writeText "all-panicking-scripts" (toString (lib.forEach paths (path:
(lib.attrByPath path (throw "x") byConfig).simulate
)));

links = linkFarm "links" {
inherit simulate;
};

in {
inherit byConfig automate simulate;
inherit byConfig;
inherit links simulate automate;
};

c = maybe haveFullRuntime (callPackage ./c.nix {
Expand Down
Loading