https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435

--- Comment #5 from Arnd Bergmann <arnd at linaro dot org> ---
(In reply to Bernd Edlinger from comment #4)
> Arnd, excuse me for possibly silly question.
> 
> Why is it necessary to have
> sys_bla(with correct paramters)
> and
> SyS_bla(with generic parameters)
> 
> On the ABI level these aliases should be equivalent,
> or are these not really the same?

The first one (sys_*) matches the prototype that is defined in a
header file and matches whatever user space should see. It can also
be called from other parts of the kernel using that prototype. This
is an alias to the second.

The second one (SyS_*) uses 'unsigned long' arguments to
ensure we don't get undefined behavior with arguments that
are shorter than a CPU register: When the ELF psABI calling
conventions mandate that the upper bits in a register are
zero-extended or sign-extended, calling the function from user
space with intentionally invalid contents may cause undefined
behavior, such as overflowing an array indexed by an 'unsigned
char' argument. The typecast from unsigned long to the real
type should ensure that the upper bits are correctly initialized
on all supported ABIs.

The third (SYS_*) prototype is for the inline function that contains
the actual syscall implementation, and it again has the correct
prototype according to the header file.

Reply via email to