linux-kernel - linux 内核中的 __context__ 属性

标签 linux-kernel

在内核\include\linux\compiler.h

#define __acquire(x)    __context__(x,1)
#define __release(x)    __context__(x,-1)

请帮助我理解,在上述声明中,我们试图通过 实现什么上下文 .我找不到它的详细信息。
我在理解 linux 内核中的自旋锁实现时越过了它。

最佳答案

来自 http://linux.die.net/man/1/sparse :

-Wcontext Warn about potential errors in synchronization or other delimited contexts. Sparse supports several means of designating functions or statements that delimit contexts, such as synchronization. Functions with the extended attribute attribute((context(expression,in_context,out_context)) require the context expression (for instance, a lock) to have the value in_context (a constant nonnegative integer) when called, and return with the value out_context (a constant nonnegative integer). For APIs defined via macros, use the statement form context(expression,in_value,out_value) in the body of the macro.

With -Wcontext Sparse will warn when it sees a function change the context without indicating this with a context attribute, either by decreasing a context below zero (such as by releasing a lock without acquiring it), or returning with a changed context (such as by acquiring a lock without releasing it). Sparse will also warn about blocks of code which may potentially execute with different contexts.

Sparse issues these warnings by default. To turn them off, use -Wno-context.

关于linux-kernel - linux 内核中的 __context__ 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28555143/

相关文章:

c - Linux 中断与轮询

linux-kernel - 内核线程转储中的 "isra"是什么

linux - 内核模块中的 obj-m 变量

c - 如果 mmap 比传统文件访问更快,我们在哪里看到节省的时间?

c - 从内核空间访问进程堆栈指针

linux-kernel - NAPI 驱动程序中的 netif_rx 与 netif_receive_skb

c - 错误 : dereferencing pointer to incomplete type - in a kernel module

linux - 尽管已安装但找不到内核头文件

linux-kernel - 如何解决加载eBPF文件对象时的 "R0 invalid mem access ' inv'”错误

Linux initramfs switch_root 无法找到内核使用的控制台