A system call is the fundamental interface between an application and the Linux kernel. When a Unix/Linux program does a file I/O, network data transfer or invokes some process which directly or indirectly interact with the low level instructions, then system call is involved. Making these calls usually involves using a library called glibc which contains the functions.
Below is a list of some frequently used system calls and their purpose.
|1||chmod||change permissions of a file|
|2||chdir||change working directory|
|3||fork||create a child process|
|4||unlink||delete a name and possibly the file it refers to|
A systems programmer writes program that will not directly make the systems call, rather than he will just specify which system call to use. This involves using a calling convention which is dependent or the hardware architecture of the system where the kernel sits. Hence different architectures have different calling conventions.
A calling convention is an implementation-level design for how subroutines receive parameters from their caller and how the results are returned. Differences in various implementations include where parameters, return values, return addresses and scope links are placed (registers, stack or memory etc.), and how the tasks of preparing for a function call and restoring the environment afterward are divided between the caller and the callee.
Below is a list of some of the scenarios describing how the Calling convention varies between different architecture
A single CPU architecture always have more than one possible calling convention but the industry has agreed to some general approach across the architectures form different producers. The 32-bit architecture has 32 registers while x64 extends x86's 8 general-purpose registers to be 64-bit. Hence there is a difference in the implementation of calling conventions. Below is comparison of major calling conventions between these two architectures.
|x-86 32bit||x-86 64 bit|
|The registers used for system call are - %ebx, %ecx, %edx, %esi, %edi, %ebp||The registers used for system call are - %rdi, %rsi, %rdx, %r10, %r8 and %r9|
|Parameters are passed on the stack using PUSH mechanism. If there are more than six arguments, %ebx must contain the memory location where the list of arguments is stored||System-calls are limited to six arguments. If there are more than 6 INTEGER parameters, the 7th INTEGER parameter and later are passed on the stack.|
|The return value is stored in the register %eax.||The return value is stored in the register %rax.|
|In x86-32 parameters were passed on stack. Last parameter was pushed first on to the stack until all parameters are done and then call instruction was executed.||First the parameters are divided into classes. The class of each parameter determines the manner in which it is passed to the called function.|
|The 32-bit int ABI (application binary interface) is usable in 64-bit code||The 64-bit ABI calls can not be used in 32-bit system.|