Linux System CallsReleased to the Public Domain by Randall HydePage 3module to call the Linux APIs. If you choose to use the INT($80) calling mechanism instead, conversion is fairlytrivial (as noted above).
1.2A Quick Note About Naming Conventions
Most Linux documentation was written assuming that the reader would be calling Linux from a C/C++ program.While the HLA header ﬁles (and this document) attempt to stick as closely to the original Linux names as possible,there are a few areas where HLA names deviate from the C names. This can occur for any of three reasons:•The C name conﬂicts with an HLA reserved word (e.g., "exit" becomes "_exit" because "exit" is anHLA reserved word).•C uses different namespaces for structs and other objects and some Linux identiﬁers are the same forboth structs and variables (HLA doesn’t allow this).•HLA uses case neutral identiﬁers, C uses case sensitive identiﬁers. Therefore, if two C identiﬁers arethe same except for alphabetic case, one of them must be changed when converting to HLA.•Many Linux constant and macro declarations use the (stylistically dubious) convention of all uppercasecharacters. Since uppercase is hard to read, such identiﬁers have been converted to all lowercase in theHLA header ﬁles.
1.3A Quick Note About Error Return Values
C/C++ programmers probably expect Linux system calls to return -1 if an error occurs and then they expect toﬁnd the actual error code in the
global variable. Assembly language calls to Linux return the error statusdirectly in the EAX register. Generally, if the return value is non-negative, this indicates success and the value is afunction result. If the return value from a Linux system call is negative, this usually indicates some sort of error.Therefore, an assembly language program should test the value in EAX upon return for negative/non-negative todetermine the error status.Linux system calls return a wide range of negative values indicating different error values. The "linux.hhf"header ﬁle deﬁnes a set of symbolic constants in the
namespace so you can use symbolic names rather than lit-eral constants. These names and values are identical to those found in standard Linux documentation with threeexceptions: (1) the HLA naming convention uses lower case for these identiﬁers rather than all uppercase letters; e.g.,
. (2) Since the HLA names are all found in the
namespace, you refer to them using an"
." preﬁx, e.g., "
" is the correct way to specify the "error, invalid permissions" error code. (3) Theconstants in the
namespace are all negative. You do not have to explicitly negate them before comparing themwith the Linux system call return result (as you would when using the C constant declarations).
2Linux System Calls, by Functional Group
This section will describe the syntax and semantics of some of the more common Linux system calls, organizedby the type of the call.If you read the Linux on-line documentation concerning the system calls, keep on thing in mind. C StandardLibrary semantics require that a system call return "-1" for an error and the actual error value is in the
globalvariable. Direct Linux system calls don’t work this way. They usually return a negative value to indicate an error anda non-negative return value to indicate success. The error values that Linux functions typically return is the negatedcopy of the value the "C" documentation describes for
This section describes the Linux system calls responsible for ﬁle I/O. The principal functions are open, close,creat, read, write, and llseek. Advanced users make want to use some of the other functions as well.