Crate rusty_doors
source ·Expand description
Rusty Doors
A streamlined and safe interface for creating and using Unix Doors.
A simple door server
use rusty_doors::{door_create, door_run};
use rusty_doors_macros::door;
use std::ffi::CString;
#[derive(Default)]
#[repr(C)]
struct Wrapped {
val: u64,
other: u16,
}
// To make a door handler just apply the #[door] attribute macro
#[door]
fn serv_proc(x: u64) -> Wrapped {
let res = x + 47;
println!("ARG: {}", x);
return Wrapped {
val: res,
other: 99,
};
}
fn main() {
let path = CString::new("/tmp/addr-test-door").expect("cstring");
let fd = door_create(serv_proc);
door_run(fd, path.as_c_str());
}
A door client
use rusty_doors::door_call;
use std::fs::File;
use std::os::unix::io::AsRawFd;
#[derive(Default)]
#[repr(C)]
struct Wrapped {
val: u64,
other: u16,
}
fn main() {
let file = File::open("/tmp/addr-test-door").expect("open fd");
let x: u64 = 74;
let res: Wrapped = door_call(file.as_raw_fd(), x);
assert_eq!(res.val, 121);
assert_eq!(res.other, 99);
}
Modules
System level doors elements.
Functions
Call the door referenced by
fd
with argument data x
. Returns door call
result by value.Call the door referenced by
fd
with argument slice x
. Returns doo call
result by value.Call the door referenced by
fd
with argument data x
. The address pointed
to by res
will be allocated by the door, and the result placed at that
location. The return value is the address to the pointed to address.Create a door. The provided
sys::DoorFunc
will be called any time this
door is called. Returns a file descriptor reference the created door.Run a door server for the door handler referenced by
fd
. fd
should be
the result of calling door_create
.