LIST_POISON1和LIST_POISON2

0 views
Skip to first unread message

Niu Tao

unread,
Jul 23, 2008, 2:54:52 AM7/23/08
to xiyouLinux, Linux论坛, 陈老师, helight. xu, 李昊
在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

Niu Tao

unread,
Jul 23, 2008, 3:04:58 AM7/23/08
to xiyouLinux, Linux论坛, 陈老师, helight. xu, 李昊
2008/7/23 Niu Tao <niuta...@gmail.com>:
还有对于它的初始化:
25#define LIST_HEAD_INIT(name) { &(name), &(name) }

30static inline void INIT_LIST_HEAD(struct list_head *list)
31{
32 list->next = list;
33 list->prev = list;
34}
有什么区别?

SIE

unread,
Jul 23, 2008, 3:26:11 AM7/23/08
to linuxe...@googlegroups.com, xiyouLinux, 陈老师, helight. xu, 李昊


2008/7/23 Niu Tao <niuta...@gmail.com>:

在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





--
#apt-get install wife
The following extra packages will be installed:
wife-house wife-car wife-friends wife-dog wife-mother_in_law wife-kid wife-no_more_tv_sports wife-kidlibs wife-bricomanialibs
The following packages will be upgraded:ego-restrainer freedom-throttler
Estimated installation time: 47 years
Do you want to continue [Y/n]?
Reply all
Reply to author
Forward
0 new messages