Skip to content

Direct system call library for Rust - no_std syscall interfaces for kernel developers and systems programmers

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

mathyslv/syscaller

Repository files navigation

Syscaller

Crates.io Documentation License

A no-std Rust library providing direct system call interfaces for Linux x86_64 systems with hand-optimized assembly implementations and procedural macros for type-safe syscall wrapper generation.

Features

  • Direct Assembly: Hand-written x86_64 syscall implementations (0-6 arguments)
  • Type Safety: Procedural macros for generating safe wrappers from C signatures
  • No-std Compatible: Minimal dependencies for embedded/kernel development
  • Zero Dependencies: Core library has no external dependencies

Target Audience

  • Kernel developers requiring direct syscall access
  • Systems programmers bypassing libc overhead
  • Security researchers analyzing syscall behavior

Quick Start

Add to your Cargo.toml:

[dependencies]
syscaller = { version = "0.1", features = ["macro"] }

Direct Assembly Usage

syscaller defines 7 basic, low-level functions that allow to invoke a Linux syscall with 0 to 6 arguments (syscall0(...) to syscall6(...)).

Their signatures are syscallX(syscallId: usize, args...: usize).

use syscaller::*;

let written = unsafe { syscall3(1, 1, b"Hello, World!\n".as_ptr() as usize, 14) }; // write syscall

Macro Usage

The wrap_syscall proc-macro allow convenient conversion between C-like functions and syscallX calls.

Syntax

wrap_syscall! {
    syscallId1 : C-style-signature,
    syscallId2 : C-style-signature,
    ...
}

Example

The following :

syscall::wrap_syscall! {
    1 : ssize_t write(int fd, void *buf, size_t count),
    59 : int execve(const char *path, char *const *argv, char *const *envp),
}

Will generate this :

#[inline(always)]
pub unsafe fn write(fd: i32, buf: *mut u8, count: usize) -> isize {
    unsafe { syscaller::syscall3(1, fd as usize, buf as usize, count) as isize }
}

#[inline(always)]
pub unsafe fn execve(path: impl AsRef<[u8]>, argv: *mut u8, envp: *mut u8) -> i32 {
    unsafe {
        syscaller::syscall3(59, path.as_ref().as_ptr() as usize, argv as usize, envp as usize) as i32
    }
}

You can then use this more convenient function :

const HELLO: &str = "Hello, world!";

unsafe { write(1, HELLO.as_ptr().cast_mut(), HELLO.len()) };

Architecture

Core Library (syscaller)

The core library provides hand-written x86_64 assembly implementations:

  • syscall0 through syscall6 - Support 0-6 arguments
  • Follows System V ABI calling conventions
  • #![no_std] compatible with zero dependencies
  • Optimized for minimal overhead

Procedural Macro (syscaller-wrap-macro)

The macro crate provides type-safe wrapper generation:

  • Parses C-like function signatures
  • Generates Rust wrapper functions with proper types
  • Handles type conversions (pointers, integers, etc.)
  • Comprehensive error handling for malformed signatures

Safety

⚠️ This library provides direct access to system calls without safety guarantees.

  • All functions are marked unsafe as they can cause undefined behavior
  • Caller must ensure syscall numbers and arguments are valid
  • Improper usage can crash your program or system
  • Intended for advanced systems programming where direct control is needed

Platform Support

Currently supports:

  • Linux x86_64

Planned support:

  • Linux ARM64
  • Linux x86

License

Licensed under either of

at your option.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Direct system call library for Rust - no_std syscall interfaces for kernel developers and systems programmers

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages