简体   繁体   中英

Linux system calls return value

In a homework assignment we were asked to add a system call to the Linux Kernel (Red Hat 2.4.18). According to the assignment the return value of the new system call should be void. The system call in itself is quite simple (just one assignment) and there is no chance for error. From what I read and learnt system calls usually return a negative value to indicate failure or 0 to indicate success. My question is whether this is just a common practice or a must? Can a system call return void?

In Linux all system calls return long, if they return at all. Say you declare your system call using:

SYSCALL_DEFINE0(mycall)
{
    /* ... */
}

This results in:

asmlinkage long sys_mycall(void)

If you don't have any useful return and the call cannot fail, simply return 0 every time to signal success.

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