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

Commit 65eccfb

Browse files
author
Pat Hickey
authored
Merge pull request #577 from bytecodealliance/pch/freebsd
freebsd support
2 parents 658ba19 + a1ec527 commit 65eccfb

File tree

13 files changed

+108
-45
lines changed

13 files changed

+108
-45
lines changed

Cargo.lock

Lines changed: 11 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lucet-module/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
1717
bincode = "1.1.4"
1818
minisign = "0.5.19"
19-
object = "0.18.0"
19+
object = "0.20.0"
2020
byteorder = "1.3"
2121
memoffset = "0.5.3"
2222
thiserror = "1.0.4"

lucet-objdump/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = ["Lucet team <lucet@fastly.com>"]
1010
edition = "2018"
1111

1212
[dependencies]
13-
object = "0.18"
13+
object = "0.20"
1414
byteorder="1.2.1"
1515
colored="1.8.0"
1616
lucet-module = { path = "../lucet-module", version = "=0.7.0-dev" }

lucet-runtime/lucet-runtime-internals/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ anyhow = "1.0"
1717
bitflags = "1.0"
1818
bincode = "1.1.4"
1919
byteorder = "1.3"
20+
cfg-if = "0.1"
2021
lazy_static = "1.4"
2122
libc = "0.2.65"
2223
libloading = "0.6"

lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,23 @@ pub const MINSIGSTKSZ: usize = libc::MINSIGSTKSZ;
465465
///
466466
/// [sigstksz]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
467467
pub const DEFAULT_SIGNAL_STACK_SIZE: usize = {
468-
// on Linux, `SIGSTKSZ` is too small for the signal handler when compiled in debug mode
469-
#[cfg(all(debug_assertions, not(target_os = "macos")))]
470-
const SIZE: usize = 12 * 1024;
471-
472-
// on Mac, `SIGSTKSZ` is way larger than we need; it would be nice to combine these debug cases once
473-
// `std::cmp::max` is a const fn
474-
#[cfg(all(debug_assertions, target_os = "macos"))]
475-
const SIZE: usize = libc::SIGSTKSZ;
476-
477-
#[cfg(not(debug_assertions))]
478-
const SIZE: usize = libc::SIGSTKSZ;
479-
480-
SIZE
468+
cfg_if::cfg_if! {
469+
if #[cfg(target_os = "freebsd")] {
470+
// on FreeBSD/amd64, `SIGSTKSZ` is not a multiple of the page size
471+
// (34816 == MINSIGSTKSZ(2048) + 32768)
472+
12 * 1024
473+
} else if #[cfg(target_os = "macos")] {
474+
// on Mac, `SIGSTKSZ` is way larger than we need;
475+
// it would be nice to combine these debug cases once
476+
// `std::cmp::max` is a const fn
477+
libc::SIGSTKSZ
478+
} else if #[cfg(debug_assertions)] {
479+
// on Linux, `SIGSTKSZ` is too small for the signal handler when compiled in debug mode
480+
12 * 1024
481+
} else {
482+
libc::SIGSTKSZ
483+
}
484+
}
481485
};
482486

483487
impl Limits {

lucet-runtime/lucet-runtime-internals/src/context/context_asm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,6 @@ _lucet_context_activate:
221221
#endif
222222

223223
/* Mark that we don't need executable stack. */
224-
#if defined(__linux__) && defined(__ELF__)
224+
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__)
225225
.section .note.GNU-stack,"",%progbits
226226
#endif

