why my module didn't crash

From: gopan (gop_kumar_at_hotmail.com)
Date: 11/28/03


Date: 28 Nov 2003 04:16:51 -0800

hi all,
             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
'a'.

 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
physical pages)

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
without OOPS.??

Awaiting for some explanation

 Thanks



Relevant Pages

  • Re: why my module didnt crash
    ... > hello message using printf and allocates about 100 bytes using ... > malloc(), then fills up the allocatd buffers with some character say ... > fault happens the mem mgr calls page allocation functions to allocate ... > c)The kernel on finding that the current Privilege ...
    (comp.os.linux.development.system)
  • Re: why my module didnt crash
    ... >> program's function pointer to a module and invoke it inside the module ... >> malloc(), then fills up the allocatd buffers with some character say ... >> fault happens the mem mgr calls page allocation functions to allocate ...
    (comp.os.linux.development.system)
  • Re: Why does ANSI not define a function to determine the size of (m)allocated mem? (like _msize)
    ... >> Generally malloc actually allocates somewhat more ... It invokes undefined behavior in the same circumstances as free, ... function to the standard. ...
    (comp.lang.c)
  • Re: Stack or Heap
    ... Gordon Burditt wrote ... > allocates its memory". ... questions- specifiaclly about malloc. ...
    (comp.lang.c)
  • Re: structs and malloc [C]
    ... you don't need to use malloc. ... generate code that allocates space for one Document object. ... If doc is a pointer, ... This should work if doc->title is a pointer to a buffer you've ...
    (alt.comp.lang.learn.c-cpp)