“'errno'未声明"编译Linux内核时 [英] "'errno' undeclared" when compile Linux kernel

查看:205
本文介绍了“'errno'未声明"编译Linux内核时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译,但不断出现以下错误: 在此处输入图片描述

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

我已经包含了asm-i386/errno.h一次,但是它没有用.我也尝试过包含linux/errno.h,但它在以太坊里不起作用.

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.

我应该包含什么文件?

推荐答案

Linux内核中没有errno变量:该变量仅位于用户空间中.

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

如果内核函数要报告错误并指定错误代码,它将错误代码封装到返回值中.这种封装有3种可能性,取决于成功返回的值类型:

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. 函数成功返回0,失败返回错误代码.

这个常用的约定有时也称为0/-err.

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

  1. 函数成功返回 valid 指针,失败返回表达式ERR_PTR(err).
  1. Function returns valid pointer on success, expression ERR_PTR(err) on fail.

此表达式的计算结果是指向指针的指针,该指针不能指向真正的内核对象.即使有效结果为NULL,也可以使用此约定.

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. 函数成功返回正整数,失败则返回错误代码:+val/-err.

如果有效结果为0,也可以使用以下约定:+val/0/-err.

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

当用户空间库需要根据内核的请求设置errno时,它将检查系统调用的结果(这是对内核执行请求的唯一方法).取决于syscall,使用1或3约定(任何系统调用的返回类型为long).

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).

在内核空间中为用户空间设置" errno的示例,请参见

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

这篇关于“'errno'未声明"编译Linux内核时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