Returning an error code in the linux kernel

I was trying to figure out how Linux system causes reverse error codes. I ran into the times () system call . This simple system call copies some data to user space, and if this operation was not successful, it returns -EFAULT

:

SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
{
    if (tbuf) {
        struct tms tmp;

        do_sys_times(&tmp);
        if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
            return -EFAULT;
    }
    force_successful_syscall_return();
    return (long) jiffies_64_to_clock_t(get_jiffies_64());
}

      

My questions:

  • Why -EFAULT

    ? Shouldn't it be EFAULT

    without a minus?
  • Is it common to return negative error codes?
+3


source to share


1 answer


From man 2 syscalls :

Note: System calls indicate failure by returning a negative error number to the caller; when it does, the wrapper function negates the returned error number (to make it positive), copies it to, errno

and returns it to the -1

caller of the wrapper.



See also the following answers:

+3


source







All Articles