This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move stack probe to
lucetc
; generalize tests over lucet_region
Moving the stack probe into the compiled Lucet modules lets us dodge Rust's current inability to reexport dynamic symbols (see <https://github.com/rust-lang/rust/issues/36342>). It loses a small amount of fidelity that we got with stack overflow traps previously, as we can't distinguish a stack overflow originating in the stack probe from anywhere else. The C test suites are now parameterized over region, much like the Rust test suites.
- Loading branch information
Showing
22 changed files
with
274 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
lucet-runtime/lucet-runtime-internals/src/probestack/mod.rs
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
lucet-runtime/lucet-runtime-internals/src/probestack/probestack_asm.S
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! Manual definition of the stack probe. | ||
//! | ||
//! Rust currently fails to reexport symbols in dynamic libraries. This means that the old way of | ||
//! including an assembly stack probe in the runtime does not work when embedding in C. | ||
//! | ||
//! There is an [issue](https://github.com/rust-lang/rust/issues/36342) tracking this, but until | ||
//! it's closed we are taking the approach of including the stack probe in every Lucet module, and | ||
//! adding custom entries for it into the trap table, so that stack overflows in the probe will be | ||
//! treated like any other guest trap. | ||
use cranelift_codegen::binemit::TrapSink; | ||
use cranelift_codegen::ir; | ||
use cranelift_faerie::traps::{FaerieTrapManifest, FaerieTrapSink}; | ||
use cranelift_faerie::FaerieProduct; | ||
use faerie::Decl; | ||
use failure::Error; | ||
|
||
/// Stack probe symbol name | ||
pub const STACK_PROBE_SYM: &'static str = "lucet_probestack"; | ||
|
||
/// The binary of the stack probe. | ||
const STACK_PROBE_BINARY: &'static [u8] = &[ | ||
// 49 89 c3 mov %rax,%r11 | ||
// 48 81 ec 00 10 00 00 sub $0x1000,%rsp | ||
// 48 85 64 24 08 test %rsp,0x8(%rsp) | ||
// 49 81 eb 00 10 00 00 sub $0x1000,%r11 | ||
// 49 81 fb 00 10 00 00 cmp $0x1000,%r11 | ||
// 77 e4 ja 4dfd3 <lucet_probestack+0x3> | ||
// 4c 29 dc sub %r11,%rsp | ||
// 48 85 64 24 08 test %rsp,0x8(%rsp) | ||
// 48 01 c4 add %rax,%rsp | ||
// c3 retq | ||
0x49, 0x89, 0xc3, 0x48, 0x81, 0xec, 0x00, 0x10, 0x00, 0x00, 0x48, 0x85, 0x64, 0x24, 0x08, 0x49, | ||
0x81, 0xeb, 0x00, 0x10, 0x00, 0x00, 0x49, 0x81, 0xfb, 0x00, 0x10, 0x00, 0x00, 0x77, 0xe4, 0x4c, | ||
0x29, 0xdc, 0x48, 0x85, 0x64, 0x24, 0x08, 0x48, 0x01, 0xc4, 0xc3, | ||
]; | ||
|
||
pub fn declare_and_define(product: &mut FaerieProduct) -> Result<(), Error> { | ||
product.artifact.declare_with( | ||
STACK_PROBE_SYM, | ||
Decl::Function { global: false }, | ||
STACK_PROBE_BINARY.to_vec(), | ||
)?; | ||
add_sink( | ||
product | ||
.trap_manifest | ||
.as_mut() | ||
.expect("trap manifest is present"), | ||
); | ||
Ok(()) | ||
} | ||
|
||
fn add_sink(manifest: &mut FaerieTrapManifest) { | ||
let mut stack_probe_trap_sink = | ||
FaerieTrapSink::new(STACK_PROBE_SYM, STACK_PROBE_BINARY.len() as u32); | ||
stack_probe_trap_sink.trap( | ||
10, /* test %rsp,0x8(%rsp) */ | ||
ir::SourceLoc::default(), | ||
ir::TrapCode::StackOverflow, | ||
); | ||
stack_probe_trap_sink.trap( | ||
34, /* test %rsp,0x8(%rsp) */ | ||
ir::SourceLoc::default(), | ||
ir::TrapCode::StackOverflow, | ||
); | ||
manifest.add_sink(stack_probe_trap_sink); | ||
} |
Oops, something went wrong.