开发者

How does a syscall knows where the wrapper function put its parameters in?

开发者 https://www.devze.com 2022-12-24 06:51 出处:网络
I\'m trying to implement a syscall in Linux (RedHat Enterprise 8) and I\'m a bit confused about the way it works. From what I understand, I implement a wrapper in user mode which puts the syscall numb

I'm trying to implement a syscall in Linux (RedHat Enterprise 8) and I'm a bit confused about the way it works. From what I understand, I implement a wrapper in user mode which puts the syscall number in eax开发者_运维知识库 and parameters in ebx, ecx, edx, etc, and then invokes int 0x80 which calls the appropriate syscall. My question is, since a syscall is written like a regular C function, how does it know what registers contain what 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 a homework assignment. I know that there are syscall macros that can do this stuff for me.


From the Linux Journal article, bottom of page 2

Since the system call interface is exclusively register-parametered, six parameters at most can be used with a single system call. %eax is the syscall number; %ebx, %ecx, %edx, %esi, %edi and %ebp are the six generic registers used as param0-5; and %esp cannot be used because it's overwritten by the kernel when it enters ring 0 (i.e., kernel mode).

Your c code may look like it's making a system call, but it actually calls a function in libc. That function makes sure that all the arguments are in the right registers, and then does the interrupt.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号