2017-07-16 414 views
0

我需要將成員添加到Linux內核4.8.0中的task_struct。然而,當我做到了,並試圖構建內核,錯誤消息顯示:如何將成員添加到task_struct以繞過「compiletime_assert」

In file included from linux-hwe-4.8.0/include/uapi/linux/stddef.h:1:0, 
      from linux-hwe-4.8.0/include/linux/stddef.h:4, 
      from linux-hwe-4.8.0/include/uapi/linux/posix_types.h:4, 
      from linux-hwe-4.8.0/include/uapi/linux/types.h:13, 
      from linux-hwe-4.8.0/include/linux/types.h:5, 
      from linux-hwe-4.8.0/include/linux/compat.h:8, 
      from linux-hwe-4.8.0/arch/x86/include/asm/fpu/internal.h:13, 
      from linux-hwe-4.8.0/arch/x86/kernel/fpu/init.c:4: 
In function ‘fpu__init_task_struct_size’, 
inlined from ‘fpu__init_system’ at linux-hwe-4.8.0/arch/x86/kernel/fpu/init.c:390:2: 
linux-hwe-4.8.0/include/linux/compiler.h:491:38: error: call to ‘__compiletime_assert_192’ declared with attribute error: BUILD_BUG_ON failed: sizeof(struct task_struct) != ALIGN(offsetofend(struct task_struct, thread), TYPE_ALIGN(struct task_struct)) 
    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) 

如何擺脫這樣的錯誤,成功打造核心?

回答

0

您遇到的斷言由一個宏(CHECK_MEMBER_AT_END_OF)觸發,該宏檢查成員struct task_struct是其最後一個字段。

按內核源代碼,Linux的/ sched.h中:

/* 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! 

只要之前添加新的領域。