]>
Commit | Line | Data |
---|---|---|
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 | 26 | A _syscall macro |
c6d039a3 | 27 | .P |
53780d2e | 28 | desired system call |
c7db92b9 | 29 | .fi |
53780d2e MK |
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. | |
de5c8e39 | 34 | There are seven macros that make the actual call into the system easier. |
53780d2e | 35 | They 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 |
43 | where |
44 | .IP | |
c6fa0841 | 45 | .I X |
523869f6 | 46 | is 0\[en]6, which are the number of arguments taken by the |
53780d2e | 47 | system call |
a6e2f128 | 48 | .IP |
c6fa0841 MK |
49 | .I type |
50 | is the return type of the system call | |
a6e2f128 | 51 | .IP |
c6fa0841 MK |
52 | .I name |
53 | is the name of the system call | |
a6e2f128 | 54 | .IP |
c6fa0841 MK |
55 | .I typeN |
56 | is the Nth argument's type | |
a6e2f128 | 57 | .IP |
c6fa0841 MK |
58 | .I argN |
59 | is the name of the Nth argument | |
c6d039a3 | 60 | .P |
c6fa0841 MK |
61 | These macros create a function called |
62 | .I name | |
63 | with the arguments you | |
53780d2e MK |
64 | specify. |
65 | Once you include the _syscall() in your source file, | |
c6fa0841 MK |
66 | you 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 |
71 | Linux. |
72 | .SH HISTORY | |
73 | Starting around Linux 2.6.18, the _syscall macros were removed | |
53780d2e MK |
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.) | |
4131356c | 82 | .SH NOTES |
c6fa0841 MK |
83 | The _syscall() macros |
84 | .I "do not" | |
85 | produce a prototype. | |
53780d2e MK |
86 | You may have to |
87 | create one, especially for C++ users. | |
c6d039a3 | 88 | .P |
53780d2e MK |
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, | |
444f1c6c | 93 | for example, |
c6fa0841 MK |
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 | |
53780d2e | 101 | .I errno |
c6fa0841 MK |
102 | to |
103 | .RI \- r | |
104 | when | |
105 | .I r | |
106 | is negative. | |
53780d2e MK |
107 | For the error codes, see |
108 | .BR errno (3). | |
c6d039a3 | 109 | .P |
c6fa0841 MK |
110 | When defining a system call, the argument types |
111 | .I must | |
112 | be | |
53780d2e MK |
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). | |
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 |
136 | int |
137 | main(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 |
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 | |
207050fa | 167 | .EE |
47297adb | 168 | .SH SEE ALSO |
53780d2e MK |
169 | .BR intro (2), |
170 | .BR syscall (2), | |
171 | .BR errno (3) |