<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ko">
	<id>http://junhoahn.kr/noriwiki/index.php?action=history&amp;feed=atom&amp;title=Container_of</id>
	<title>Container of - 편집 역사</title>
	<link rel="self" type="application/atom+xml" href="http://junhoahn.kr/noriwiki/index.php?action=history&amp;feed=atom&amp;title=Container_of"/>
	<link rel="alternate" type="text/html" href="http://junhoahn.kr/noriwiki/index.php?title=Container_of&amp;action=history"/>
	<updated>2026-06-14T04:15:45Z</updated>
	<subtitle>이 문서의 편집 역사</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>http://junhoahn.kr/noriwiki/index.php?title=Container_of&amp;diff=86&amp;oldid=prev</id>
		<title>Ahn9807: 새 문서: 분류: 리눅스 커널 API  == 개요 ==  container_of(입력 주소, 구조체 A, 해당 구조체 멤버)  어떤 구조체(A)의 멤버가 입력 주소일 경우 해당하는 구조체의 주소를 가져온다.   예를 들어서 linux/bpf/hashtab.c  &lt;syntaxhighlight lang=c&gt; static void *__htab_map_lookup_elem(struct bpf_map *map, void *key) {         struct bpf_htab *htab = container_of(map, struct bpf_htab, map);         struct hlist_nulls_head *head;         struct...</title>
		<link rel="alternate" type="text/html" href="http://junhoahn.kr/noriwiki/index.php?title=Container_of&amp;diff=86&amp;oldid=prev"/>
		<updated>2023-02-03T12:01:15Z</updated>

		<summary type="html">&lt;p&gt;새 문서: &lt;a href=&quot;/noriwiki/index.php?title=%EB%B6%84%EB%A5%98:%EB%A6%AC%EB%88%85%EC%8A%A4_%EC%BB%A4%EB%84%90_API&quot; title=&quot;분류:리눅스 커널 API&quot;&gt;분류: 리눅스 커널 API&lt;/a&gt;  == 개요 ==  container_of(입력 주소, 구조체 A, 해당 구조체 멤버)  어떤 구조체(A)의 멤버가 입력 주소일 경우 해당하는 구조체의 주소를 가져온다.   예를 들어서 linux/bpf/hashtab.c  &amp;lt;syntaxhighlight lang=c&amp;gt; static void *__htab_map_lookup_elem(struct bpf_map *map, void *key) {         struct bpf_htab *htab = container_of(map, struct bpf_htab, map);         struct hlist_nulls_head *head;         struct...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;새 문서&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[분류: 리눅스 커널 API]]&lt;br /&gt;
&lt;br /&gt;
== 개요 ==&lt;br /&gt;
 container_of(입력 주소, 구조체 A, 해당 구조체 멤버)&lt;br /&gt;
 어떤 구조체(A)의 멤버가 입력 주소일 경우 해당하는 구조체의 주소를 가져온다. &lt;br /&gt;
&lt;br /&gt;
예를 들어서 linux/bpf/hashtab.c &lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
static void *__htab_map_lookup_elem(struct bpf_map *map, void *key)&lt;br /&gt;
{&lt;br /&gt;
        struct bpf_htab *htab = container_of(map, struct bpf_htab, map);&lt;br /&gt;
        struct hlist_nulls_head *head;&lt;br /&gt;
        struct htab_elem *l;&lt;br /&gt;
        u32 hash, key_size;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
에서 container_of의 구조를 분석해 보면, &amp;lt;/br&amp;gt;&lt;br /&gt;
map이란 struct bpf_map의 주소값이다. 근데 bpf_htab이란 구조체는 내부 인자중 하나로 struct bpf_map map을 가진다. 이 경우, 우리는 bpf_map의 주소값만을 알지만, bpf_map의 주소값의 bpf_htab의 상대적인 위치를 알기 때문에 결국 bpf_htab의 위치를 알 수 있다. &lt;br /&gt;
&lt;br /&gt;
container_of는 다음과 같은 구현을 가진다.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=c&amp;gt;&lt;br /&gt;
1 #define container_of(ptr, type, member) ({ \&lt;br /&gt;
2                const typeof( ((type *)0)-&amp;gt;member ) *__mptr = (ptr); &lt;br /&gt;
3                (type *)( (char *)__mptr - offsetof(type,member) );})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
이에 따라서 offsetof로 인해서 구조체 에서의 상대적인 위치를 가져오고 그 결과를 __mptr즉 ptr의 위치에서 빼면서 원하는 구조체의 위치를 가져오게 되는 것이다.&lt;/div&gt;</summary>
		<author><name>Ahn9807</name></author>
	</entry>
</feed>