| 1 |
.\" Copyright (c) 1993 Michael Haardt ([email protected]), |
| 2 |
.\" Fri Apr 2 11:32:09 MET DST 1993 |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
.\" |
| 6 |
.\" Tue Jul 6 12:42:46 MDT 1993 <[email protected]> |
| 7 |
.\" Added "Calling Directly" and supporting paragraphs |
| 8 |
.\" |
| 9 |
.\" Modified Sat Jul 24 15:19:12 1993 by Rik Faith <[email protected]> |
| 10 |
.\" |
| 11 |
.\" Modified 21 Aug 1994 by Michael Chastain <[email protected]>: |
| 12 |
.\" Added explanation of arg stacking when 6 or more args. |
| 13 |
.\" |
| 14 |
.\" Modified 10 June 1995 by Andries Brouwer <[email protected]> |
| 15 |
.\" |
| 16 |
.\" 2007-10-23 mtk: created as a new page, by taking the content |
| 17 |
.\" specific to the _syscall() macros from intro(2). |
| 18 |
.\" |
| 19 |
.TH _syscall 2 2024-06-15 "Linux man-pages 6.9.1" |
| 20 |
.SH NAME |
| 21 |
_syscall \- invoking a system call without library support (OBSOLETE) |
| 22 |
.SH SYNOPSIS |
| 23 |
.nf |
| 24 |
.B #include <linux/unistd.h> |
| 25 |
.P |
| 26 |
A _syscall macro |
| 27 |
.P |
| 28 |
desired system call |
| 29 |
.fi |
| 30 |
.SH DESCRIPTION |
| 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. |
| 35 |
They have the form: |
| 36 |
.P |
| 37 |
.in +4n |
| 38 |
.EX |
| 39 |
.RI _syscall X ( type , name , type1 , arg1 , type2 , arg2 ,...) |
| 40 |
.EE |
| 41 |
.in |
| 42 |
.P |
| 43 |
where |
| 44 |
.IP |
| 45 |
.I X |
| 46 |
is 0\[en]6, which are the number of arguments taken by the |
| 47 |
system call |
| 48 |
.IP |
| 49 |
.I type |
| 50 |
is the return type of the system call |
| 51 |
.IP |
| 52 |
.I name |
| 53 |
is the name of the system call |
| 54 |
.IP |
| 55 |
.I typeN |
| 56 |
is the Nth argument's type |
| 57 |
.IP |
| 58 |
.I argN |
| 59 |
is the name of the Nth argument |
| 60 |
.P |
| 61 |
These macros create a function called |
| 62 |
.I name |
| 63 |
with the arguments you |
| 64 |
specify. |
| 65 |
Once you include the _syscall() in your source file, |
| 66 |
you call the system call by |
| 67 |
.IR name . |
| 68 |
.SH FILES |
| 69 |
.I /usr/include/linux/unistd.h |
| 70 |
.SH STANDARDS |
| 71 |
Linux. |
| 72 |
.SH HISTORY |
| 73 |
Starting around Linux 2.6.18, the _syscall macros were removed |
| 74 |
from header files supplied to user space. |
| 75 |
Use |
| 76 |
.BR syscall (2) |
| 77 |
instead. |
| 78 |
(Some architectures, notably ia64, never provided the _syscall macros; |
| 79 |
on those architectures, |
| 80 |
.BR syscall (2) |
| 81 |
was always required.) |
| 82 |
.SH NOTES |
| 83 |
The _syscall() macros |
| 84 |
.I "do not" |
| 85 |
produce a prototype. |
| 86 |
You may have to |
| 87 |
create one, especially for C++ users. |
| 88 |
.P |
| 89 |
System calls are not required to return only positive or negative error |
| 90 |
codes. |
| 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, |
| 93 |
for example, |
| 94 |
.RI \- EPERM . |
| 95 |
The _syscall() macros will return the result |
| 96 |
.I r |
| 97 |
of the system call |
| 98 |
when |
| 99 |
.I r |
| 100 |
is nonnegative, but will return \-1 and set the variable |
| 101 |
.I errno |
| 102 |
to |
| 103 |
.RI \- r |
| 104 |
when |
| 105 |
.I r |
| 106 |
is negative. |
| 107 |
For the error codes, see |
| 108 |
.BR errno (3). |
| 109 |
.P |
| 110 |
When defining a system call, the argument types |
| 111 |
.I must |
| 112 |
be |
| 113 |
passed by-value or by-pointer (for aggregates like structs). |
| 114 |
.\" The preferred way to invoke system calls that glibc does not know |
| 115 |
.\" about yet is via |
| 116 |
.\" .BR syscall (2). |
| 117 |
.\" However, this mechanism can be used only if using a libc |
| 118 |
.\" (such as glibc) that supports |
| 119 |
.\" .BR syscall (2), |
| 120 |
.\" and if the |
| 121 |
.\" .I <sys/syscall.h> |
| 122 |
.\" header file contains the required SYS_foo definition. |
| 123 |
.\" Otherwise, the use of a _syscall macro is required. |
| 124 |
.\" |
| 125 |
.SH EXAMPLES |
| 126 |
.\" SRC BEGIN (_syscall.c) |
| 127 |
.EX |
| 128 |
#include <stdio.h> |
| 129 |
#include <stdlib.h> |
| 130 |
#include <errno.h> |
| 131 |
#include <linux/unistd.h> /* for _syscallX macros/related stuff */ |
| 132 |
#include <linux/kernel.h> /* for struct sysinfo */ |
| 133 |
\& |
| 134 |
_syscall1(int, sysinfo, struct sysinfo *, info); |
| 135 |
\& |
| 136 |
int |
| 137 |
main(void) |
| 138 |
{ |
| 139 |
struct sysinfo s_info; |
| 140 |
int error; |
| 141 |
\& |
| 142 |
error = sysinfo(&s_info); |
| 143 |
printf("code error = %d\[rs]n", error); |
| 144 |
printf("Uptime = %lds\[rs]nLoad: 1 min %lu / 5 min %lu / 15 min %lu\[rs]n" |
| 145 |
"RAM: total %lu / free %lu / shared %lu\[rs]n" |
| 146 |
"Memory in buffers = %lu\[rs]nSwap: total %lu / free %lu\[rs]n" |
| 147 |
"Number of processes = %d\[rs]n", |
| 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, |
| 153 |
s_info.procs); |
| 154 |
exit(EXIT_SUCCESS); |
| 155 |
} |
| 156 |
.EE |
| 157 |
.\" SRC END |
| 158 |
.SS Sample output |
| 159 |
.EX |
| 160 |
code error = 0 |
| 161 |
uptime = 502034s |
| 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 |
| 167 |
.EE |
| 168 |
.SH SEE ALSO |
| 169 |
.BR intro (2), |
| 170 |
.BR syscall (2), |
| 171 |
.BR errno (3) |