在对 dup / dup2 的源码分析中,我遇到了一对 annotation ,即 __acquires
和 __releases
html
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__
来对代码进行静态检查 。工具