0

I'm trying to compile and I keep getting the following error: enter image description here

I've included the asm-i386/errno.h once and it didn't work. Also I've tried including linux/errno.h and it didn't work ether.

What file should I include?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
wanhu
  • 13
  • 1
  • 5
  • There is no `errno` variable in Linux kernel: this variable lives in **user space only**. If kernel function terminates with error, error code (if it is) can be extracted from returning value. – Tsyvarev Nov 13 '16 at 19:08
  • @Tsyvarev I think you should move the comment to the answer. It's totally valid, but I would add extra info about how errno is set: http://stackoverflow.com/questions/24567584/how-to-set-errno-in-linux-device-driver – Andrejs Cainikovs Nov 14 '16 at 10:45
  • 1
    @AndrejsCainikovs: Thanks for the link. Initially I wanted to mark the question as a duplicate, that is why I have commented instead of answering. But then I decide that question is broader than the referenced one, and I decide to provide an answer. – Tsyvarev Nov 14 '16 at 12:01
  • @RawanR: It is Stack Overflow *requirement*, that **error log should be in the question post itself** (as **text**), not a linked image. I have added main part of the error message into the title, but *textual form* of the error log is still needed. Also, it is worth to specify, whether you compile your kernel module or kernel itself (with your modifications). – Tsyvarev Nov 14 '16 at 12:45

1 Answers1

3

There is no errno variable in Linux kernel: this variable lives in user space only.

If kernel function wants to report about the error and specify the error code, it encapsulates the error code into the returning value. There are 3 possibilities of such encapsulation, dependent from value type returned on success:

  1. Function returns 0 on success, negated error code on fail.

This mostly used convention is sometimes referenced as 0/-err.

  1. Function returns valid pointer on success, expression ERR_PTR(err) on fail.

This expression is evaluated to the pointer, which can never points to real kernel object. This convention may be used even if NULL is valid result.

  1. Function returns positive integer on success, negated error code on fail: +val/-err.

In case when 0 is valid result, this convention may be used too: +val/0/-err.


When user space library needs to set errno according to kernel's request, it checks result of the system call (which is the only way for perform request to the kernel). Dependent on syscall, either 1 or 3 convention is used (return type of any system call is long).

Example of "setting" errno in kernel space for user space see here.

Community
  • 1
  • 1
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153