Syscalls for Rustaceans!

by Gargi Sharma   

Follow the slides:

What even is a systems programming language?

1970s:Improving on Assembly

"A system program is
an integrated set of
exceeding some
threshold of size
and/or complexity.

Systems Programming Languages
(Bergeron et al. 1972)


  • The system program is likely to be used to support other software programs.

  • It is designed for continued “production” use rather than a one-shot solution to a single applications problem.


A language which can be used without undue concern for bit twiddling.

Credit: Systems Programming (Donovan 1972)

1990s:Rise of Scripting languages


Rise of Scripting languages

  • Bash, languages like Perl, Python, Ruby, Javascript etc. worked their way into the mainstream.
  • Systems programming languages designed to build more primitive computer elements.
  • Scripting languages are designed for gluing.

2010s:Boundaries Blur


Boundaries Blur

  • Dropbox was able to build surprisingly large and scalable systems on just Python.
  • Javascript is used to render real-time, complex UIs in billions of web pages.
  • Gradual typing has gained steam in Javascript, Python, etc. enabling a transition from “prototype” code to “production” code.

What is a systems programming language today?

Where does Rust shine?

Systems programming is
programming where
you spend more time reading man pages than reading the internet.

- Kamal Mahrubi

Writing our own strace!

System Calls!


Around 330 system calls in Linux:

  • File Access - creat, read, write, open, close, etc.
  • Process Control - wait, waitpid , kill, fork, etc.
  • Network Access - socket, getsockopt , listen, etc.

What happens when a syscall occurs?

What happens when a syscall occurs?

Making a syscall.

  • Setup register with syscall number & parameters.
  • Send a trap to kernel.
  • Result stored in register.

What is strace?

  • A diagnostic, debugging and instructional userspace utility for Linux.
  • Invaluable for solving problems with programs for which the source is not readily available.

What is strace?

        fn main() {
          println!("Hello RustConf!");

What is strace?

Writing our own strace.

  • How to observe another process?
  • How to trap a system call?
  • How to fetch register values?

How to observe a process?


How to observe a process?

        let output = cmd.before_exec(ptrace::traceme());
        let mut child = cmd.spawn();

How to trap a system call?

How to trap a system call?


        waitpid(pid, None);

How to fetch register values?

        let res = ptrace::ptrace(
          PT_NULL as *mut c_void,
          &mut regs as *mut _ as *mut c_void,


Conclusion 😊

A Shoutout!

  1. Arshia Mufti
  2. Shalom Abete
  3. Hailey James-Sorenson
  4. Taylor James-Sorenson
  5. Carrie Wu
  6. Andrew Zuckerman
  7. Theo Constantinedes
  8. Charilaos Pipis
  9. Wassim Marrakchi
  10. Stephen Koo

Thank you!


  1. A Go Programmer's Guide to Syscalls
  2. Rust implementation of glibc
  3. System call table for Linux x86
  4. What is systems programming really?
  5. Scripting: Higher Level Programming for the 21st Century
  6. Rust + nix = easier unix systems programming
  7. Slide theme from @jlengstorf

Tweet: @gawwrgi