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

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

猜你喜欢

转载自www.cnblogs.com/nlp-in-shell/p/11923426.html