How does the Linux kernel determine in the location of function arguments in CPU registers?

Viewed 82

I'm wondering how the Linux kernel knows in which registers to look for function arguments when performing a system call. For example: I call the write system call from assembly. The arguments are stores in rdi, rsi and rdx. The kernel then calls the write function which looks something like write(fd, buf, len).

But how does the kernel know, that fd is stored in rdi, buf in rsi and len in rdx? How is the implementation? Is there some kind of a mapping in the kernel that initializes the arguments from these registers?

I guess im missing something. Maybe it doesn't even has something to do with these registers? I would appreciate some help :)

1 Answers

When a system call is executed, the arguments are stored in registers as defined in the x86_64 calling conventions. On *nix Systems, these are most likely SystemV. The arguments to a simple C function are stored there as well, as the compiler also follows the calling conventions. Because of this, no further processing has to be done in order to map argument locations to the C calling routines.

Related