246 lines
6.4 KiB
HTML
246 lines
6.4 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of _SYSCALL</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>_SYSCALL</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
_syscall - invoking a system call without library support (OBSOLETE)
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/linux/unistd.h">linux/unistd.h</A>></B>
|
|
|
|
<P>
|
|
|
|
A _syscall macro
|
|
<P>
|
|
|
|
desired system call
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The important thing to know about a system call is its prototype.
|
|
You need to know how many arguments, their types,
|
|
and the function return type.
|
|
There are seven macros that make the actual call into the system easier.
|
|
They have the form:
|
|
<P>
|
|
|
|
|
|
|
|
_syscall<I>X</I>(<I>type</I>,<I>name</I>,<I>type1</I>,<I>arg1</I>,<I>type2</I>,<I>arg2</I>,...)
|
|
|
|
|
|
|
|
<P>
|
|
|
|
where
|
|
<DL COMPACT>
|
|
<DT id="1"><DD>
|
|
<I>X</I>
|
|
|
|
is 0-6, which are the number of arguments taken by the
|
|
system call
|
|
<DT id="2"><DD>
|
|
<I>type</I>
|
|
|
|
is the return type of the system call
|
|
<DT id="3"><DD>
|
|
<I>name</I>
|
|
|
|
is the name of the system call
|
|
<DT id="4"><DD>
|
|
<I>typeN</I>
|
|
|
|
is the Nth argument's type
|
|
<DT id="5"><DD>
|
|
<I>argN</I>
|
|
|
|
is the name of the Nth argument
|
|
</DL>
|
|
<P>
|
|
|
|
These macros create a function called
|
|
<I>name</I>
|
|
|
|
with the arguments you
|
|
specify.
|
|
Once you include the _syscall() in your source file,
|
|
you call the system call by
|
|
<I>name</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>FILES</H2>
|
|
|
|
<I>/usr/include/linux/unistd.h</I>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The use of these macros is Linux-specific, and deprecated.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Starting around kernel 2.6.18, the _syscall macros were removed
|
|
from header files supplied to user space.
|
|
Use
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2)
|
|
|
|
instead.
|
|
(Some architectures, notably ia64, never provided the _syscall macros;
|
|
on those architectures,
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2)
|
|
|
|
was always required.)
|
|
<P>
|
|
|
|
The _syscall() macros
|
|
<I>do not</I>
|
|
|
|
produce a prototype.
|
|
You may have to
|
|
create one, especially for C++ users.
|
|
<P>
|
|
|
|
System calls are not required to return only positive or negative error
|
|
codes.
|
|
You need to read the source to be sure how it will return errors.
|
|
Usually, it is the negative of a standard error code,
|
|
for example,
|
|
-<I>EPERM</I>.
|
|
|
|
The _syscall() macros will return the result
|
|
<I>r</I>
|
|
|
|
of the system call
|
|
when
|
|
<I>r</I>
|
|
|
|
is nonnegative, but will return -1 and set the variable
|
|
<I>errno</I>
|
|
|
|
to
|
|
-<I>r</I>
|
|
|
|
when
|
|
<I>r</I>
|
|
|
|
is negative.
|
|
For the error codes, see
|
|
<B><A HREF="/cgi-bin/man/man2html?3+errno">errno</A></B>(3).
|
|
|
|
<P>
|
|
|
|
When defining a system call, the argument types
|
|
<I>must</I>
|
|
|
|
be
|
|
passed by-value or by-pointer (for aggregates like structs).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/errno.h">errno.h</A>>
|
|
#include <<A HREF="file:///usr/include/linux/unistd.h">linux/unistd.h</A>> /* for _syscallX macros/related stuff */
|
|
#include <<A HREF="file:///usr/include/linux/kernel.h">linux/kernel.h</A>> /* for struct sysinfo */
|
|
<P>
|
|
_syscall1(int, sysinfo, struct sysinfo *, info);
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct sysinfo s_info;
|
|
<BR> int error;
|
|
<P>
|
|
<BR> error = sysinfo(&s_info);
|
|
<BR> printf("code error = %d\n", error);
|
|
<BR> printf("Uptime = %lds\nLoad: 1 min %lu / 5 min %lu / 15 min %lu\n"
|
|
<BR> "RAM: total %lu / free %lu / shared %lu\n"
|
|
<BR> "Memory in buffers = %lu\nSwap: total %lu / free %lu\n"
|
|
<BR> "Number of processes = %d\n",
|
|
<BR> s_info.uptime, s_info.loads[0],
|
|
<BR> s_info.loads[1], s_info.loads[2],
|
|
<BR> s_info.totalram, s_info.freeram,
|
|
<BR> s_info.sharedram, s_info.bufferram,
|
|
<BR> s_info.totalswap, s_info.freeswap,
|
|
<BR> s_info.procs);
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Sample output</H3>
|
|
|
|
|
|
code error = 0
|
|
uptime = 502034s
|
|
Load: 1 min 13376 / 5 min 5504 / 15 min 1152
|
|
RAM: total 15343616 / free 827392 / shared 8237056
|
|
Memory in buffers = 5066752
|
|
Swap: total 27881472 / free 24698880
|
|
Number of processes = 40
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+intro">intro</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+errno">errno</A></B>(3)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">FILES</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="13"><A HREF="#lbAI">Sample output</A><DD>
|
|
</DL>
|
|
<DT id="14"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="15"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|