编译包含非内核头文件的linux内核(2.6)模块 [英] Compile linux kernel (2.6) module including non kernel headers

查看:92
本文介绍了编译包含非内核头文件的linux内核(2.6)模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以编译包含非内核包含定义的功能的linux kernel(2.6)模块?

Is it possible to compile a linux kernel(2.6) module that includes functionality defined by non-kernel includes?

例如:

kernelmodule.h

kernelmodule.h

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>   // printk()
// ...
#include <openssl/sha.h>
// ...


Makefile


Makefile

obj-m := kernelmodule.o
all:
    $(MAKE) -C /lib/modules/`uname -r`/build M=`pwd` modules

clean:
    $(MAKE) -C /lib/modules/`uname -r`/build M=`pwd` clean
    $(RM) Module.markers modules.order

我编写并尝试编译的内核模块包含许多openssl包含文件中的功能.

The kernel module I have written and are trying to compile contains functionality found in a number of openssl include files.

上面提供的标准makefile不允许在linux标头之外包含.是否可以包含此功能,如果可以,请您指出正确的方向.

The standard makefile presented above doesn't allow includes outside of the linux headers. Is it possible to include this functionality, and if so, could you please point me in the right direction.

谢谢, 迈克

推荐答案

内核不能使用用户空间代码,并且必须独立(即完全自包含,没有库),因此它不会拾取标准标头.

The kernel cannot use userspace code and must stand alone (i.e. be completely self contained, no libraries), therefore it does not pick up standard headers.

尚不清楚尝试获取用户空间标头有什么好处.如果其中存在可以使用的有效内容(常量,某些宏,只要它们不调用任何用户空间函数),则最好复制它们并仅包含所需的内核兼容部分.

It is not clear what benefit trying to pick up userspace headers is. If there are things in there that it would be valid to use (constants, some macros perhaps provided they don't call any userspace functions), then it may be better to duplicate them and include only the kernel-compatible parts that you need.

不可能将内核与为用户空间使用而设计的库链接在一起,即使它们不进行任何OS调用,因为内核中的链接环境无法对其进行提取.

It is not possible to link the kernel with libraries designed for userspace use - even if they don't make any OS calls - because the linking environment in the kernel cannot pick them up.

相反,重新编译要在内核中使用的所有函数(假设它们不进行任何OS或库调用-例如malloc-在这种情况下,无论如何都需要对其进行修改).将它们合并到您自己的库中以在内核模块中使用.

Instead, recompile any functions to be used in the kernel (assuming they don't make any OS or library calls - e.g. malloc - in which case they'll need to be modified anyway). Incorporate them into your own library to be used in your kernel modules.

Linux的最新版本仍然包含加密功能,包括各种SHA哈希-也许您可以使用其中之一.

Recent versions of linux contain cryptographic functions anyway, including various SHA hashes - perhaps you can use one of those instead.

另一个想法是停止尝试在内核空间中进行加密并将代码移至用户空间.用户空间代码更易于编写/调试/维护等.

Another idea would be to stop trying to do crypto in kernel-space and move the code to userspace. Userspace code is easier to write / debug / maintain etc.

这篇关于编译包含非内核头文件的linux内核(2.6)模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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