Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

[WIP] Lucet i686 (32-bit x86) support... ish #508

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lucet-runtime/Cargo.toml
Expand Up @@ -15,6 +15,7 @@ lucet-runtime-internals = { path = "lucet-runtime-internals", version = "=0.7.0-
lucet-module = { path = "../lucet-module", version = "=0.7.0-dev" }
num-traits = "0.2"
num-derive = "0.3.0"
cfg-if = "*"

[dev-dependencies]
byteorder = "1.2"
Expand Down
2 changes: 2 additions & 0 deletions lucet-runtime/include/lucet_types.h
Expand Up @@ -16,6 +16,8 @@
#include <ucontext.h>
#endif

#include <signal.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only present because I was wildly flailing around trying to fix header issues that were caused by fiddling with an include path I shouldn't have. I left it because lucet_types.h references siginfo_t without including signal.h. This isn't an issue because lucet.h includes signal.h before lucet_types.h, but someone using lucet_types.h individually for some reason would be in for a surprise.

... I ought to make this a PR on its own.


enum lucet_error {
lucet_error_ok,
lucet_error_invalid_argument,
Expand Down
1 change: 1 addition & 0 deletions lucet-runtime/lucet-runtime-internals/Cargo.toml
Expand Up @@ -13,6 +13,7 @@ edition = "2018"
lucet-module = { path = "../../lucet-module", version = "=0.7.0-dev" }
lucet-runtime-macros = { path = "../lucet-runtime-macros", version = "=0.7.0-dev" }

cfg-if = "*"
anyhow = "1.0"
bitflags = "1.0"
bincode = "1.1.4"
Expand Down
10 changes: 9 additions & 1 deletion lucet-runtime/lucet-runtime-internals/build.rs
Expand Up @@ -3,8 +3,16 @@ use std::fs::File;
use std::path::Path;

fn main() {
let context_asm_arch = match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"x86_64" => "x86_64",
"x86" => "i686",
arch => {
panic!("unsupported architecture {}", arch);
}
};

cc::Build::new()
.file("src/context/context_asm.S")
.file(&format!("src/context/sysdep/{}/context_asm.S", context_asm_arch))
.compile("context_context_asm");
cc::Build::new()
.file("src/instance/siginfo_ext.c")
Expand Down
45 changes: 38 additions & 7 deletions lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs
Expand Up @@ -339,7 +339,8 @@ impl Alloc {
/// Since the stack grows down, `alloc.stack_mut()[0]` is the top of the stack, and
/// `alloc.stack_mut()[alloc.limits.stack_size - 1]` is the last word at the bottom of the
/// stack.
pub unsafe fn stack_u64_mut(&mut self) -> &mut [u64] {
#[cfg(target_pointer_width = "64")]
pub unsafe fn stack_words_mut(&mut self) -> &mut [u64] {
assert!(
self.slot().stack as usize % 8 == 0,
"stack is 8-byte aligned"
Expand All @@ -353,6 +354,21 @@ impl Alloc {
self.slot().limits.stack_size / 8,
)
}
#[cfg(target_pointer_width = "32")]
pub unsafe fn stack_words_mut(&mut self) -> &mut [u32] {
assert!(
self.slot().stack as usize % 4 == 0,
"stack is 4-byte aligned"
);
assert!(
self.slot().limits.stack_size % 4 == 0,
"stack size is multiple of 4-bytes"
);
std::slice::from_raw_parts_mut(
self.slot().stack as *mut u32,
self.slot().limits.stack_size / 4,
)
}

/// Return the globals as a slice.
pub unsafe fn globals(&self) -> &[GlobalValue] {
Expand Down Expand Up @@ -454,12 +470,27 @@ pub const DEFAULT_SIGNAL_STACK_SIZE: usize = {

impl Limits {
pub const fn default() -> Limits {
Limits {
heap_memory_size: 16 * 64 * 1024,
heap_address_space_size: 0x0002_0000_0000,
stack_size: 128 * 1024,
globals_size: 4096,
signal_stack_size: DEFAULT_SIGNAL_STACK_SIZE,
use cfg_if::cfg_if;
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
Limits {
heap_memory_size: 16 * 64 * 1024,
heap_address_space_size: 0x0002_0000_0000,
stack_size: 128 * 1024,
globals_size: 4096,
signal_stack_size: DEFAULT_SIGNAL_STACK_SIZE,
}
} else if #[cfg(target_pointer_width = "32")] {
Limits {
heap_memory_size: 16 * 64 * 1024,
heap_address_space_size: 0xffff_ffff,
stack_size: 128 * 1024,
globals_size: 4096,
signal_stack_size: DEFAULT_SIGNAL_STACK_SIZE,
}
} else {
panic!("unsupported architecture!");
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lucet-runtime/lucet-runtime-internals/src/alloc/tests.rs
Expand Up @@ -650,7 +650,7 @@ macro_rules! alloc_tests {
unsafe {
let heap_ptr = inst.alloc_mut().heap_mut().as_ptr() as *mut c_void;
let mut child = ContextHandle::create_and_init(
inst.alloc_mut().stack_u64_mut(),
inst.alloc_mut().stack_words_mut(),
heap_touching_child as usize,
&[Val::CPtr(heap_ptr)],
)
Expand Down Expand Up @@ -699,7 +699,7 @@ macro_rules! alloc_tests {
unsafe {
let heap_ptr = inst.alloc_mut().heap_mut().as_ptr() as *mut c_void;
let mut child = ContextHandle::create_and_init(
inst.alloc_mut().stack_u64_mut(),
inst.alloc_mut().stack_words_mut(),
stack_pattern_child as usize,
&[Val::CPtr(heap_ptr)],
)
Expand Down
@@ -0,0 +1 @@
pub mod val;