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

Commit 8cb7d8e

Browse files
committed
[lucet-runtime-internals] add UContext support for FreeBSD
1 parent cf53a3b commit 8cb7d8e

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

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

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

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

7+
#[cfg(target_os = "freebsd")]
8+
mod freebsd;
9+
710
#[cfg(target_os = "macos")]
811
pub use macos::*;
912

1013
#[cfg(target_os = "linux")]
1114
pub use linux::*;
15+
16+
#[cfg(target_os = "freebsd")]
17+
pub use freebsd::*;

0 commit comments

Comments
 (0)