How does syscall know where the shell function puts its parameters?

I am trying to implement syscall on Linux (RedHat Enterprise 8) and I am a bit confused about how it works. From what I understand, I am implementing a user-mode shell that puts the syscall number in eax and the parameters in ebx, ecx, edx, etc., and then calls int 0x80, which calls the corresponding syscall. My question is, since syscall is written like a regular C function, how does it know which registers contain which parameters? Is it a convention, or is there a mechanism for it, and if so, where and how does it do it?

EDIT: This is homework. I know there are syscall macros that can do this for me.

+3
source share
1 answer

From the Linux Journal at the bottom of the page

Since the system call interface has an exclusive registration characteristic, a maximum of six parameters can be used with one system call. % eax is the call system number; % ebx,% ecx,% edx,% esi,% edi and% ebp are six common registers used as param0-5; and% esp cannot be used because it is overwritten by the kernel when it enters ring 0 (i.e. kernel mode).

Your c code may look like a system call, but it actually calls a function in libc. This function ensures that all arguments are in the correct registers and then performs an interrupt.

+4
source

Source: https://habr.com/ru/post/1738101/


All Articles