168static inline void list_del(struct list_head *entry)
169{
170 __list_del(entry->prev, entry->next);
171 entry->next = LIST_POISON1;
172 entry->prev = LIST_POISON2;
173}
list_del是删除entry所在的链表的entry节点,在171和172行将
entry->next=LIST_POISON1;
entry->prev=LIST_POISON2;
而LIST_POISON1和LIST_POISON2都被定义在:/linux/include/linux/poison.h中:
10#define LIST_POISON1 ((void *) 0x00100100)
11#define LIST_POISON2 ((void *) 0x00200200)
我的问题是:
1、一般我们在操作双向链表时,删除一个节点的操作是将该节点从链表中删除,之后
要么直接释放该节点,要么将其返回,而此处没有释放也 没有返回,而是赋予了
LIST_POISON1 和LIST_POISON12这两个值,是何用意?
2、这两个位置是什么内容?有什么特殊?将entry->next和entry->prev分别指向这两个
位置,那可不可以指向其他无效的位置?
3、这两个位置是人为规定的?并且对于所有访问它的程序都给予确定的回应(就像访问
0x00000000就会出现断错误这样的回应)?
--
My Bolg: http://niutao.cublog.cn
在linux内核中,/linux/include/linux/list.h
21struct list_head {
22 struct list_head *next, *prev;
23};
list_head被用做建立双向循环链表,其中对它的一个操作是删除一个节点:
155static inline void __list_del(struct list_head * prev, struct
list_head * next)
156{
157 next->prev = prev;
158 prev->next = next;
159}
168static inline void list_del(struct list_head *entry)
169{
170 __list_del(entry->prev, entry->next);
171 entry->next = LIST_POISON1;
172 entry->prev = LIST_POISON2;
173}
list_del是删除entry所在的链表的entry节点,在171和172行将
entry->next=LIST_POISON1;
entry->prev=LIST_POISON2;
而LIST_POISON1和LIST_POISON2都被定义在:/linux/include/linux/poison.h中:
10#define LIST_POISON1 ((void *) 0x00100100)
11#define LIST_POISON2 ((void *) 0x00200200)
我的问题是:
1、一般我们在操作双向链表时,删除一个节点的操作是将该节点从链表中删除,之后
要么直接释放该节点,要么将其返回,而此处没有释放也 没有返回,而是赋予了
LIST_POISON1 和LIST_POISON12这两个值,是何用意?
2、这两个位置是什么内容?有什么特殊?将entry->next和entry->prev分别指向这两个
位置,那可不可以指向其他无效的位置?
3、这两个位置是人为规定的?并且对于所有访问它的程序都给予确定的回应(就像访问
0x00000000就会出现断错误这样的回应)?
--
My Bolg: http://niutao.cublog.cn