_syscall(2)

πŸ’– _syscall(2) β€” the System Calls Manual, bestie edition πŸ’–

okay so this is the _syscall page, from the Linux System Calls Manual, and before we do literally anything else: this whole thing is OBSOLETE 😭. Like, retired. Vintage. Archive-core. DevOps girlies, do not build your whole personality on this one.


✨ NAME ✨

_syscall β€” invoking a system call without library support (OBSOLETE)

no cap, that "(OBSOLETE)" is doing so much heavy lifting in that sentence. it's giving "still on the syllabus but the professor keeps apologizing about it." πŸ’€


πŸŽ€ SYNOPSIS πŸŽ€

#include <linux/unistd.h>

A _syscall macro

desired system call


πŸ¦‹ DESCRIPTION πŸ¦‹

so the one thing you actually need to know about a system call is its prototype. like, the whole situation. you gotta know:

  • how many arguments it takes
  • what types those arguments are
  • what the function returns

and then there are seven macros that make the actual call into the system easier. seven!! a whole little squad ✨. they look like this:

_syscallX(type,name,type1,arg1,type2,arg2,...)

and here's the breakdown, icon by icon:

  • X is 0–6, which is literally just how many arguments the system call takes
  • type is the return type of the system call
  • name is the name of the system call
  • typeN is the Nth argument's type
  • argN is the name of the Nth argument

these macros create a function called name with the arguments you specify, and once you include the _syscall() in your source file, you just call the system call by name. that's it, that's the whole vibe. she's simple like that 🫢


πŸ“ FILES πŸ“

  • /usr/include/linux/unistd.h

🌈 STANDARDS 🌈

Linux. just Linux. that's the standard. periodt πŸ’…


πŸ‘‘ HISTORY πŸ‘‘

gather round, storytime πŸ“–:

starting around Linux 2.6.18, the _syscall macros were removed from the header files supplied to user space. so yeah, they're gone-gone. use syscall(2) instead, bestie, that's the move now.

and okay, extra lore: some architectures β€” notably ia64 β€” never provided the _syscall macros at all, not even once. on those architectures, syscall(2) was always required. they were ahead of the curve, honestly. main character energy. ⭐


🧚 NOTES 🧚

  • the _syscall() macros do not produce a prototype. so you may have to create one yourself, and this is especially a you-problem if you're a C++ user 😭. sorry C++ girlies, love you, mean it.
  • system calls are not required to return only positive or negative error codes. so like, you genuinely need to read the source to be sure how it will return errors. usually it's the negative of a standard error code β€” for example, -EPERM. here's the actual mechanic: the _syscall() macros return the result r of the system call when r is nonnegative, but return -1 and set the variable errno to -r when r is negative. for the error codes, go see errno(3). ✨
  • when defining a system call, the argument types must be passed by-value or by-pointer (this is for aggregates like structs, iykyk).

πŸ”₯ EXAMPLES πŸ”₯

okay here's a whole little program, look at her go:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/unistd.h>       /* for _syscallX macros/related stuff */
#include <linux/kernel.h>       /* for struct sysinfo */

_syscall1(int, sysinfo, struct sysinfo *, info);

int
main(void)
{
    struct sysinfo s_info;
    int error;

    error = sysinfo(&s_info);
    printf("code error = %d\n", error);
    printf("Uptime = %lds\nLoad: 1 min %lu / 5 min %lu / 15 min %lu\n"
           "RAM: total %lu / free %lu / shared %lu\n"
           "Memory in buffers = %lu\nSwap: total %lu / free %lu\n"
           "Number of processes = %d\n",
           s_info.uptime, s_info.loads[0],
           s_info.loads[1], s_info.loads[2],
           s_info.totalram, s_info.freeram,
           s_info.sharedram, s_info.bufferram,
           s_info.totalswap, s_info.freeswap,
           s_info.procs);
    exit(EXIT_SUCCESS);
}

🌸 Sample output 🌸

code error = 0
uptime = 502034s
Load: 1 min 13376 / 5 min 5504 / 15 min 1152
RAM: total 15343616 / free 827392 / shared 8237056
Memory in buffers = 5066752
Swap: total 27881472 / free 24698880
Number of processes = 40

look at that output. code error = 0, uptime 502034s, loads doing their little 1/5/15 minute thing, RAM numbers absolutely unhinged in size, buffers at 5066752, swap chilling, and 40 processes. she ate and left no crumbs πŸ”₯


πŸ‘― SEE ALSO πŸ‘―


and that's the whole page, bestie!! πŸŽ€πŸ’– if you take literally one thing from this it's that _syscall is a retired icon and you should be over on syscall(2) living your best life.

this cutie was brought to you by Linux man-pages 6.20, dated 2025-05-17 ✨ stay slay, read your errno, mwah πŸ’…πŸ«Ά

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-2.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms