在我的项目中,我使用字符驱动程序在用户空间和内核空间之间进行通信。我使用函数 copy_to_user(void user *to, const void *from, unsigned long n)
将数据从内核空间复制到用户空间缓冲区。我们可以在#include < asm/uaccess.h >
下找到这个函数头文件。
我使用 Linux 内核版本 4.4.0-59-generic、Ubuntu OS 版本 16.04 LTS 编译了这个项目,它工作正常,没有任何错误和警告。我得到了想要的输出。
我使用 Linux 内核版本 4.12.8、Ubuntu 操作系统版本 16.04.2 LTS 编译了同一个项目,它在编译期间向我发出警告 WARNING: "copy_to_user" [/home/ldrv1/Desktop/Vijay/code/build/uts.ko] undefined!
.当我对我的模块执行 insmod 时,出现如下错误 insmod: ERROR: could not insert module uts.ko: Unknown symbol in module
.我认为 #include <asm/uaccess.h>
头文件在 4.12.8 内核版本中仍然受支持,否则我会得到 fatal error :编译时没有这样的文件或目录错误。我尝试使用 apt-get install linux-headers-$(uname -r)
更新 linux 内核头文件命令,我得到以下响应:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.12.8
E: Couldn't find any package by glob 'linux-headers-4.12.8'
E: Couldn't find any package by regex 'linux-headers-4.12.8'
此操作系统版本 16.04.2 LTS 具有 linux-headers-4.10.0-35。 我如何摆脱这个警告?建议和支持表示赞赏。如果需要更多信息,请随时询问。
最佳答案
你应该使用
#include <linux/uaccess.h>
对于 4.12.8。 这是 definition .在 4.4 中,一些驱动程序使用
#include <asm/uaccess.h>
而其他人 使用#include <linux/uaccess.h>
.#include <linux/uaccess.h>
我认为更可取。你应该做
apt-get update
然后apt-get install linux-headers-generic
.
关于linux - copy_to_user 在 linux 内核版本 4.12.8 中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302524/