- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我一直在尝试在运行 4.15.0-43-generic 并安装了 linux-headers-4.15.0-43 的 Ubuntu 18.04 上编译一个简单的“Hello world”LKM。
这是代码:
#define MODULE
#define LINUX
#define __KERNEL__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_DEBUG "Hello World!");
return 0;
}
module_init( init_module );
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Hello world");
这是我的生成文件:
CC := gcc
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -c $(WARN) $(INCLUDE)
SOURCES := helloworld.c
TARGET := helloworld.ko
all:
$(CC) $(CFLAGS) $(SOURCES) -o $(TARGET)
这些是/lib/modules/$(uname -r)/build/include
的内容
acpi asm-generic clocksource config crypto drm dt-bindings generated keys kvm linux math-emu media memory misc net pcmcia ras rdma scsi soc sound target trace uapi video xen
我得到了一个fatal error: asm/barrier.h: No such file or directory
这是意料之中的,因为 asm
目录不存在。请参阅下面的完整输出:
gcc -O2 -c -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include helloworld.c -o helloworld.ko
In file included from /usr/src/linux-headers-4.15.0-43/include/linux/init.h:5:0,
from helloworld.c:5:
/usr/src/linux-headers-4.15.0-43/include/linux/compiler.h:247:10: fatal error: asm/barrier.h: No such file or directory
#include <asm/barrier.h>
^~~~~~~~~~~~~~~
compilation terminated.
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 1
对...所以我想如果我创建一个 asm-generic 到 asm 的符号链接(symbolic link)会怎么样?
sudo ln -s /lib/modules/$(uname -r)/build/include/asm-generic /lib/modules/$(uname -r)/build/include/asm
ls -ld/lib/modules/$(uname -r)/build/include/asm
确认链接存在:
lrwxrwxrwx 1 root root 56 Jan 24 19:51 /lib/modules/4.15.0-43-generic/build/include/asm -> /lib/modules/4.15.0-43-generic/build/include/asm-generic
一切正常吗?不 :( 现在它提示找不到 asm/thread_info.h
(在我做了符号链接(symbolic link)之后)。
gcc -O2 -c -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include helloworld.c -o helloworld.ko
In file included from /lib/modules/4.15.0-43-generic/build/include/asm/preempt.h:5:0,
from /usr/src/linux-headers-4.15.0-43/include/linux/preempt.h:81,
from /usr/src/linux-headers-4.15.0-43/include/linux/spinlock.h:51,
from /usr/src/linux-headers-4.15.0-43/include/linux/seqlock.h:36,
from /usr/src/linux-headers-4.15.0-43/include/linux/time.h:6,
from /usr/src/linux-headers-4.15.0-43/include/linux/stat.h:19,
from /usr/src/linux-headers-4.15.0-43/include/linux/module.h:10,
from helloworld.c:6:
/usr/src/linux-headers-4.15.0-43/include/linux/thread_info.h:38:10: fatal error: asm/thread_info.h: No such file or directory
#include <asm/thread_info.h>
^~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 1
我从一开始就知道符号链接(symbolic link)不是个好主意。
我也试过包括 /usr/src/linux-headers-4.15.0-43/include
而不是 /lib/modules/...
但说来话长简而言之,“asm”目录不在 /usr/src/linux-headers-4.15.0-43/include/
和符号链接(symbolic link) /usr/src/linux-headers- 4.15.0-43/include/asm-generic
到 /usr/src/linux-headers-4.15.0-43/include/asm
产生了与上述相同的问题。
我知道问题出在哪里,显然头文件丢失了,但问题是我找不到它们,我从哪里得到它们?软件包已安装:
$ dpkg -l | grep linux-headers-
ii linux-headers-4.15.0-23
ii linux-headers-4.15.0-43
ii linux-headers-4.15.0-43-generic
ii linux-headers-generic
我都试过了,都出现了同样的问题。
最佳答案
好的,多亏了 Tsyvarev,我在进一步阅读后发现了问题 :)
问题的主要原因是我的 Makefile,以下确实对我有用:
obj-m += helloworld.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
这解决了我遇到的原始问题,弹出了一个与此线程无关的新问题,但都已解决。
关于linux - LKM - 无法编译模块 - 缺少头文件但安装了头包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54343325/
我写了一个LKM(loadable kernel module),需要调用/linux/driver下的另一个内核驱动模块中的函数。我不知道如何将这些功能导入 LKM。由于/lib/modules/l
我知道内核使用 vmalloc() 加载可加载内核模块 (LKM) 假设整个 LKM 都驻留在堆中是否安全? 最佳答案 更准确地说,内核模块的内存是使用 vmalloc_exec() 分配的。 Is
我有一个简单的可加载内核模块,它通过提供闪烁周期、开/关功能等来控制 LED... 设备位于/sys/led ,并且运行正常。 我已经为命令行提供了一个输入参数,它接受 LED 连接到哪个 GPIO。
我的 LKM 劫持了 stdin/sshd 输入:https://pastebin.com/RChpbt9G # uname -a Linux kali 4.19.0-kali4-amd64 #1 S
所以我一直在尝试在运行 4.15.0-43-generic 并安装了 linux-headers-4.15.0-43 的 Ubuntu 18.04 上编译一个简单的“Hello world”LKM。
假设我在 linux-kernel 中插入了 Loadable-Kernel-Module 并且 Hook 了读、写、打开和关闭函数。所以现在我可以停止对任何文件的访问,但我想阻止文件被复制到设备外部
这个问题在这里已经有了答案: Implementing Linux System Call using LKM (1 个回答) 关闭 6 年前。 所以我看到了一堆关于添加系统调用的问题,但我找不到任
我制作了简单的 LKM(Linux 内核模块)以在用户级别与内核级别信息交互我的 MPI 应用程序(每个计算节点的多进程)。我需要在运行时从内核中提取一些数据到用户级应用程序。我的 MPI 应用程序使
我写了下面的代码: #include #include #include #include #include void **sys_call_table; int __init kaslr_
作为练习(安全研究),我正在尝试实现一个包装的系统调用。根据 getdents 文档 - 您必须实现自己的 linux_dirent 结构(https://linux.die.net/man/2/ge
我开始学习一个非常基本的“hello world”LKM,另外我已经向内核添加了功能并成功重新编译并且它可以工作。我现在喜欢做的是将一个变量添加到已编译的内核代码中,然后在加载和卸载模块时从我的 LK
我是内核新手,在使用内核模块的导出符号编译 Linux 内核时需要一些帮助。 我尝试了以下 - LKM 源代码中的 EXPORT_SYMBOL(func_name),LKM 编译并在其 Module.
我正在开发一个 Linux 内核模块 (LKM),它分析我笔记本电脑的电池参数并在每个给定时间间隔内写入内核日志文件 (/var/log/kern.log)。使用日志文件中的数据,我将绘制实时图表。
是否有可能在版本为 3.0.31- 的内核中使用为 3.0.8+ mod_unload ARMv5(我自制的内核)编译的可加载内核模块gd5a18e0 SMP 抢占 mod_unload ARMv7(
我在内核树之外使用 LKM,我想为我的模块使用一些编译选项,例如 MYLKM_CONFIG_{something}。我知道这可以使用 C 预处理 (#define//#ifdef//#endif) 来
我是内核开发技术的新手。我想知道一旦动态加载内核模块,是否有办法在内核和内核模块 (LKM) 之间建立通信。我想要做的是从内核的特定部分调用一个函数来发送一些数据,而内核模块正在等待它。如果模块还没有
我有一个生成数据的 Linux 内核模块,我想将该数据发送到用户空间应用程序。有哪些选择,它们有哪些优点/缺点? 比方说,数据可能是每秒几个 char[] 和几个 int[] 的 100 个结构。 此
我最近一直在研究这个问题,并查看了各种文章和 stackoverflow 帖子,但我似乎无法找到直接的答案。在创建内核模块时,我看到大多数代码如下所示: #include static int te
我的目标是编写一个 LKM(Linux 内核模块)来拦截所有 TCP 数据包、查找 tcp_sock 结构并根据某些条件从 tcp_sock 结构(例如:tcpsock->snd_una)记录一些信息
我正在从 Linux (3.x) 的系统调用表中覆盖 SYS_READ,但在卸载模块本身时遇到了一些麻烦。我首先加载找到系统调用表的模块,然后启用 RW,用我自己的 SYS_READ 函数覆盖 SYS
我是一名优秀的程序员,十分优秀!