Looking for a detailed document on Linux system calls

I would like to write my own libc for x86 Linux for learning. To do this, I will need to call the Linux System call in an assembly level language. I know how to make a system call in an assembly on Linux. However, I need to get complete information about the calls to the Linux system.

I'm looking for a detailed document on Linux system calls such as the inputs and outputs for each system call. Can anyone provide me with a URL / PDF for a Linux system call.

For example, to call 'sys_socketcall', register AX = 102, BX must contain the call number for a method of type create / bind, and CX must contain a pointer to "unsigned long". Here I need more information about the third parameter (CX).

+3


source to share


3 answers


The best source of information about the Linux kernel is unfortunately its source: https://github.com/torvalds/linux/blob/master/include/linux/syscalls.h should contain the required call definition.

The origin of the call itself: http://lxr.free-electrons.com/source/net/socket.c#L2366 , here you can see how the parameters are handled.



To quickly load a linux source on the web, you can use LXR: http://lxr.free-electrons.com/ident?i=sys_socketcall .

+1


source


The system call socketcall

is a special case, so you shouldn't rely on it to know the general format. Also, it only exists on x86-32, and other platforms use separate system calls for each socket operation function / procedure (not with these platforms socketcall

, but socket

, bind

etc.).

For the special case that is socketcall

: it expects __NR_socketcall

in eax

, a subfunction (ex SYS_SOCKET

, SYS_BIND

etc.) in, ebx

and the address of other arguments in ecx

. You will need to store an array as an example, 3 words for a socket operation (create a socket), store family at my_array[0]

, type at, my_array[1]

and protocol (usually 0) at my_array[2]

, pass the address my_array to ecx

(you are not passing the number of items in my_array

any explicit way, this is implied subfunction of the socket you are calling).

You may like these documents:



Now, for other system calls that are no exception socketcall

, you just need to get a reference to the POSIX function patch (see reference ) or the corresponding function description from man(2)

( man(2)

- this is the section of the man pages dealing with system calls), which you can find as For example, here: man-pages section 2 . Then you must specify the order of the arguments. You will pass the system call number in eax

, and then all the other arguments in the same order, which is described as man(2)

, or the POSIX, okay ebx

, ecx

, edx

, esi

, edi

, ebp

(up to six arguments). The status / result is returned to eax

.

Please note that the above only applies to Linux on Intel architecture (you are assuming other processors have different registers) and also note that the system call numbers differ between x86-32 and x86-64.

+1


source


0


source







All Articles