Warning: main() [function.main]: open_basedir restriction in effect. File(/var/data/www/ods/ods.com.ua/htdocs/htdig/header.php) is not within the allowed path(s): (/home/ods/:/tmp:/usr/local/lib/php/) in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 4

Warning: main(/var/data/www/ods/ods.com.ua/htdocs/htdig/header.php) [function.main]: failed to open stream: Operation not permitted in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 4

Warning: main() [function.include]: Failed opening '/var/data/www/ods/ods.com.ua/htdocs/htdig/header.php' for inclusion (include_path='.:/usr/local/lib/php/') in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 4
next up previous contents
Next: 5 The ``swiss army Up: e Previous: 3 The Linux libc

4 System calls

A system call is usually a request to the operating system (kernel) to do a hardware/system-specific or privileged operation. As of Linux-1.2, 140 system calls have been defined. System calls like close() are implemented in the Linux libc. This implementation often involves calling a macro which eventually calls syscall(). Parameters passed to syscall() are the number of the system call followed by the needed arguments. The actual system call numbers can be found in <linux/unistd.h> while <sys/syscall.h> gets updated with a new libc. If new calls appear that don't have a stub in libc yet, you can use syscall(). As an example, you can close a file using syscall() like this (not advised):

#include <syscall.h>

extern int syscall(int, ...);

int my_close(int filedescriptor)
{
   return syscall(SYS_close, filedescriptor);
}

On the i386 architecture, system calls are limited to 5 arguments besides the system call number because of the number of hardware registers. If you use Linux on another architecture you can check <asm/unistd.h> for the _syscall macros to see how many arguments your hardware supports or how many the developers chose to support. These _syscall macros can be used instead of syscall(), but this is not recommended since such a macro expands to a full function which might already exist in a library. Therefore, only kernel hackers should play with the _syscall macros. To demonstrate, here is the close() example using a _syscall macro.

#include <linux/unistd.h>

_syscall1(int, close, int, filedescriptor);

The _syscall1 macro expands revealing the close() function. Thus we have close() twice-once in libc and once in our program. The return value of syscall() or a _syscall macro is -1 if the system call failed and 0 or greater on success. Take a look at the global variable errno to see what happened if a system call failed.

The following system calls that are available on BSD and SYS V are not available on Linux:
audit(), auditon(), auditsvc(), fchroot(), getauid(), getdents(), getmsg(), mincore(), poll(), putmsg(), setaudit(), setauid().


next up previous contents
Next: 5 The ``swiss army Up: e Previous: 3 The Linux libc

Converted on:
Fri Mar 29 14:43:04 EST 1996

Warning: main() [function.main]: open_basedir restriction in effect. File(/var/data/www/ods/ods.com.ua/htdocs/include/footer.php) is not within the allowed path(s): (/home/ods/:/tmp:/usr/local/lib/php/) in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 71

Warning: main(/var/data/www/ods/ods.com.ua/htdocs/include/footer.php) [function.main]: failed to open stream: Operation not permitted in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 71

Warning: main() [function.include]: Failed opening '/var/data/www/ods/ods.com.ua/htdocs/include/footer.php' for inclusion (include_path='.:/usr/local/lib/php/') in /home/ods/domains/ods.com.ua/public_html/win/eng/unix/lpg/node5.html on line 71