why my module didn't crash
From: gopan (gop_kumar_at_hotmail.com)
Date: 28 Nov 2003 04:16:51 -0800
I know it is absolutely forbidden to pass a user land
program's function pointer to a module and invoke it inside the module
but just to learn exactly what happens i tried it in this fashion.
In my applicaton program, i have a function say fun() which prints a
hello message using printf and allocates about 100 bytes using
malloc(), then fills up the allocatd buffers with some character say
Using an ioctl call i passed the address of fun() to my module.
The module on receiving the ioctl, will extract the function pointer
and will execute fun()
Now what i was expecting was a module crash due to the page fault as
what i have read about malloc() is, as soon as u call malloc() only
the virtual mem region is reserved for ur process and the physical
pages are allocated only when u touch those virtual regions( when page
fault happens the mem mgr calls page allocation functions to allocate
Considering this fact when i invoke the user land function from my
module, the following should have happened
a) malloc is executed, and the code touches the allocated memory
b) page fault happens as the physical pages are not yet allocated
c)The kernel (Page Fault handler)on finding that the current Privilege
Level (PL)is 0 gives an Oops..
But nothing of this sort happened, how many ever times i called the
ioctl the code worked fine without any crashes!!!
Does this has to do anything with malloc, i mean on return from malloc
does the PL comes to 3 and hence the kernel services the PFault
Awaiting for some explanation