简体   繁体   中英

Return value size or type of a system call in Linux

I understand, from looking at kernel code, the linux system call return type is long int and the size is effectively 32-bit .

Is it possible to have a linux system call return a 64-bit value (of type, say, long long int )?

I understand that changing the size makes no sense but I am interested in learning the limitations if there are any or if this is just a matter of preference.

On x86, the return value is put in the eax register, so it cannot be bigger than 32 bit; similarly, on x86-64 it is stored on rax (the 64-bit extension of eax ).

In general, the trend seems to be to always use a register for the return value (which seems reasonable for system calls), so you are limited to the size of the "native integer" of the current platform. If you needed to return bigger stuff, you'd have to resort to passing the location for the output via a pointer.

I am limiting my discussion to x86_64 and i386 in this answer:

System calls are declared as long .

A 64-bit kernel will return a 64-bit int value back to user-space for system calls. A 32-bit kernel will return a 32-bit int value.

However, lets say that on the 32-bit kernel you change the return type of the system calls to long long; then they would be returned in %eax and %edx together with LSB in %eax and MSB in %edx

So your call gate (stuff in entry.S) will just have to ensure that it's not clobbering %eax and %edx on iret / ret instructions.

Your corresponding user-space wrapper functions that make the system call via int80 or via _syscall() macros on old systems or reimplementing the syscall(2) library call in the newer system to be a long long return type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM