I am some Linux kernel space code. I want an application in user space to be able to register a callback function in the kernel space code by calling a function in the kernel space code and passing the address of that callback function. The kernel space code would then execute the callback function at a later time when running. I believe the kernel space code should look something like this:
typedef void (*callback_func) (void);
callback_func callback;
static void registerCallBack(callback_func funct){callback = funct;}
//another kernel space method
funct();
However, I am a little unsure on the proper typedef and if this will work properly. Can anyone confirm the functionality of this or offer any advice in this area? I am unable to test this right now as I am waiting on the rest of the kernel space code to be finished.
You cannot directly call to a userspace function from the kernel. One possible solution would be to use signals. From the kernel code you could send a signal to a given process. The signal handler would work then as a sort of callback function.