man-pages/man2/_syscall.2.html
2021-03-31 01:06:50 +01:00

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">&nbsp;</A>
<H2>NAME</H2>
_syscall - invoking a system call without library support (OBSOLETE)
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/linux/unistd.h">linux/unistd.h</A>&gt;</B>
<P>
A _syscall macro
<P>
desired system call
<A NAME="lbAD">&nbsp;</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">&nbsp;</A>
<H2>FILES</H2>
<I>/usr/include/linux/unistd.h</I>
<A NAME="lbAF">&nbsp;</A>
<H2>CONFORMING TO</H2>
The use of these macros is Linux-specific, and deprecated.
<A NAME="lbAG">&nbsp;</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">&nbsp;</A>
<H2>EXAMPLE</H2>
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/linux/unistd.h">linux/unistd.h</A>&gt; /* for _syscallX macros/related stuff */
#include &lt;<A HREF="file:///usr/include/linux/kernel.h">linux/kernel.h</A>&gt; /* for struct sysinfo */
<P>
_syscall1(int, sysinfo, struct sysinfo *, info);
<P>
int
main(void)
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;sysinfo&nbsp;s_info;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;error;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;error&nbsp;=&nbsp;sysinfo(&amp;s_info);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;code&nbsp;error&nbsp;=&nbsp;%d\n&quot;,&nbsp;error);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Uptime&nbsp;=&nbsp;%lds\nLoad:&nbsp;1&nbsp;min&nbsp;%lu&nbsp;/&nbsp;5&nbsp;min&nbsp;%lu&nbsp;/&nbsp;15&nbsp;min&nbsp;%lu\n&quot;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;RAM:&nbsp;total&nbsp;%lu&nbsp;/&nbsp;free&nbsp;%lu&nbsp;/&nbsp;shared&nbsp;%lu\n&quot;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Memory&nbsp;in&nbsp;buffers&nbsp;=&nbsp;%lu\nSwap:&nbsp;total&nbsp;%lu&nbsp;/&nbsp;free&nbsp;%lu\n&quot;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Number&nbsp;of&nbsp;processes&nbsp;=&nbsp;%d\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.uptime,&nbsp;s_info.loads[0],
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.loads[1],&nbsp;s_info.loads[2],
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.totalram,&nbsp;s_info.freeram,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.sharedram,&nbsp;s_info.bufferram,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.totalswap,&nbsp;s_info.freeswap,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_info.procs);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAI">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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>