views:

1321

answers:

3

I'm writting a Linux module (Kernel Programming), and I`m getting:

"Unable to handle kernel NULL pointer dereference"

What does it mean?

+1  A: 

Sounds like a pointer which currently has the NULL value (zero) is being dereferenced. Assign an address to the pointer before dereferencing it.

e.g.

int x = 5;
int * x_ptr = NULL;

x_ptr = &x; // this line may be missing in your code

*x_ptr += 5; //can't dereference x_ptr here if x_ptr is still NULL
Nathan
Your analysis is correct, but the comment in the code is wrong. *x_ptr += 5 is OK because x_ptr now has the address of x (a stack address) and thus can be dereferenced.
ctuffli
+2  A: 

The kernel tries to read from address 0, which your kernel apparently treats specially (good thing!). As the kernel has no way to just kill itself like we know from user mode applications (those would have received a Segmentation Fault), this error is fatal. It will have probably panic'ed and displayed that message to you.


http://en.wikipedia.org/wiki/Null_pointer#The_null_pointer

Johannes Schaub - litb
+1  A: 

It means the kernel tried to deference a null pointer. This generates a page fault which can't be handled in the kernel- if it's running a user task (but in kernel space), it generally makes an "Oops" which (uncleanly) kills the current task and may leak kernel resources. If it's in some other context, e.g. an interrupt, it generally causes a kernel panic.

MarkR