list_entry

来源:互联网 发布:手机服装绘图软件 编辑:程序博客网 时间:2024/05/23 01:22
说明:以下所有代码基于linux-2.6.22.6内核;
 

1、<include/linux/list.h>
/**
 * list_entry - get the struct for this entry
 * @ptr:the &struct list_head pointer.
 * @type:the type of the struct this is embedded in.
 * @member:the name of the list_struct within the struct.
 */
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
1.1、list_entry的功能是获取链表结构中的节点地址;

2、<include/linux/kernel.h>
#define container_of(ptr, type, member) ({\
const typeof( ((type *)0)->member ) *__mptr = (ptr);\
(type *)( (char *)__mptr - offsetof(type,member) );}) 
2.1、typeof是C语言的关键字,返回表达式的类型;
2.2、"
( (char *)__mptr"中使用"(char *)"强制转换的原因是:字符类型的指针加减操作步长是一个字节;
2.3、 "
offsetof(type,member)"在arm体系结构中返回类型为无符号整型;

3、<include/linux/stddef.h>
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
4、<include/linux/types.h>
typedef __kernel_size_t size_t; 
5、<include/asm-arm/posix_types.h>
typedef unsigned int __kernel_size_t; 
0 0
原创粉丝点击