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:

#![feature(phase)]

#[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. :)

8 comments:

  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. http://man7.org/linux/man-pages/man7/vdso.7.html

    ReplyDelete
  2. Indeed https://github.com/kmcallister/syscall.rs/issues/4

    ReplyDelete
  3. i really like your blog, thanks for share...
    please visit are website..
    http://packersmoversbhopal.in/
    http://packersmoversbhopal.in/packers-and-movers-indore

    ReplyDelete
  4. "Enjoyed every bit of your blog article.Really looking forward to read more. Really Cool
    Packers And Movers Hyderabad

    ReplyDelete
  5. Brilliant information being shared here with us,This is very interesting, You’re a very skilled blogger.Plz visit here: Packers And Movers Jaipur

    ReplyDelete