21.3: Appendix C - System Services
- Page ID
- 54595
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)This appendix provides a listing and brief description of a subset of the system service calls. This list is for 64-bit Ubuntu systems. A more complete list can be obtained from multiple web sources.
23.1 Return Codes
The system call will return a code in the rax register. If the value returned is less than 0, that is an indication that an error has occurred. If the operation is successful, the value returned will depend on the specific system service. Refer to the Error Codes section for additional information regarding the values of the error codes.
23.2 Basic System Services
The following table summarizes the more common system services.
Call Code (rax) |
System Service |
Description |
0 |
SYS_read |
Read characters |
rdi = file descriptor (of where to read from) |
||
rsi = address of where to store characters |
||
rdx = count of characters to read |
||
If unsuccessful, returns negative value. If successful, returns count of characters actually read. |
||
1 |
SYS_write |
Write characters |
rdi = file descriptor (of where to write to) |
||
rsi = address of characters to write |
||
rdx = count of characters to write |
||
If unsuccessful, returns negative value. If successful, returns count of characters actually written. |
||
2 |
SYS_open |
Open a file |
rdi = address of NULL terminated file name |
||
rsi = file status flags (typically O_RDONLY) |
||
If unsuccessful, returns negative value. If successful, returns file descriptor. |
||
3 |
SYS_close |
Close an open file |
rdi = file descriptor of open file to close |
||
If unsuccessful, returns negative value. |
||
8 |
SYS_lseek |
Reposition the file read/write file offset. |
rdi = file descriptor (of where to write to) |
||
rsi = offset |
||
rdx = origin |
||
If unsuccessful, returns negative value. |
||
57 |
SYS_fork |
Fork current process. |
59 |
SYS_execve |
Execute a program |
rdi = Address of NULL terminated string for name of program to execute. |
||
60 |
SYS_exit |
Terminate executing process. |
rdi = exit status (typically 0) |
||
85 |
SYS_creat |
Open/Create a file. |
rdi = address of NULL terminated file name |
||
rsi = file mode flags |
||
If unsuccessful, returns negative value. If successful, returns file descriptor. |
||
96 |
SYS_gettimeofday |
Get date and time of day |
rdi = address of time value structure |
||
rsi = address of time zone structure |
||
If unsuccessful, returns negative value. If successful, returns information in the passed structures. |
||
23.3 File Modes
When performing file operations, the file mode provides information to the operating system regarding the file access permissions that will be allowed.
When opening an existing file, one of the following file modes must be specified.
Mode |
Value |
Description |
O_RDONLY |
0 |
Read only. Allow reading from the file, but to not allow writing to the file. Most common operation. |
O_WRONLY |
1 |
Write only. Typically used if information is to be appended to a file. |
O_RDWR |
2 |
Allow simultaneous reading and writing. |
When creating a new file, the file permissions must be specified. Below are the complete set of file permissions. As is standard for Linux file systems, the permission values are specified in Octal.
Mode |
Value |
Description |
S_IRWXU |
00700q |
User (file owner) has read, write, and execute permission. |
S_IRUSR |
00400q |
User (file owner) has read permission. |
S_IWUSR |
00200q |
User (file owner) has write permission. |
S_IXUSR |
00100q |
User (file owner) has execute permission. |
S_IRWXG |
00070q |
Group has read, write, and execute permission. |
S_IRGRP |
00040q |
Group has read permission. |
S_IWGRP |
00020q |
Group has write permission. |
S_IXGRP |
00010q |
Group has execute permission. |
S_IRWXO |
00007q |
Others have read, write, and execute permission. |
S_IROTH |
00004q |
Others have read permission. |
S_IWOTH |
00002q |
Others have write permission. |
S_IXOTH |
00001q |
Others have execute permission. |
The text examples only address permissions for the user or owner of the file.
23.4 Error Codes
If a system service returns an error, the value of the return code will be negative. The following is a list of the error code. The code value is provided along with the Linux symbolic name. High-level languages typically use the name which is not used at the assembly level and is only provided for reference.
Error Code |
Symbolic Name |
Description |
-1 |
EPERM |
Operation not permitted. |
-2 |
ENOENT |
No such file or directory. |
-3 |
ESRCH |
No such process. |
-4 |
EINTR |
Interrupted system call. |
-5 |
EIO |
I/O Error. |
-6 |
ENXIO |
No such device or address. |
-7 |
E2BIG |
Argument list too long. |
-8 |
ENOEXEC |
Exec format error. |
-9 |
EBADF |
Bad file number. |
-10 |
ECHILD |
No child process. |
-11 |
EAGAIN |
Try again. |
-12 |
ENOMEM |
Out of memory. |
-13 |
EACCES |
Permission denied. |
-14 |
EFAULT |
Bad address. |
-15 |
ENOTBLK |
Block device required. |
-16 |
EBUSY |
Device or resource busy. |
-17 |
EEXIST |
File exists. |
-18 |
EXDEV |
Cross-device link. |
-19 |
ENODEV |
No such device. |
-20 |
ENOTDIR |
Not a directory. |
-21 |
EISDIR |
Is a directory. |
-22 |
EINV AL |
Invalid argument. |
-23 |
ENFILE |
File table overflow. |
-24 |
EMFILE |
Too many open files. |
-25 |
ENOTTY |
Not a typewriter. |
-26 |
ETXTBSY |
Text file busy. |
-27 |
EFBIG |
File too large. |
-28 |
ENOSPC |
No space left on device. |
-29 |
ESPIPE |
Illegal seek. |
-30 |
EROFS |
Read-only file system. |
-31 |
EMLINK |
Too many links. |
-32 |
EPIPE |
Broken pipe. |
-33 |
EDOM |
Math argument out of domain of function. |
-34 |
ERANGE |
Math result not representable. |
Only the most common error codes are shown. A complete list can be found via the Internet or by looking on the current system includes files. For Ubuntu, this is typically located in /usr/include/asm-generic/errno-base.h.