1 .\" Copyright (c) 1993 Michael Haardt (michael@moria.de),
2 .\" Fri Apr 2 11:32:09 MET DST 1993
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\" Tue Jul 6 12:42:46 MDT 1993 <dminer@nyx.cs.du.edu>
7 .\" Added "Calling Directly" and supporting paragraphs
9 .\" Modified Sat Jul 24 15:19:12 1993 by Rik Faith <faith@cs.unc.edu>
11 .\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
12 .\" Added explanation of arg stacking when 6 or more args.
14 .\" Modified 10 June 1995 by Andries Brouwer <aeb@cwi.nl>
16 .\" 2007-10-23 mtk: created as a new page, by taking the content
17 .\" specific to the _syscall() macros from intro(2).
19 .TH _SYSCALL 2 2022-09-09 "Linux man-pages (unreleased)"
21 _syscall \- invoking a system call without library support (OBSOLETE)
24 .B #include <linux/unistd.h>
31 The important thing to know about a system call is its prototype.
32 You need to know how many arguments, their types,
33 and the function return type.
34 There are seven macros that make the actual call into the system easier.
39 .RI _syscall X ( type , name , type1 , arg1 , type2 , arg2 ,...)
46 is 0\(en6, which are the number of arguments taken by the
50 is the return type of the system call
53 is the name of the system call
56 is the Nth argument's type
59 is the name of the Nth argument
61 These macros create a function called
63 with the arguments you
65 Once you include the _syscall() in your source file,
66 you call the system call by
69 .I /usr/include/linux/unistd.h
71 The use of these macros is Linux-specific, and deprecated.
73 Starting around kernel 2.6.18, the _syscall macros were removed
74 from header files supplied to user space.
78 (Some architectures, notably ia64, never provided the _syscall macros;
79 on those architectures,
87 create one, especially for C++ users.
89 System calls are not required to return only positive or negative error
91 You need to read the source to be sure how it will return errors.
92 Usually, it is the negative of a standard error code,
95 The _syscall() macros will return the result
100 is nonnegative, but will return \-1 and set the variable
107 For the error codes, see
110 When defining a system call, the argument types
113 passed by-value or by-pointer (for aggregates like structs).
114 .\" The preferred way to invoke system calls that glibc does not know
117 .\" However, this mechanism can be used only if using a libc
118 .\" (such as glibc) that supports
121 .\" .I <sys/syscall.h>
122 .\" header file contains the required SYS_foo definition.
123 .\" Otherwise, the use of a _syscall macro is required.
126 .\" [[deprecated]] SRC BEGIN (_syscall.c)
131 #include <linux/unistd.h> /* for _syscallX macros/related stuff */
132 #include <linux/kernel.h> /* for struct sysinfo */
134 _syscall1(int, sysinfo, struct sysinfo *, info);
139 struct sysinfo s_info;
142 error = sysinfo(&s_info);
143 printf("code error = %d\en", error);
144 printf("Uptime = %lds\enLoad: 1 min %lu / 5 min %lu / 15 min %lu\en"
145 "RAM: total %lu / free %lu / shared %lu\en"
146 "Memory in buffers = %lu\enSwap: total %lu / free %lu\en"
147 "Number of processes = %d\en",
148 s_info.uptime, s_info.loads[0],
149 s_info.loads[1], s_info.loads[2],
150 s_info.totalram, s_info.freeram,
151 s_info.sharedram, s_info.bufferram,
152 s_info.totalswap, s_info.freeswap,
162 Load: 1 min 13376 / 5 min 5504 / 15 min 1152
163 RAM: total 15343616 / free 827392 / shared 8237056
164 Memory in buffers = 5066752
165 Swap: total 27881472 / free 24698880
166 Number of processes = 40