Parameter Passing
Like ordinary functions, system calls often require some input/output parameters, which may consist of actual values (i.e., numbers), addresses of variables in the address space of the User Mode process, or even addresses of data structures including pointers to User Mode functions (see the section "System Calls Related to Signal Handling" in Chapter 11).
Because the system_call( )
and
the sysenter_entry( )
functions are
the common entry points for all system calls in Linux, each of them has
at least one parameter: the system call number passed in the eax
register. For instance, if an application
program invokes the fork( )
wrapper routine, the eax
register is set to 2 (i.e., _ _NR_fork
) before executing the int $0x80
or sysenter
assembly language instruction.
Because the register is set by the wrapper routines included in the
libc library, programmers do not usually care about
the system call number.
The fork( )
system call does
not require other parameters. However, many system calls do require
additional parameters, which must be explicitly passed by the
application program. For instance, the mmap(
)
system call may require up to six additional parameters
(besides the system call number).
The parameters of ordinary C functions are usually passed by writing their values in the active program stack (either the User Mode stack or the Kernel Mode stack). Because system calls are a special kind of function that cross over from user to kernel land, neither the User ...
Get Understanding the Linux Kernel, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.