]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man/man2/_syscall.2
man/, share/mk/: Move man*/ to man/
[thirdparty/man-pages.git] / man / man2 / _syscall.2
CommitLineData
53780d2e
MK
1.\" Copyright (c) 1993 Michael Haardt (michael@moria.de),
2.\" Fri Apr 2 11:32:09 MET DST 1993
3.\"
e4a74ca8 4.\" SPDX-License-Identifier: GPL-2.0-or-later
53780d2e
MK
5.\"
6.\" Tue Jul 6 12:42:46 MDT 1993 <dminer@nyx.cs.du.edu>
7.\" Added "Calling Directly" and supporting paragraphs
8.\"
9.\" Modified Sat Jul 24 15:19:12 1993 by Rik Faith <faith@cs.unc.edu>
10.\"
11.\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
12.\" Added explanation of arg stacking when 6 or more args.
13.\"
14.\" Modified 10 June 1995 by Andries Brouwer <aeb@cwi.nl>
15.\"
38f76cd2 16.\" 2007-10-23 mtk: created as a new page, by taking the content
53780d2e
MK
17.\" specific to the _syscall() macros from intro(2).
18.\"
4c1c5274 19.TH _syscall 2 (date) "Linux man-pages (unreleased)"
53780d2e
MK
20.SH NAME
21_syscall \- invoking a system call without library support (OBSOLETE)
47297adb 22.SH SYNOPSIS
c7db92b9 23.nf
53780d2e 24.B #include <linux/unistd.h>
c6d039a3 25.P
53780d2e 26A _syscall macro
c6d039a3 27.P
53780d2e 28desired system call
c7db92b9 29.fi
53780d2e
MK
30.SH DESCRIPTION
31The important thing to know about a system call is its prototype.
32You need to know how many arguments, their types,
33and the function return type.
de5c8e39 34There are seven macros that make the actual call into the system easier.
53780d2e 35They have the form:
c6d039a3 36.P
bdd915e2
MK
37.in +4n
38.EX
53780d2e 39.RI _syscall X ( type , name , type1 , arg1 , type2 , arg2 ,...)
bdd915e2
MK
40.EE
41.in
c6d039a3 42.P
a6e2f128
MK
43where
44.IP
c6fa0841 45.I X
523869f6 46is 0\[en]6, which are the number of arguments taken by the
53780d2e 47system call
a6e2f128 48.IP
c6fa0841
MK
49.I type
50is the return type of the system call
a6e2f128 51.IP
c6fa0841
MK
52.I name
53is the name of the system call
a6e2f128 54.IP
c6fa0841
MK
55.I typeN
56is the Nth argument's type
a6e2f128 57.IP
c6fa0841
MK
58.I argN
59is the name of the Nth argument
c6d039a3 60.P
c6fa0841
MK
61These macros create a function called
62.I name
63with the arguments you
53780d2e
MK
64specify.
65Once you include the _syscall() in your source file,
c6fa0841
MK
66you call the system call by
67.IR name .
53780d2e
MK
68.SH FILES
69.I /usr/include/linux/unistd.h
3113c7f3 70.SH STANDARDS
4131356c
AC
71Linux.
72.SH HISTORY
73Starting around Linux 2.6.18, the _syscall macros were removed
53780d2e
MK
74from header files supplied to user space.
75Use
76.BR syscall (2)
77instead.
78(Some architectures, notably ia64, never provided the _syscall macros;
79on those architectures,
80.BR syscall (2)
81was always required.)
4131356c 82.SH NOTES
c6fa0841
MK
83The _syscall() macros
84.I "do not"
85produce a prototype.
53780d2e
MK
86You may have to
87create one, especially for C++ users.
c6d039a3 88.P
53780d2e
MK
89System calls are not required to return only positive or negative error
90codes.
91You need to read the source to be sure how it will return errors.
92Usually, it is the negative of a standard error code,
444f1c6c 93for example,
c6fa0841
MK
94.RI \- EPERM .
95The _syscall() macros will return the result
96.I r
97of the system call
98when
99.I r
100is nonnegative, but will return \-1 and set the variable
53780d2e 101.I errno
c6fa0841
MK
102to
103.RI \- r
104when
105.I r
106is negative.
53780d2e
MK
107For the error codes, see
108.BR errno (3).
c6d039a3 109.P
c6fa0841
MK
110When defining a system call, the argument types
111.I must
112be
53780d2e
MK
113passed 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).
33a0ccb2 117.\" However, this mechanism can be used only if using a libc
53780d2e
MK
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.\"
a14af333 125.SH EXAMPLES
8a60e58b 126.\" SRC BEGIN (_syscall.c)
207050fa 127.EX
53780d2e
MK
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 */
fe5dba13 133\&
53780d2e 134_syscall1(int, sysinfo, struct sysinfo *, info);
fe5dba13 135\&
53780d2e
MK
136int
137main(void)
138{
139 struct sysinfo s_info;
140 int error;
fe5dba13 141\&
53780d2e 142 error = sysinfo(&s_info);
d1a71985
MK
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",
53780d2e
MK
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}
207050fa 156.EE
33857069 157.\" SRC END
73d8cece 158.SS Sample output
207050fa 159.EX
53780d2e
MK
160code error = 0
161uptime = 502034s
162Load: 1 min 13376 / 5 min 5504 / 15 min 1152
163RAM: total 15343616 / free 827392 / shared 8237056
164Memory in buffers = 5066752
165Swap: total 27881472 / free 24698880
166Number of processes = 40
207050fa 167.EE
47297adb 168.SH SEE ALSO
53780d2e
MK
169.BR intro (2),
170.BR syscall (2),
171.BR errno (3)