MIT 6.828 - 1.2 __acquires() 和 __releases()

Tags: MIT 6.828

在对 dup / dup2 的源码分析中,我遇到了一对 annotation ,即 __acquires__releases

1
2
3
4
5
6
static int do_dup2(struct files_struct *files,
struct file *file, unsigned fd, unsigned flags)
__releases(&files->file_lock) // <- 这个东西
{
// ... omitted
}

经查阅,此为内核代码静态分析工具 Sparse 的 annotation 。Sparse 通过 gcc 的扩展属性 __attribute__ 以及自己定义的 __context__ 来对代码进行静态检查 。

其他可见 内核文档一篇博客



知识共享许可协议 2000 - 2099 MonKey's Blog | 自豪地采用 Hexo + Pandoc + KaTeX + Highlight.js