container_of
-
kernel macro, container_ofIT/Linux Kernel 2013. 1. 11.
container_of 란?#define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) container_of는 커널 매크로로써, 구조체의 멤버변수의 주소값만 알고 있다면 그 구조체 주소를 얻어 올 수 있는 방법입니다. 세가지 인자를 갖습니다.1. 멤버변수의 주소값(ptr)2. 구조체 type(struct)3. 멤버변수 이름(member) 이 세가지 정보를 가지고 구조체에 해당하는 주소를 가져오는데요. 원리는 간단합니다.일단, 해당 멤버변수가 구조체 시작 위치에서 어디에 위치하는지 offset..