1_SYSCALL(2) Linux Programmer's Manual _SYSCALL(2)
2
3
4
6 _syscall - invoking a system call without library support (OBSOLETE)
7
9 #include <linux/unistd.h>
10
11 A _syscall macro
12
13 desired system call
14
16 The important thing to know about a system call is its prototype. You
17 need to know how many arguments, their types, and the function return
18 type. There are seven macros that make the actual call into the system
19 easier. They have the form:
20
21 _syscallX(type,name,type1,arg1,type2,arg2,...)
22
23 where
24
25 X is 0–6, which are the number of arguments taken by the system
26 call
27
28 type is the return type of the system call
29
30 name is the name of the system call
31
32 typeN is the Nth argument's type
33
34 argN is the name of the Nth argument
35
36 These macros create a function called name with the arguments you spec‐
37 ify. Once you include the _syscall() in your source file, you call the
38 system call by name.
39
41 /usr/include/linux/unistd.h
42
44 The use of these macros is Linux-specific, and deprecated.
45
47 Starting around kernel 2.6.18, the _syscall macros were removed from
48 header files supplied to user space. Use syscall(2) instead. (Some
49 architectures, notably ia64, never provided the _syscall macros; on
50 those architectures, syscall(2) was always required.)
51
52 The _syscall() macros do not produce a prototype. You may have to cre‐
53 ate one, especially for C++ users.
54
55 System calls are not required to return only positive or negative error
56 codes. You need to read the source to be sure how it will return
57 errors. Usually, it is the negative of a standard error code, for
58 example, -EPERM. The _syscall() macros will return the result r of the
59 system call when r is nonnegative, but will return -1 and set the vari‐
60 able errno to -r when r is negative. For the error codes, see
61 errno(3).
62
63 When defining a system call, the argument types must be passed by-value
64 or by-pointer (for aggregates like structs).
65
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <errno.h>
70 #include <linux/unistd.h> /* for _syscallX macros/related stuff */
71 #include <linux/kernel.h> /* for struct sysinfo */
72
73 _syscall1(int, sysinfo, struct sysinfo *, info);
74
75 int
76 main(void)
77 {
78 struct sysinfo s_info;
79 int error;
80
81 error = sysinfo(&s_info);
82 printf("code error = %d\n", error);
83 printf("Uptime = %lds\nLoad: 1 min %lu / 5 min %lu / 15 min %lu\n"
84 "RAM: total %lu / free %lu / shared %lu\n"
85 "Memory in buffers = %lu\nSwap: total %lu / free %lu\n"
86 "Number of processes = %d\n",
87 s_info.uptime, s_info.loads[0],
88 s_info.loads[1], s_info.loads[2],
89 s_info.totalram, s_info.freeram,
90 s_info.sharedram, s_info.bufferram,
91 s_info.totalswap, s_info.freeswap,
92 s_info.procs);
93 exit(EXIT_SUCCESS);
94 }
95
96 Sample output
97 code error = 0
98 uptime = 502034s
99 Load: 1 min 13376 / 5 min 5504 / 15 min 1152
100 RAM: total 15343616 / free 827392 / shared 8237056
101 Memory in buffers = 5066752
102 Swap: total 27881472 / free 24698880
103 Number of processes = 40
104
106 intro(2), syscall(2), errno(3)
107
109 This page is part of release 5.04 of the Linux man-pages project. A
110 description of the project, information about reporting bugs, and the
111 latest version of this page, can be found at
112 https://www.kernel.org/doc/man-pages/.
113
114
115
116Linux 2019-03-06 _SYSCALL(2)