QQ咨询不加好友发不了信息,咨询前先加好友! → QQ:820896380 ×

Linux内核基础篇——container


Linux内核中经常可见container_of的身影,它在实际驱动的编写中也是广泛应用。

container_of原理

作用:通过结构体的某个成员变量地址找到该结构体的首地址

定义如下:

/**
 * container_of - cast a member of a structure out to the containing structure
 * @ptr:    the pointer to the member.
 * @type:   the type of the container struct this is embedded in.
 * @member: the name of the member within the struct.
 *
 */
#define container_of(ptr, type, member) ({          \\
    const typeof( ((type *)0)->member ) *__mptr = (ptr); \\
    (type *)( (char *)__mptr - offsetof(type,member) );})

给TA打赏
共{{data.count}}人
人已打赏
运维

Linux服务器大量的log日志,如何正确看日志快速定位错误?

2024-5-3 13:54:54

运维

薪资增长的秘诀在于掌握Linux运维技能

2024-5-3 14:02:27

个人中心
购物车
优惠劵
有新私信 私信列表
搜索