gpt4 book ai didi

linux - 如何向task_struct添加成员绕过 "compiletime_assert"

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:40 25 4
gpt4 key购买 nike

我需要在 Linux 内核 4.8.0 中向 task_struct 添加成员。但是,当我这样做并尝试构建内核时,错误消息显示:

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__)

如何摆脱此类错误并成功构建我的内核?

最佳答案

您遇到的断言是由一个宏 (CHECK_MEMBER_AT_END_OF) 触发的,该宏检查 struct task_structthread 成员是否是它的最后一个字段。

根据内核源代码,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!

只需在它之前添加您的新字段。

关于linux - 如何向task_struct添加成员绕过 "compiletime_assert",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45125500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com