先贴错误
./arch/x86/include/asm/uaccess.h:32:9: error: dereferencing pointer to incomplete type ‘struct task_struct’
current->thread.addr_limit = fs;
在编译自己写的module的时候,出现这个错误,有点摸不着头脑
根据字面意思,好像 struct task_struct 这个结构体没有定义thread字段一样,然后果断在源码中查找这个结构实在哪声明的,搜索结果作为结构出现在一下两个文件中
include/linux/sched.h, line 520 (as a struct)
tools/include/linux/lockdep.h, line 26 (as a struct)
进一步查找之后,知道了定义实在 /linux/sched.h 中定义的,然后就开始查找 有没有 thread字段,结果自然是有这个字段的啊,而且这个字段 也没有被宏包裹 ,结构体真长,而thread字段在最后一个字段被定义的
struct task_struct {
#ifdef CONFIG_THREAD_INFO_IN_TASK
/*
* For reasons of header soup (see current_thread_info()), this
* must be the first element of task_struct.
*/
struct thread_info thread_info;
#endif
····
····
····
/* CPU-specific state of this task: */
struct thread_struct thread;
/*
* WARNING: on x86, 'thread_struct' contains a variable-sized
* structure. It *MUST* be at the end of 'task_struct'.
*
* Do not put anything below here!
*/
字段也有,定义也有,这就应该没错啊,可惜,还是有这个错
只能进入出错文件看看了,进入
/arch/x86/include/asm/uaccess.h
文件,他的根是在/lib/modules/$(shell uname -r)/build
, WTAF, 他没有包含#include <linux/sched.h>
, 然后自己添加包含之后,错误就消失了…
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_UACCESS_H
#define _ASM_X86_UACCESS_H
/*
* User space memory access functions
*/
#include <linux/compiler.h>
#include <linux/kasan-checks.h>
#include <linux/string.h>
#include <asm/asm.h>
#include <asm/page.h>
#include <asm/smap.h>
#include <asm/extable.h>
/*
* The fs value determines whether argument validity checking should be
* performed or not. If get_fs() == USER_DS, checking is performed, with
* get_fs() == KERNEL_DS, checking is bypassed.
*
* For historical reasons, these macros are grossly misnamed.
*/
做个记录,如果后续遇到这种错误,给自己提供一个解决错误的方法