Saturday 15 June 2013

C: Linux built in linked list in kernel data structures usage -



C: Linux built in linked list in kernel data structures usage -

i attempting add together scheme phone call linux kernel , advantageous utilize built-in linked list modifying task_struct (by adding linked list), , task_struct has quite few struct list_head's in there other purposes. uniformity, stick info structure.

my issue don't understand how utilize structure. see have "struct list_head children" example. however, implementation of construction simple "*next" , "*last".

i've looked examples online , every single 1 says, make

struct node{ int data; struct list_head list; };

but wouldn't indicate info construction should including in task_struct should

struct node list;

?

i don't quite understand how initialize construction contain info contain if utilize list_head.

essentially want add together linked list of scheme calls , tack them on process in form of linked list of char* (readable format).

for now, semantics of obtaining scheme phone call info unimportant... need figure out how linked list working task_struct.

edit: illustration of trying do:

i've obtained list of scheme calls performed function. keeping these in separate char* variables. add together list within processes task_struct keeps track of of these scheme calls.

for example

process 'abc' calls printf ~> equates "writescreen" getchar ~> equates "readkey"

i have userland piece of code has these 2 strings. phone call scheme phone call write (once per tag) "tag" process these scheme calls.

after both calls, task_struct of 'abc' has list

abc->task_struct->tag_list

this list contains "writescreen" , "readkey".

later utilize these tags print list of processes have called writescreen, readkey, etc. implementation of these happen after find out how utilize list appropriately store strings attached process.

so instead of creating list of processes (task_struct) you're trying accomplish list per process.

this means each process have own list, i.e. own list head.

this list store, in add-on next/prev pointers, single piece of data, string (could string or pointer string elsewhere).

the list node therefore:

struct my_node { struct list_head list; char data[100]; // arbitrarily set 100; char* }

the task_struct should augmented new list head:

struct task_struct { // many members contains info process ... struct list_head my_list; }

yes. you'll notice both cases (when process belongs list, , when list belongs process) fellow member same; utilize different.

now, when process created should initialize list head (as each process have new list):

init_list_head(&new_process.my_list);

to insert new node (supposing created it, is, allocated memory , initialized data):

struct my_node *node; struct task_struct *a_process; [... my_node initialized ...] [... a_proccess obtained somehow ...] list_add_tail(&node->list, &a_process->my_list);

to iterate on elements:

struct my_node *p; struct task_struct *a_process // list fellow member name (yes, fellow member name) of list within my_node list_for_each_entry(p, &a_process->my_list, list) { // whatever want p }

edit:

note, however, have other ways trying do, without resorting complex linked lists.

for instance, allocate single char array , encode list of strings means of separating them char (commas, periods, , on). way:

"writescreen,readkey\0"

in case should after buffer limits, never overflow it. on other hand not have take care of allocating , freeing nodes of list.

c linux-kernel kernel

No comments:

Post a Comment