UMBC | CMSC 313 -- System Calls | Previous | Next |
Because of that, access to the system resources is what we call
privileged access and can only be done by the operating system.
The user program requests that the operating system provide
that access via a well-defined service. Then, assuming the
service was properly requested, that service will be provided.
What services are there? Currently, we are using a version of
the Linux kernel that is about 2.4.20-8 (different sites are
using different versions) which as 258 different services
The good news is that all systems have the same calls if that
call is defined for that system. This gives the programmer a
standard API when programming.
If you look at the write man page, which is written for
a C program, you find how to use it:
OK, what is a ssize_t and size_t? That is defined by your
system in the appropriate header file.
In the file /usr/include/asm/unistd.h> we find out the system
call number is 4:
EAX is set to four.
Remember, the man page listed the call as:
What about the return value? It is returned in the EAX register
every time.
Finding Out about System Calls
The system calls are usually given meaningful names, like
read, write, kill, fork, rename or lseek. The man page system
is set up to help you find out how to use them.
ssize_t write(int fd, const void *buf, size_t count);
Variable type
Source of definition
Definition
Container
size_t
include/asm/posix_types.h
include/linux/types.htypedef unsigned int __kernel_size_t;
typedef __kernel_size_t size_t;unsigned 4 byte integer
ssize_t
include/asm/posix_types.h
include/linux/types.htypedef int __kernel_ssize_t;
typedef __kernel_ssize_t ssize_t;signed 4 byte integer
API For System Calls
EAX contains the System call number and the
parameters are stored from left to right in the
registers in the following order: EBX, ECX, EDX, EDI, ESI.
Example
In the last lecture we used the write system call:
;; Use the write system call to output our hex character
mov edx, 1 ; How much are we going to output
mov ecx, hex ; Where is what we are going to output
mov ebx, 1 ; Which file are we going to use
; 1 is stdout
mov eax, 4 ; Use system call number 4
int 80h ; Just do it!
EBX register is set to the file descriptor.
ECX gets set to the address of the buffer (which in our case was a one byte buffer).
EDX gets the number of bytes to write out.
ssize_t write(int fd, const void *buf, size_t count);