__attribute__如何使用的记录

在内核中看到各种个样的__attribute__的属性的使用,在这个帖子中,逐渐记录我看到的每个使用。


# define __rcu __attribute__((noderef, address_space(4)))

RCU代表的是 "read, copy, update"。它是一种算法,允许多个读者访问数据,并且同时允许修改者,删除者能够进行操作。

如果内核使用 CONFIG_SPARSE_RCU_POINTER 的编译, __rcu 就会被定义为上面的定义。

这是一种标记,可以给Sparse code 分析工具来对于某些东西进行警告。

引用 http://stackoverflow.com/questions/17128210/what-does-rcu-stands-for-in-linux

可以知道: __rcu sparse 检查:使用__rcu 附上 RCU保护的数据结构,如果你没有使用rcu_dereference()类中某个函数,Sparse就会警告你这个操作。


__attribute__((aligned(4)))

参考网页:https://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Type-Attributes.html

aligned (alignment): 这个属性指定对于一个变量,最小的对齐标准。


原文地址:https://www.cnblogs.com/hwy89289709/p/6849975.html