linux内核神级list

  1 #ifndef _LINUX_LIST_H
  2 #define _LINUX_LIST_H
  3
  4 struct list_head {
  5     struct list_head *next, *prev;
  6 };
  7
  8 struct hlist_head {
  9     struct hlist_node *first;
 10 };
 11
 12 struct hlist_node {
 13     struct hlist_node *next, **pprev;
 14 };
 15
 16 #ifndef offsetof
 17 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 18 #endif
 19
 20 #ifndef container_of
 21 /**
 22  * container_of - cast a member of a structure out to the containing structure
 23  * @ptr:    the pointer to the member.
 24  * @type:    the type of the container struct this is embedded in.
 25  * @member:    the name of the member within the struct.
 26  *
 27  */
 28 #define container_of(ptr, type, member) ({             29     const typeof(((type *)0)->member) * __mptr = (ptr);     30     (type *)((char *)__mptr - offsetof(type, member)); })
 31 #endif
 32
 33 #define LIST_POISON1 NULL
 34 #define LIST_POISON2 NULL
 35
 36 /*
 37  * Simple doubly linked list implementation.
 38  *
 39  * Some of the internal functions ("__xxx") are useful when
 40  * manipulating whole lists rather than single entries, as
 41  * sometimes we already know the next/prev entries and we can
 42  * generate better code by using them directly rather than
 43  * using the generic single-entry routines.
 44  */
 45
 46 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 47
 48 #define LIST_HEAD(name)  49     struct list_head name = LIST_HEAD_INIT(name)
 50
 51 static inline void INIT_LIST_HEAD(struct list_head *list)
 52 {
 53     list->next = list;
 54     list->prev = list;
 55 }
 56
 57 /*
 58  * Insert a new entry between two known consecutive entries.
 59  *
 60  * This is only for internal list manipulation where we know
 61  * the prev/next entries already!
 62  */
 63 #ifndef CONFIG_DEBUG_LIST
 64 static inline void __list_add(struct list_head *new,
 65                   struct list_head *prev,
 66                   struct list_head *next)
 67 {
 68     next->prev = new;
 69     new->next = next;
 70     new->prev = prev;
 71     prev->next = new;
 72 }
 73 #else
 74 extern void __list_add(struct list_head *new,
 75                   struct list_head *prev,
 76                   struct list_head *next);
 77 #endif
 78
 79 /**
 80  * list_add - add a new entry
 81  * @new: new entry to be added
 82  * @head: list head to add it after
 83  *
 84  * Insert a new entry after the specified head.
 85  * This is good for implementing stacks.
 86  */
 87 static inline void list_add(struct list_head *new, struct list_head *head)
 88 {
 89     __list_add(new, head, head->next);
 90 }
 91
 92
 93 /**
 94  * list_add_tail - add a new entry
 95  * @new: new entry to be added
 96  * @head: list head to add it before
 97  *
 98  * Insert a new entry before the specified head.
 99  * This is useful for implementing queues.
100  */
101 static inline void list_add_tail(struct list_head *new, struct list_head *head)
102 {
103     __list_add(new, head->prev, head);
104 }
105
106 /*
107  * Delete a list entry by making the prev/next entries
108  * point to each other.
109  *
110  * This is only for internal list manipulation where we know
111  * the prev/next entries already!
112  */
113 static inline void __list_del(struct list_head * prev, struct list_head * next)
114 {
115     next->prev = prev;
116     prev->next = next;
117 }
118
119 /**
120  * list_del - deletes entry from list.
121  * @entry: the element to delete from the list.
122  * Note: list_empty() on entry does not return true after this, the entry is
123  * in an undefined state.
124  */
125 #ifndef CONFIG_DEBUG_LIST
126 static inline void __list_del_entry(struct list_head *entry)
127 {
128     __list_del(entry->prev, entry->next);
129 }
130
131 static inline void list_del(struct list_head *entry)
132 {
133     __list_del(entry->prev, entry->next);
134     entry->next = LIST_POISON1;
135     entry->prev = LIST_POISON2;
136 }
137 #else
138 extern void __list_del_entry(struct list_head *entry);
139 extern void list_del(struct list_head *entry);
140 #endif
141
142 /**
143  * list_replace - replace old entry by new one
144  * @old : the element to be replaced
145  * @new : the new element to insert
146  *
147  * If @old was empty, it will be overwritten.
148  */
149 static inline void list_replace(struct list_head *old,
150                 struct list_head *new)
151 {
152     new->next = old->next;
153     new->next->prev = new;
154     new->prev = old->prev;
155     new->prev->next = new;
156 }
157
158 static inline void list_replace_init(struct list_head *old,
159                     struct list_head *new)
160 {
161     list_replace(old, new);
162     INIT_LIST_HEAD(old);
163 }
164
165 /**
166  * list_del_init - deletes entry from list and reinitialize it.
167  * @entry: the element to delete from the list.
168  */
169 static inline void list_del_init(struct list_head *entry)
170 {
171     __list_del_entry(entry);
172     INIT_LIST_HEAD(entry);
173 }
174
175 /**
176  * list_move - delete from one list and add as another‘s head
177  * @list: the entry to move
178  * @head: the head that will precede our entry
179  */
180 static inline void list_move(struct list_head *list, struct list_head *head)
181 {
182     __list_del_entry(list);
183     list_add(list, head);
184 }
185
186 /**
187  * list_move_tail - delete from one list and add as another‘s tail
188  * @list: the entry to move
189  * @head: the head that will follow our entry
190  */
191 static inline void list_move_tail(struct list_head *list,
192                   struct list_head *head)
193 {
194     __list_del_entry(list);
195     list_add_tail(list, head);
196 }
197
198 /**
199  * list_is_last - tests whether @list is the last entry in list @head
200  * @list: the entry to test
201  * @head: the head of the list
202  */
203 static inline int list_is_last(const struct list_head *list,
204                 const struct list_head *head)
205 {
206     return list->next == head;
207 }
208
209 /**
210  * list_empty - tests whether a list is empty
211  * @head: the list to test.
212  */
213 static inline int list_empty(const struct list_head *head)
214 {
215     return head->next == head;
216 }
217
218 /**
219  * list_empty_careful - tests whether a list is empty and not being modified
220  * @head: the list to test
221  *
222  * Description:
223  * tests whether a list is empty _and_ checks that no other CPU might be
224  * in the process of modifying either member (next or prev)
225  *
226  * NOTE: using list_empty_careful() without synchronization
227  * can only be safe if the only activity that can happen
228  * to the list entry is list_del_init(). Eg. it cannot be used
229  * if another CPU could re-list_add() it.
230  */
231 static inline int list_empty_careful(const struct list_head *head)
232 {
233     struct list_head *next = head->next;
234     return (next == head) && (next == head->prev);
235 }
236
237 /**
238  * list_rotate_left - rotate the list to the left
239  * @head: the head of the list
240  */
241 static inline void list_rotate_left(struct list_head *head)
242 {
243     struct list_head *first;
244
245     if (!list_empty(head)) {
246         first = head->next;
247         list_move_tail(first, head);
248     }
249 }
250
251 /**
252  * list_is_singular - tests whether a list has just one entry.
253  * @head: the list to test.
254  */
255 static inline int list_is_singular(const struct list_head *head)
256 {
257     return !list_empty(head) && (head->next == head->prev);
258 }
259
260 static inline void __list_cut_position(struct list_head *list,
261         struct list_head *head, struct list_head *entry)
262 {
263     struct list_head *new_first = entry->next;
264     list->next = head->next;
265     list->next->prev = list;
266     list->prev = entry;
267     entry->next = list;
268     head->next = new_first;
269     new_first->prev = head;
270 }
271
272 /**
273  * list_cut_position - cut a list into two
274  * @list: a new list to add all removed entries
275  * @head: a list with entries
276  * @entry: an entry within head, could be the head itself
277  *    and if so we won‘t cut the list
278  *
279  * This helper moves the initial part of @head, up to and
280  * including @entry, from @head to @list. You should
281  * pass on @entry an element you know is on @head. @list
282  * should be an empty list or a list you do not care about
283  * losing its data.
284  *
285  */
286 static inline void list_cut_position(struct list_head *list,
287         struct list_head *head, struct list_head *entry)
288 {
289     if (list_empty(head))
290         return;
291     if (list_is_singular(head) &&
292         (head->next != entry && head != entry))
293         return;
294     if (entry == head)
295         INIT_LIST_HEAD(list);
296     else
297         __list_cut_position(list, head, entry);
298 }
299
300 static inline void __list_splice(const struct list_head *list,
301                  struct list_head *prev,
302                  struct list_head *next)
303 {
304     struct list_head *first = list->next;
305     struct list_head *last = list->prev;
306
307     first->prev = prev;
308     prev->next = first;
309
310     last->next = next;
311     next->prev = last;
312 }
313
314 /**
315  * list_splice - join two lists, this is designed for stacks
316  * @list: the new list to add.
317  * @head: the place to add it in the first list.
318  */
319 static inline void list_splice(const struct list_head *list,
320                 struct list_head *head)
321 {
322     if (!list_empty(list))
323         __list_splice(list, head, head->next);
324 }
325
326 /**
327  * list_splice_tail - join two lists, each list being a queue
328  * @list: the new list to add.
329  * @head: the place to add it in the first list.
330  */
331 static inline void list_splice_tail(struct list_head *list,
332                 struct list_head *head)
333 {
334     if (!list_empty(list))
335         __list_splice(list, head->prev, head);
336 }
337
338 /**
339  * list_splice_init - join two lists and reinitialise the emptied list.
340  * @list: the new list to add.
341  * @head: the place to add it in the first list.
342  *
343  * The list at @list is reinitialised
344  */
345 static inline void list_splice_init(struct list_head *list,
346                     struct list_head *head)
347 {
348     if (!list_empty(list)) {
349         __list_splice(list, head, head->next);
350         INIT_LIST_HEAD(list);
351     }
352 }
353
354 /**
355  * list_splice_tail_init - join two lists and reinitialise the emptied list
356  * @list: the new list to add.
357  * @head: the place to add it in the first list.
358  *
359  * Each of the lists is a queue.
360  * The list at @list is reinitialised
361  */
362 static inline void list_splice_tail_init(struct list_head *list,
363                      struct list_head *head)
364 {
365     if (!list_empty(list)) {
366         __list_splice(list, head->prev, head);
367         INIT_LIST_HEAD(list);
368     }
369 }
370
371 /**
372  * list_entry - get the struct for this entry
373  * @ptr:    the &struct list_head pointer.
374  * @type:    the type of the struct this is embedded in.
375  * @member:    the name of the list_struct within the struct.
376  */
377 #define list_entry(ptr, type, member) 378     container_of(ptr, type, member)
379
380 /**
381  * list_first_entry - get the first element from a list
382  * @ptr:    the list head to take the element from.
383  * @type:    the type of the struct this is embedded in.
384  * @member:    the name of the list_struct within the struct.
385  *
386  * Note, that list is expected to be not empty.
387  */
388 #define list_first_entry(ptr, type, member) 389     list_entry((ptr)->next, type, member)
390
391 /**
392  * list_for_each    -    iterate over a list
393  * @pos:    the &struct list_head to use as a loop cursor.
394  * @head:    the head for your list.
395  */
396 #define list_for_each(pos, head) 397     for (pos = (head)->next; pos != (head); pos = pos->next)
398
399 /**
400  * __list_for_each    -    iterate over a list
401  * @pos:    the &struct list_head to use as a loop cursor.
402  * @head:    the head for your list.
403  *
404  * This variant doesn‘t differ from list_for_each() any more.
405  * We don‘t do prefetching in either case.
406  */
407 #define __list_for_each(pos, head) 408     for (pos = (head)->next; pos != (head); pos = pos->next)
409
410 /**
411  * list_for_each_prev    -    iterate over a list backwards
412  * @pos:    the &struct list_head to use as a loop cursor.
413  * @head:    the head for your list.
414  */
415 #define list_for_each_prev(pos, head) 416     for (pos = (head)->prev; pos != (head); pos = pos->prev)
417
418 /**
419  * list_for_each_safe - iterate over a list safe against removal of list entry
420  * @pos:    the &struct list_head to use as a loop cursor.
421  * @n:        another &struct list_head to use as temporary storage
422  * @head:    the head for your list.
423  */
424 #define list_for_each_safe(pos, n, head) 425     for (pos = (head)->next, n = pos->next; pos != (head); 426         pos = n, n = pos->next)
427
428 /**
429  * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
430  * @pos:    the &struct list_head to use as a loop cursor.
431  * @n:        another &struct list_head to use as temporary storage
432  * @head:    the head for your list.
433  */
434 #define list_for_each_prev_safe(pos, n, head) 435     for (pos = (head)->prev, n = pos->prev; 436          pos != (head); 437          pos = n, n = pos->prev)
438
439 /**
440  * list_for_each_entry    -    iterate over list of given type
441  * @pos:    the type * to use as a loop cursor.
442  * @head:    the head for your list.
443  * @member:    the name of the list_struct within the struct.
444  */
445 #define list_for_each_entry(pos, head, member)                446     for (pos = list_entry((head)->next, typeof(*pos), member);    447          &pos->member != (head);     448          pos = list_entry(pos->member.next, typeof(*pos), member))
449
450 /**
451  * list_for_each_entry_reverse - iterate backwards over list of given type.
452  * @pos:    the type * to use as a loop cursor.
453  * @head:    the head for your list.
454  * @member:    the name of the list_struct within the struct.
455  */
456 #define list_for_each_entry_reverse(pos, head, member)            457     for (pos = list_entry((head)->prev, typeof(*pos), member);    458          &pos->member != (head);     459          pos = list_entry(pos->member.prev, typeof(*pos), member))
460
461 /**
462  * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
463  * @pos:    the type * to use as a start point
464  * @head:    the head of the list
465  * @member:    the name of the list_struct within the struct.
466  *
467  * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
468  */
469 #define list_prepare_entry(pos, head, member) 470     ((pos) ? : list_entry(head, typeof(*pos), member))
471
472 /**
473  * list_for_each_entry_continue - continue iteration over list of given type
474  * @pos:    the type * to use as a loop cursor.
475  * @head:    the head for your list.
476  * @member:    the name of the list_struct within the struct.
477  *
478  * Continue to iterate over list of given type, continuing after
479  * the current position.
480  */
481 #define list_for_each_entry_continue(pos, head, member)         482     for (pos = list_entry(pos->member.next, typeof(*pos), member);    483          &pos->member != (head);    484          pos = list_entry(pos->member.next, typeof(*pos), member))
485
486 /**
487  * list_for_each_entry_continue_reverse - iterate backwards from the given point
488  * @pos:    the type * to use as a loop cursor.
489  * @head:    the head for your list.
490  * @member:    the name of the list_struct within the struct.
491  *
492  * Start to iterate over list of given type backwards, continuing after
493  * the current position.
494  */
495 #define list_for_each_entry_continue_reverse(pos, head, member)        496     for (pos = list_entry(pos->member.prev, typeof(*pos), member);    497          &pos->member != (head);    498          pos = list_entry(pos->member.prev, typeof(*pos), member))
499
500 /**
501  * list_for_each_entry_from - iterate over list of given type from the current point
502  * @pos:    the type * to use as a loop cursor.
503  * @head:    the head for your list.
504  * @member:    the name of the list_struct within the struct.
505  *
506  * Iterate over list of given type, continuing from current position.
507  */
508 #define list_for_each_entry_from(pos, head, member)             509     for (; &pos->member != (head);    510          pos = list_entry(pos->member.next, typeof(*pos), member))
511
512 /**
513  * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
514  * @pos:    the type * to use as a loop cursor.
515  * @n:        another type * to use as temporary storage
516  * @head:    the head for your list.
517  * @member:    the name of the list_struct within the struct.
518  */
519 #define list_for_each_entry_safe(pos, n, head, member)            520     for (pos = list_entry((head)->next, typeof(*pos), member),    521         n = list_entry(pos->member.next, typeof(*pos), member);    522          &pos->member != (head);                     523          pos = n, n = list_entry(n->member.next, typeof(*n), member))
524
525 /**
526  * list_for_each_entry_safe_continue - continue list iteration safe against removal
527  * @pos:    the type * to use as a loop cursor.
528  * @n:        another type * to use as temporary storage
529  * @head:    the head for your list.
530  * @member:    the name of the list_struct within the struct.
531  *
532  * Iterate over list of given type, continuing after current point,
533  * safe against removal of list entry.
534  */
535 #define list_for_each_entry_safe_continue(pos, n, head, member)         536     for (pos = list_entry(pos->member.next, typeof(*pos), member),         537         n = list_entry(pos->member.next, typeof(*pos), member);        538          &pos->member != (head);                        539          pos = n, n = list_entry(n->member.next, typeof(*n), member))
540
541 /**
542  * list_for_each_entry_safe_from - iterate over list from current point safe against removal
543  * @pos:    the type * to use as a loop cursor.
544  * @n:        another type * to use as temporary storage
545  * @head:    the head for your list.
546  * @member:    the name of the list_struct within the struct.
547  *
548  * Iterate over list of given type from current point, safe against
549  * removal of list entry.
550  */
551 #define list_for_each_entry_safe_from(pos, n, head, member)             552     for (n = list_entry(pos->member.next, typeof(*pos), member);        553          &pos->member != (head);                        554          pos = n, n = list_entry(n->member.next, typeof(*n), member))
555
556 /**
557  * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
558  * @pos:    the type * to use as a loop cursor.
559  * @n:        another type * to use as temporary storage
560  * @head:    the head for your list.
561  * @member:    the name of the list_struct within the struct.
562  *
563  * Iterate backwards over list of given type, safe against removal
564  * of list entry.
565  */
566 #define list_for_each_entry_safe_reverse(pos, n, head, member)        567     for (pos = list_entry((head)->prev, typeof(*pos), member),    568         n = list_entry(pos->member.prev, typeof(*pos), member);    569          &pos->member != (head);                     570          pos = n, n = list_entry(n->member.prev, typeof(*n), member))
571
572 /**
573  * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
574  * @pos:    the loop cursor used in the list_for_each_entry_safe loop
575  * @n:        temporary storage used in list_for_each_entry_safe
576  * @member:    the name of the list_struct within the struct.
577  *
578  * list_safe_reset_next is not safe to use in general if the list may be
579  * modified concurrently (eg. the lock is dropped in the loop body). An
580  * exception to this is if the cursor element (pos) is pinned in the list,
581  * and list_safe_reset_next is called after re-taking the lock and before
582  * completing the current iteration of the loop body.
583  */
584 #define list_safe_reset_next(pos, n, member)                585     n = list_entry(pos->member.next, typeof(*pos), member)
586
587 /*
588  * Double linked lists with a single pointer list head.
589  * Mostly useful for hash tables where the two pointer list head is
590  * too wasteful.
591  * You lose the ability to access the tail in O(1).
592  */
593
594 #define HLIST_HEAD_INIT { .first = NULL }
595 #define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
596 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
597 static inline void INIT_HLIST_NODE(struct hlist_node *h)
598 {
599     h->next = NULL;
600     h->pprev = NULL;
601 }
602
603 static inline int hlist_unhashed(const struct hlist_node *h)
604 {
605     return !h->pprev;
606 }
607
608 static inline int hlist_empty(const struct hlist_head *h)
609 {
610     return !h->first;
611 }
612
613 static inline void __hlist_del(struct hlist_node *n)
614 {
615     struct hlist_node *next = n->next;
616     struct hlist_node **pprev = n->pprev;
617     *pprev = next;
618     if (next)
619         next->pprev = pprev;
620 }
621
622 static inline void hlist_del(struct hlist_node *n)
623 {
624     __hlist_del(n);
625     n->next = LIST_POISON1;
626     n->pprev = LIST_POISON2;
627 }
628
629 static inline void hlist_del_init(struct hlist_node *n)
630 {
631     if (!hlist_unhashed(n)) {
632         __hlist_del(n);
633         INIT_HLIST_NODE(n);
634     }
635 }
636
637 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
638 {
639     struct hlist_node *first = h->first;
640     n->next = first;
641     if (first)
642         first->pprev = &n->next;
643     h->first = n;
644     n->pprev = &h->first;
645 }
646
647 /* next must be != NULL */
648 static inline void hlist_add_before(struct hlist_node *n,
649                     struct hlist_node *next)
650 {
651     n->pprev = next->pprev;
652     n->next = next;
653     next->pprev = &n->next;
654     *(n->pprev) = n;
655 }
656
657 static inline void hlist_add_after(struct hlist_node *n,
658                     struct hlist_node *next)
659 {
660     next->next = n->next;
661     n->next = next;
662     next->pprev = &n->next;
663
664     if(next->next)
665         next->next->pprev  = &next->next;
666 }
667
668 /* after that we‘ll appear to be on some hlist and hlist_del will work */
669 static inline void hlist_add_fake(struct hlist_node *n)
670 {
671     n->pprev = &n->next;
672 }
673
674 /*
675  * Move a list from one list head to another. Fixup the pprev
676  * reference of the first entry if it exists.
677  */
678 static inline void hlist_move_list(struct hlist_head *old,
679                    struct hlist_head *new)
680 {
681     new->first = old->first;
682     if (new->first)
683         new->first->pprev = &new->first;
684     old->first = NULL;
685 }
686
687 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
688
689 #define hlist_for_each(pos, head) 690     for (pos = (head)->first; pos ; pos = pos->next)
691
692 #define hlist_for_each_safe(pos, n, head) 693     for (pos = (head)->first; pos && ({ n = pos->next; 1; }); 694          pos = n)
695
696 /**
697  * hlist_for_each_entry    - iterate over list of given type
698  * @tpos:    the type * to use as a loop cursor.
699  * @pos:    the &struct hlist_node to use as a loop cursor.
700  * @head:    the head for your list.
701  * @member:    the name of the hlist_node within the struct.
702  */
703 #define hlist_for_each_entry(tpos, pos, head, member)             704     for (pos = (head)->first;                     705          pos &&                             706         ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); 707          pos = pos->next)
708
709 /**
710  * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
711  * @tpos:    the type * to use as a loop cursor.
712  * @pos:    the &struct hlist_node to use as a loop cursor.
713  * @member:    the name of the hlist_node within the struct.
714  */
715 #define hlist_for_each_entry_continue(tpos, pos, member)         716     for (pos = (pos)->next;                         717          pos &&                             718         ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); 719          pos = pos->next)
720
721 /**
722  * hlist_for_each_entry_from - iterate over a hlist continuing from current point
723  * @tpos:    the type * to use as a loop cursor.
724  * @pos:    the &struct hlist_node to use as a loop cursor.
725  * @member:    the name of the hlist_node within the struct.
726  */
727 #define hlist_for_each_entry_from(tpos, pos, member)             728     for (; pos &&                             729         ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); 730          pos = pos->next)
731
732 /**
733  * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
734  * @tpos:    the type * to use as a loop cursor.
735  * @pos:    the &struct hlist_node to use as a loop cursor.
736  * @n:        another &struct hlist_node to use as temporary storage
737  * @head:    the head for your list.
738  * @member:    the name of the hlist_node within the struct.
739  */
740 #define hlist_for_each_entry_safe(tpos, pos, n, head, member)          741     for (pos = (head)->first;                     742          pos && ({ n = pos->next; 1; }) &&                  743         ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); 744          pos = n)
745
746 #endif
时间: 2024-10-10 06:27:48