lucet-runtime/lucet-runtime-internals/src/region/mmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl MmapRegion {
365365
region.limits.total_memory_size(),
366366
ProtFlags::PROT_NONE,
367367
MapFlags::MAP_ANON | MapFlags::MAP_PRIVATE,
368-
0,
368+
-1,
369369
0,
370370
)?
371371
}
@@ -436,7 +436,7 @@ unsafe fn mmap_aligned(
436436
alignment_offset: usize,
437437
) -> Result<*mut c_void, Error> {
438438
let addr = ptr::null_mut();
439-
let fd = 0;
439+
let fd = -1;
440440
let offset = 0;
441441

442442
let padded_length = requested_length + alignment + alignment_offset;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use libc::{c_void, ucontext_t};
2+
3+
#[derive(Clone, Copy, Debug)]
4+
pub struct UContextPtr(*mut ucontext_t);
5+
6+
impl UContextPtr {
7+
#[inline]
8+
pub fn new(ptr: *mut c_void) -> Self {
9+
assert!(!ptr.is_null(), "non-null context");
10+
UContextPtr(ptr as *mut ucontext_t)
11+
}
12+
13+
#[inline]
14+
pub fn get_ip(self) -> *const c_void {
15+
let mcontext = &unsafe { self.0.as_ref().unwrap() }.uc_mcontext;
16+
mcontext.mc_rip as *const _
17+
}
18+
19+
#[inline]
20+
pub fn set_ip(self, new_ip: *const c_void) {
21+
let mut mcontext = &mut unsafe { self.0.as_mut().unwrap() }.uc_mcontext;
22+
mcontext.mc_rip = new_ip as i64;
23+
}
24+
25+
#[inline]
26+
pub fn set_rdi(self, new_rdi: u64) {
27+
let mut mcontext = &mut unsafe { self.0.as_mut().unwrap() }.uc_mcontext;
28+
mcontext.mc_rdi = new_rdi as i64;
29+
}
30+
}
31+
32+
#[repr(C)]
33+
#[derive(Clone, Copy)]
34+
pub struct UContext {
35+
context: *mut ucontext_t,
36+
}
37+
38+
impl UContext {
39+
#[inline]
40+
pub fn new(ptr: *mut c_void) -> Self {
41+
UContext {
42+
context: unsafe { (ptr as *mut ucontext_t).as_mut().expect("non-null context") },
43+
}
44+
}
45+
46+
pub fn as_ptr(&mut self) -> UContextPtr {
47+
UContextPtr::new(self.context as *mut _ as *mut _)
48+
}
49+
}
50+
51+
impl Into<UContext> for UContextPtr {
52+
#[inline]
53+
fn into(self) -> UContext {
54+
UContext { context: self.0 }
55+
}
56+
}

lucet-runtime/lucet-runtime-internals/src/sysdeps/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ mod macos;
44
#[cfg(target_os = "linux")]
55
mod linux;
66

7+
#[cfg(target_os = "freebsd")]
8+
mod freebsd;
9+
710
#[cfg(unix)]
811
mod unix;
912

@@ -13,5 +16,8 @@ pub use macos::*;
1316
#[cfg(target_os = "linux")]
1417
pub use linux::*;
1518

19+
#[cfg(target_os = "freebsd")]
20+
pub use freebsd::*;
21+
1622
#[cfg(unix)]
1723
pub use unix::*;

lucet-runtime/lucet-runtime-tests/src/guest_fault.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ macro_rules! guest_fault_tests {
258258
static ref RECOVERABLE_PTR_LOCK: Mutex<()> = Mutex::new(());
259259
}
260260

261-
#[cfg(target_os = "linux")]
261+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
262262
const INVALID_PERMISSION_FAULT: libc::c_int = SIGSEGV;
263-
#[cfg(not(target_os = "linux"))]
263+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
264264
const INVALID_PERMISSION_FAULT: libc::c_int = SIGBUS;
265265

266-
#[cfg(target_os = "linux")]
266+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
267267
const INVALID_PERMISSION_SIGNAL: Signal = Signal::SIGSEGV;
268-
#[cfg(not(target_os = "linux"))]
268+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
269269
const INVALID_PERMISSION_SIGNAL: Signal = Signal::SIGBUS;
270270

271271
$(
@@ -299,7 +299,7 @@ macro_rules! guest_fault_tests {
299299
4096,
300300
ProtFlags::PROT_NONE,
301301
MapFlags::MAP_ANON | MapFlags::MAP_PRIVATE,
302-
0,
302+
-1,
303303
0,
304304
)
305305
.expect("mmap succeeds") as *mut libc::c_char;

0 commit comments

Comments
 (0)