Wednesday, September 17, 2014

Raw system calls for Rust

I wrote a small library for making raw system calls from Rust programs. It provides a macro that expands into in-line system call instructions, with no run-time dependencies at all. Here's an example:


#[phase(plugin, link)]
extern crate syscall;

fn write(fd: uint, buf: &[u8]) {
    unsafe {
        syscall!(WRITE, fd, buf.as_ptr(), buf.len());

fn main() {
    write(1, "Hello, world!\n".as_bytes());

Right now it only supports x86-64 Linux, but I'd love to add other platforms. Pull requests are much appreciated. :)


  1. On Linux, the kernel injects a "virtual dynamic library" into every process, containing optimal code for making system calls, including special fast-path code for especially performance-critical calls (e.g. clock_gettime). You should really use that if you possibly can.

  2. Indeed

  3. i really like your blog, thanks for share...
    please visit are website..