gpt4 book ai didi

c - 文件 linux/compiler.h 中定义的预处理器宏的目的是什么?

转载 作者:IT王子 更新时间:2023-10-29 00:14:10 28 4
gpt4 key购买 nike

我是 Linux 内核的新手。我正在使用稀疏工具来清除代码中存在的噪音。我遇到了这些宏:

   # define __user      __attribute__((noderef, address_space(1)))
# define __kernel __attribute__((address_space(0)))
# define __safe __attribute__((safe))
# define __force __attribute__((force))
# define __nocast __attribute__((nocast))
# define __iomem __attribute__((noderef, address_space(2)))
# define __must_hold(x) __attribute__((context(x,1,1)))
# define __acquires(x) __attribute__((context(x,0,1)))
# define __releases(x) __attribute__((context(x,1,0)))
# define __acquire(x) __context__(x,1)
# define __release(x) __context__(x,-1)
# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
# define __percpu __attribute__((noderef, address_space(3)))

现在我想知道:sparse 如何使用它们来报告错误/警告?

我的问题:

  1. 我想要了解它们如何帮助编译器和稀疏报告警告的详细信息。
  2. 这些 address_space(x) context(X, x, x) 是什么,有什么用途?
  3. __nocast__force__user__safe 的目的是什么?

最佳答案

我认为所有这些宏仅在 sparse 的上下文中才有意义(联机帮助页 here - 您可以在那里找到所有这些属性和稀疏警告的描述)。如果您查看上面复制的源文件,就会发现一个很大的 __CHECKER__ 宏用于启用它们。

我不确定此时 gcc 是否对它们做了任何事情 - 我认为它有点默默地忽略了它们......在 2004 年 Linus Torvalds 的一封电子邮件中说:

This is important to remember: for gcc, the sparse annotations are meaningless. They can still be useful just to tell the programmer that "hey, that pointer you got wasn't a normal pointer" in a fairly readable manner, but in the end, unless you use sparse, they don't actually do anything.

有一些票为此目的而开 - http://www.spinics.net/lists/linux-sparse/msg03366.html .

关于c - 文件 linux/compiler.h 中定义的预处理器宏的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425673/

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