SYSCALL(2)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

๐Ÿ’… SYSCALL(2) โ€” the indirect system call page, bestie edition

okay so this is the syscall(2) page from the System Calls Manual, and honestly? it's a little icon. let's get into it ๐Ÿซถ


โœจ NAME โœจ

syscall, __syscall โ€” indirect system call

like, you're calling a syscall indirectly, iykyk ๐Ÿ’ซ

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C Library (libc, -lc)

yep, the classic. the one that's literally always there ๐ŸŽ€

๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <sys/syscall.h>
#include <unistd.h>

int
syscall(int number, ...);

off_t
__syscall(quad_t number, ...);

two headers, two functions. that's the whole vibe check โœจ

๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so the way syscall() works is, it performs the system call whose assembly language interface has the specified number with the specified arguments. that's it, that's the whole thing โ€” you hand it a number, it goes and does the syscall ๐Ÿ’…

Symbolic constants for system calls can be found in the header file <sys/syscall.h. so like, please don't just memorize raw numbers, the constants are right there ๐Ÿงš

the __syscall() form should be used when one or more of the arguments is a 64-bit argument to ensure that argument alignment is correct. lowkey important โ€” misaligned args are not the moment, ngl ๐Ÿ˜ญ

this system call is useful for testing new system calls that do not have entries in the C library. so when the libc hasn't caught up yet and you're feeling brave? this is your girl. main character energy fr fr ๐Ÿ‘‘

๐Ÿ”ฅ RETURN VALUES ๐Ÿ”ฅ

the return values are defined by the system call being invoked. like, it's not gonna tell you here, it depends on what you asked for.

in general, a 0 return value indicates success ๐Ÿ’š a -1 return value indicates an error, and an error code is stored in errno. so if you get -1, go check errno, that's where the tea is ๐Ÿ“

๐Ÿฆ‹ HISTORY ๐Ÿฆ‹

the syscall() function appeared in 4.0BSD. vintage! iconic! ๐Ÿ’œ

๐Ÿ‘‘ BUGS ๐Ÿ‘‘

there is no way to simulate system calls that have multiple return values such as pipe(2). so like, if a syscall hands back more than one thing? this trick just cannot do it. periodt ๐Ÿ’€

okay bestie that's the whole page ๐ŸŒˆ huge thanks to the Debian crew for this one โ€” this version is from Debian, dated June 16, 1993, so it's older than most of your faves and it's still serving ๐Ÿ’…โœจ ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms