如何在系统调用中分配结构

时间:2018-10-30 02:16:04

标签: linux linux-kernel system-calls

struct test{
    /*...*/
}

asmlinkage syscall(){
    struct test *t;
    t = (struct test *)malloc(sizeof(struct test));
    //...
}

在编译整个内核期间,显示以下错误。

函数'malloc'的隐式声明

似乎我不能包含 stdlib.h ,但是如果我不使用 malloc ,则 t 指针将是 NULL

这导致 无法在(空)处处理内核NULL指针取消引用

如何为 t 分配指针?

1 个答案:

答案 0 :(得分:-1)

这将指针分配给指针类型     结构测试* t;

使用跟踪代码

struct test t;

完成