Skip to contentSkip to conversation

task switch hook - crashes

DISCUSSION Krisztian Flautner 1 participant 1 message Mar 15, 2001

lore
Share & tools
lore
#0 lore raw

I am experimenting with adding a few hooks to the kernel. One of the hooks gets invoked every time the kernel switches two tasks. To do this I added a single line to schedule() right before the tasks are switched:

     ...
     if (task_switch_hook) task_switch_hook(prev, next)

     switch_to(prev, next, prev);
     ...

I then wrote a module that attaches a function to this hook in its init_module() function. The problem is that if I do this, the kernel crashes. Sometimes, the hooks are invoked a few times, other times, the machine locks up immediately. I previous version that compiled everything into the kernel worked fine.

I don't quite understand why this does not work. Is this due to some virtual memory interactions? Maybe the problem is that modules are vmalloc-ed and the hook function should be kmalloc-ed?

Any insights?

Thanks, -- Kris