如何获取内核头文件?

发布于 2024-11-06 20:39:53 字数 1554 浏览 3 评论 0原文

我试图在内核 2.6.21 中进行新的系统调用

,其中一个新的系统调用使用“sys_write”函数,

但是要使用此函数,我意识到我必须根据 2.6.21 版本安装内核头文件。

但我找不到内核头文件(2.6.21)

我尝试了 apt-get install linux-headers-'uname -r' , apt-cache search linux-headers-$( uname -r)

但我找不到任何东西..

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>

int main(){
    int fd;
    int old_fs;
    old_fs = get_fs();
    set_fs(KERNEL_DS);
    fd = sys_open("config.txt", O_RDONLY, 0);
    if(fd >= 0)
        sys_close(fd);
    set_fs(old_fs);
    return 0;
}



 vv.c:2:24: error: linux/init.h: No such file or directory  
 vv.c:3:26: error: linux/module.h: No such file or directory  
 vv.c:4:28: error: linux/syscalls.h: No such file or directory  
 In file included from /usr/include/asm/fcntl.h:1,  
                 from /usr/include/linux/fcntl.h:4,  
                 from vv.c:5:  
 /usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’  
 /usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’  
  vv.c:6:25: error: asm/uaccess.h: No such file or directory  
 vv.c: In function ‘main’:  
 vv.c:12: error: ‘KERNEL_DS’ undeclared (first use in this function)  
 vv.c:12: error: (Each undeclared identifier is reported only once  
 vv.c:12: error: for each function it appears in.)  

另外,上面的头文件就是我想要的。

如何获取内核头文件?

请帮我..

i'm trying to make new system calls in kernel 2.6.21

and one of the new system calls use 'sys_write' function,

but to use this function, i realized that i must install kernel header file according to 2.6.21 version.

but i can't find kernel header file(2.6.21)

i tried apt-get install linux-headers-'uname -r' , apt-cache search linux-headers-$(uname -r)

but i can't find anything..

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>

int main(){
    int fd;
    int old_fs;
    old_fs = get_fs();
    set_fs(KERNEL_DS);
    fd = sys_open("config.txt", O_RDONLY, 0);
    if(fd >= 0)
        sys_close(fd);
    set_fs(old_fs);
    return 0;
}



 vv.c:2:24: error: linux/init.h: No such file or directory  
 vv.c:3:26: error: linux/module.h: No such file or directory  
 vv.c:4:28: error: linux/syscalls.h: No such file or directory  
 In file included from /usr/include/asm/fcntl.h:1,  
                 from /usr/include/linux/fcntl.h:4,  
                 from vv.c:5:  
 /usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’  
 /usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’  
  vv.c:6:25: error: asm/uaccess.h: No such file or directory  
 vv.c: In function ‘main’:  
 vv.c:12: error: ‘KERNEL_DS’ undeclared (first use in this function)  
 vv.c:12: error: (Each undeclared identifier is reported only once  
 vv.c:12: error: for each function it appears in.)  

additionally, above header files is what i want to.

how can i get the kernel header file?

please help me..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘落散花 2024-11-13 20:39:53

标头安装完成了吗?如果是这样,那么它们应该安装在 /usr/include 中,并且您给出的包含指令应该可以正常工作。

编辑:

首先运行:

sudo apt-get update

要确保您拥有最新的软件包,然后:

sudo apt-get install linux-headers-$(uname -r)

这是一个包含 Ubuntu 中所有内核头文件的包。

Did installing the headers complete? If so then they should be installed in /usr/include and the include directives you gave should just work.

Edit:

First run:

sudo apt-get update

To make sure you have the latest packages, then:

sudo apt-get install linux-headers-$(uname -r)

This is the one package that should contain all the kernel header files in Ubuntu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文