linux内核神级list的相关文章

linux内核源码级调试

一 linux内核源码阅读工具 windows下当然首选source insight, 但是linux下就没有source insight这么优秀的工具了,但是也有不少的替代品,但觉绝对部分人会选择vim+ctags+cscope的组合,还有部分人或选择wine中的source insight或选择navigatror,当然对于代码阅读来说vim+ctags+cscope的组合还是比较好的一个选择方案,但是,当我使用了eclipse之后,个人感觉用eclipse作为linux环境下源码阅读工具确

Linux内核--基于Netfilter的内核级包过滤防火墙实现

测试内核版本:Linux Kernel 2.6.35----Linux Kernel 3.2.1 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7572382 更多请查看专栏http://blog.csdn.net/column/details/linux-kernel-net.html 作者:闫明 知识基础:本防火墙的开发基于对Linux内核网络栈有个良好的概念,本人对网络栈的分析是基于早期版本(Linux 1.2.13),在

Linux 内核引导参数简介

概述 内核引导参数大体上可以分为两类:一类与设备无关.另一类与设备有关.与设备有关的引导参数多如牛毛,需要你自己阅读内核中的相应驱动程序源码以获取其能够接受的引导参数.比如,如果你想知道可以向 AHA1542 SCSI 驱动程序传递哪些引导参数,那么就查看 drivers/scsi/aha1542.c 文件,一般在前面 100 行注释里就可以找到所接受的引导参数说明.大多数参数是通过"__setup(... , ...)"函数设置的,少部分是通过"early_param(..

