Results 1 to 4 of 4
Hi guys, I'm writing a simple module which can tell a user process if something happens in kernel. Specifically, inside my module, I declare a symbol:
void *pointer = NULL;
...
- 06-02-2006 #1Just Joined!
- Join Date
- Aug 2005
- Posts
- 6
How to block a process in kernel
Hi guys, I'm writing a simple module which can tell a user process if something happens in kernel. Specifically, inside my module, I declare a symbol:
void *pointer = NULL;
Now, I want to tell some process in userspace when this pointer is not NULL. I did that by doing the following:
In user space
devfd = open("/dev/my_dev",O_RDWR);
//my_dev is a fake character device I created
ioctl(devfd,CHECK_POINTER);
In kernel space
switch CONSTANT
{
...
case CHECK_POINTER: while(pointer==NULL){}
return 0;
}
My intention is letting the kernel blocks ioctl while pointer is NULL and returns immediately when pointer is not NULL. However, this way makes my computer hangs. Do you guys have any better idea to block ioctl.
- 06-04-2006 #2
The hangs comes from this:
Maybe you need a kind of signaling mechanism. What if your user-space programs checks periodically the /dev/my_dev file until it gets the proper value?
Originally Posted by LegolasV
Best regards
- 06-08-2006 #3Just Joined!
- Join Date
- Jun 2006
- Posts
- 3
The best way that I know of to signal a user-mode from kernel-mode is to use signalling. That is equivilent to a user-mode interrupt. You hook a signal and when someone taps that signal for your process, your registered callback function is called.
This taken (cut) from some project I did a couple of years. It is probably missing some stuff, but should be enough to get you going.
For user-mode look at usage for functions:
//Setup
sigaction act;
sigset_t signalsUsed;
act.sa_handler = CallBackFunc;
sigemptyset( &act.sa_mask );
sigaction(SIGINT, &act, 0);
sigaction( YourSignalNo, &act, 0);
//use this to get task id for kernel mode signalling
pid=getpid(); //pass this to your kernel module for use down below
//Signal handler
void CallBackFunc(int signum)
{
sigprocmask(SIG_BLOCK, &signalsUsed, NULL);
printf("SIGNAL RECEIVED:%d\n",signum);
if ( signum == SIGINT )
{
goto EXIT_NOW;
}
//
//Do your work here
//
//Leave
EXIT_NOW:
sigprocmask(SIG_UNBLOCK, &signalsUsed, NULL);
}
For kernel mode, call this to interrupt user-mode (first parm is your signal no, second is the result from calling find_task_by_pid(pid) obtained from the user-mode call getpid() function):
//Interrupt signal owner (user-mode in this case)
extern int send_sig(int, struct task_struct *, int); //kernel function
Hope this helps.
-AM
- 06-21-2006 #4Just Joined!
- Join Date
- Aug 2005
- Posts
- 6
thanks for your reply. I found that wake_up() and sleep() also solves the problem


Reply With Quote
