I am trying to implement mahogany / ebony on Linux on task_struct using code from linux/rbtree.h. I can correctly insert mahogany / ebony in a separate space in the kernel, such as a module, but when I try to get the same code to work with rb_rootone declared either in task_struct, or task_struct->files_struct, I get a SEGFAULTevery time I try to insert.
Here is the code:
In task_struct, I create a structure rb_rootfor my tree (not a pointer). In init_task.h, macro INIT_TASK(tsk), I set it equal rb_root. To do the insert, I use this code:
rb_insert(&(current->fd_tree), &rbnode);
This is where the problem arises.
My insert command is a standard insert, which is documented throughout the RBTree documentation for the kernel:
int my_insert(struct rb_root *root, struct mytype *data)
{
struct rb_node **new = &(root->rb_node), *parent = NULL;
while (*new) {
struct mytype *this = container_of(*new, struct mytype, node);
int result = strcmp(data->keystring, this->keystring);
parent = *new;
if (result < 0)
new = &((*new)->rb_left);
else if (result > 0)
new = &((*new)->rb_right);
else
return FALSE;
}
rb_link_node(&data->node, parent, new);
rb_insert_color(&data->node, root);
return TRUE;
}
Is there something I am missing?
- , task_struct? rb_root , . task_struct task_struct->files_struct, a SEGFAULT. root node ?
. , .
Edit:
SEGFAULT , . , . rb_entry rb_first - , . current ( ), tree - node ( ), ( ). rb_first *rb_root. .
printk(KERN_CRIT "node=%d\n", rb_entry(rb_first(&(current->tree)), struct rb_tree_struct, node)->fd_key);