如何切入 Linux 内核源代码

Makefile不是Make Love 从前在学校,混了四年,没有学到任何东西,每天就是逃课,上网,玩游戏,睡觉.毕业的时候,人家跟我说Makefile我完全不知,但是一说Make Love我就来劲了,现在想来依然觉得丢人. 毫不夸张地说,Kconfig和Makefile是我们浏览内核代码时最为依仗的两个文件.基本上,Linux内核中每一个目录下边都会有一个 Kconfig文件和一个Makefile文件.对于一个希望能够在Linux内核的汪洋代码里看到一丝曙光的人来说,将它们放在怎么重要的地位都

详解Linux内核异常处理体系结构

本节内容:Linux内核异常处理的的初始化过程和异常发生时的处理流程. [首先来区分一下两个概念:中断(Interrupt)和异常(Exception).中断属于异常的一种,就拿2440开发板来说,他有60多种中断源,例如来自DMA控制器.UART.IIC和外部中断等.2440有一个专门的中断控制器来处理这些中断,中断控制器在接收到这些中断信号之后就需要ARM920T进入IRQ或FIQ模式进行处理,这两种模式也是中断异常的仅有模式.而异常的概念要广的多,它包括复位.未定义指令.软中断.IRQ等等

Linux内核经典书籍

1.<Linux内核设计与实现> 本书重在原理.适合入门的最佳图书.作者是为2.6内核加入了抢占的人,对调度部分非常精通,而调度是整个系统的核心,因此本书是很权威的. 2.<深入理解Linux内核> 此书比上一本多了些细节.是Linux内核黑客在推荐图书时的首选.写的比较简单易懂,适合刚刚接触LINUX内核的.此书图表很多,形象地给出了关键数据结构的定义,与<Linux内核源代码情景分析>相比,本书内容紧凑,不会一个问题讲解动辄上百页,有提纲挈领的功用,但是深度上要逊于

Linux Kernel - Debug Guide (Linux内核调试指南 )

http://blog.csdn.net/blizmax6/article/details/6747601 linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一部分:基础知识*** 总纲:内核世界的陷阱 源码阅读的陷阱 代码调试的陷阱 原理理解的陷阱 建立调试环境 发行版的选择和安装 安装交叉编译工具 bin工具集的使用 qemu的使用 initrd.img的原理与制作 x86虚拟调试环境的建立 arm虚拟调试环境的建立 arm开发板调试环

(linux)BSP板级支持包开发理解

1. 概述 嵌入式系统由硬件环境.嵌入式操作系统和应用程序组成,硬件环境是操作系统和应用程序运行的硬件平台,它随应用的不同而有不同的要求.硬件平台的多样性是嵌入式系统的主要特点,如何使嵌入式操作系统在不同的硬件平台上有效地运行,是嵌入式系统开发中需要解决的关键问题.解决的方法是在硬件平台和操作系统之间提供硬件相关层来屏蔽这些硬件的差异,给操作系统提供统一的运行环境,这种硬件相关层就是嵌入式系统中的板级支持包BSP(Board Support Package,简称BSP). 2. BSP及其作用

《Linux内核设计与实现》学习总结 Chap4

第四章 进程调度 调度程序负责决定将哪个进程投入运行,何时运行以及运行多长时间,进程调度程序可看做在可运行态进程之间分配有限的处理器时间资源的内核子系统.只有通过调度程序的合理调度,系统资源才能最大限度地发挥作用,多进程才会有并发行的效果. 调度程序没有太复杂的原理,最大限度地利用处理器时间的原则是只要有可以执行的进程,那么就总会有进程正在执行,但是只要系统中可运行的进程的数目比处理器的个数多,就注定某一给定时刻会有一些进程不能执行,这些进程在等待运行,在一组处于可运行状态的进程中,选择―个来执