在對 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__
來對代碼進行靜態檢查 。工具