MIT 6.828 - 1.2 __acquires() 和 __releases()

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

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__ 来对代码进行静态检查 。

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

posted @ 2019-11-24 18:02  nlp-in-shell  阅读(431)  评论(0编辑  收藏  举报