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.
- 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
- Kernel developers requiring direct syscall access
- Systems programmers bypassing libc overhead
- Security researchers analyzing syscall behavior
Add to your Cargo.toml:
[dependencies]
syscaller = { version = "0.1", features = ["macro"] }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 syscallThe 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()) };The core library provides hand-written x86_64 assembly implementations:
syscall0throughsyscall6- Support 0-6 arguments- Follows System V ABI calling conventions
#![no_std]compatible with zero dependencies- Optimized for minimal overhead
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
- All functions are marked
unsafeas 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
Currently supports:
- Linux x86_64
Planned support:
- Linux ARM64
- Linux x86
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.