Assembly Syscall Question

Terry Lambert tlambert2 at mindspring.com
Fri Aug 1 01:00:27 PDT 2003


Ryan Sommers wrote:
> When making a system call to the kernel why is it necessary to push the
> syscall value onto the stack when you don't call another function?

The stack is visible in both user space and kernel space; in
general, the register space won't be, unless you are on an
architecture with an abundance of registers that doesn't do a
save/restore on trap entries.

By pushing it onto the stack, you are *positive* that the vale
is visible.

There is also the (small) possibility that the C compiler will
take advanatage of the calling conventions to assume that a
value will not change over a system call.  Short of declaring
that all registers are volatile, you can't really guarantee
that the registers pushed in will have the values after the
call that they had before the call, unless you save and restore
all of them (which is more expensive than the copyin, for system
calls with 3 arguments or less -- which is most of them; cost,
of course, will vary by architecture).

Personally, I like to look at the Linux register-based passing
mechanism in the same light that they look at the FreeBSD use
of the MMU hardware to assist VM, at the cost of increased
FreeBSD VM system complexity (i.e. they think our VM is too
convoluted, and we think their system calls are too convoluted).

-- Terry


More information about the freebsd-hackers mailing list