Skip to content

mauri870/syscall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

syscall - Test a Linux system call

A port of the Plan 9 syscall command to Linux. Rather than going through libc, it calls syscall(2) directly, which makes it useful for testing kernel behaviour, understanding how system calls work, and quick scripting without writing C.

Not every Linux syscall is invocable this way — some require kernel structures that can't be expressed as plain scalars — but the most common ones work fine.

Build

make
make test
make install
make uninstall

Usage

syscall [-o -v -l -h] entry [arg ...]
Flag Effect
-o Print the contents of buf to stdout after the call
-n bytes With -o, print exactly bytes bytes using fwrite instead of stopping at the first null
-v Print the syscall return value to stderr
-l List all available syscalls and exit
-h Print usage and exit

Special arguments

Token Expands to
buf An 8 KB scratch buffer, passed as a pointer
stdin File descriptor 0
stdout File descriptor 1
stderr File descriptor 2

Up to 6 arguments can be passed, matching the maximum number of arguments any Linux syscall takes.

Examples

Write a string to standard output:

syscall write stdout hello 5

Read 5 bytes from stdin and print the buffer:

echo -n hello | syscall -o read stdin buf 5

Get the current working directory:

syscall -ov getcwd buf 100

Get the PID of the current process:

syscall -v getpid

Get 16 bytes of random data from the kernel (1 == GRND_RANDOM):

syscall -ov getrandom buf 16 1

Dump all fields of struct utsname across null bytes:

syscall -on 390 uname buf | tr '\0' ' ' | tr -s ' '

Create a directory:

syscall mkdir my-dir 0755

Rename a file:

syscall rename old-name new-name

Exit with a specific status code:

syscall exit 2

List all available syscalls:

syscall -l

About

syscall(1) - Test a linux system call

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors