How to implement the callback to application functions in a driver



Suppose I have the following data structure:

typedef struct {
void* data_ptr;
void* notify_param;
void (*notify_func)(void* param);
} ExampleStructure;

Here is what the application looks like:

void notification(void* param)
{
/* Does not have to be free(), user can specify the parameter and do
whatever he wants */
free(param);
}

void main()
{
void* data_ptr = malloc(1024);
ExampleStructure example = {data_ptr, data_ptr, notification};
DeviceIoControl(hDevice, &example);
while (1) {}
}

In the driver, I use GetOwnerProcess() and MapPtrToProcess() to map the
example.data_ptr, and then do something with the data pointed by that
pointer. When done, I call the example.notification (the address is also
mapped) to notify the application that I'm done and let application do
whatever it needs, usually a free(). However, what I've experienced is that
if I do something as simple as operating the local variables in the
notification function, it works, however, if I put a call to free() or access
any global variable of the application, it generates data abort exception.
Does anyone know how to solve this? Thanks a bunch!!!
.



Relevant Pages

  • RE: How to implement the callback to application functions in a driver
    ... > Suppose I have the following data structure: ... >} ExampleStructure; ... > void notification ... > if I do something as simple as operating the local variables in the ...
    (microsoft.public.windowsce.embedded)
  • Re: Applet ( canvas )
    ... int positionX1 = 0; ... @param D The Drawing. ... void collectrectinfo ... Start the Tilemode1 View draw thread. ...
    (comp.lang.java.programmer)
  • APPLET ( CANVAS )
    ... int positionX1 = 0; ... @param D The Drawing. ... void collectrectinfo ... Start the Tilemode1 View draw thread. ...
    (comp.lang.java.programmer)
  • Re: fields for methods?
    ... than one method on a "Brush" object: ... void change_color; ... Sure, "encapsulation" is a buzzword with many competing definitions, ... the same as static local variables because static local variables are like ...
    (comp.programming)
  • Re: C99: Suggestions for style(9)
    ... at the start clearly points that there're no local variables used. ... non-scalar declarations in a function, then a compiler can coalesce them ... void f; ... struct Foo a; ...
    (freebsd-hackers)