Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339760
  • 博文数量: 166
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-21 17:29
文章分类

全部博文(166)

文章存档

2015年(60)

2014年(99)

2013年(7)

我的朋友

分类: LINUX

2014-01-02 17:25:17

为了实现在内核态唤醒用户程序,就尝试用发信号的方式,结果中断发生时,就死机了,不知道这个信号是怎么发出去的,更不知道用户程序有没有收到信号。
烦恼中在网上收集了些信息,附加在这里来分析。

内核态:(请来拿分) 内核态驱动的中断里怎么发信号给用户程序?


1/6/2009
我的一个网卡驱动,我发现在它的接收中断里不能发信号给用户程序,否则会出现错误,死机,非中断的地方可以发的。我用的函数是send_sig(sig,*task struct,priv),这个函数的第三个参数priv有什么作用? 谢谢!

针对第一个问题。可能是信号级别问题?

至于第二个问题,我找到一个回答,你看看先。
kernel to user space signalling
You should find the task structure using find_task_by_pid(pid) and then deliver the signal.
You also have to take care of some locks(mostly siglock).


节自 < > 3rd.

11.2.1. The specific_send_sig_info( ) Function
The specific_send_sig_info( ) function sends a signal to a specific process. It acts on three parameters:


sig

The signal number.


info

Either the address of a siginfo_t table or one of three special values: 0 means that the signal has been sent by a User Mode process, 1 means that it has been sent by the kernel, and 2 means that is has been sent by the kernel and the signal is SIGSTOP or SIGKILL.


t

A pointer to the descriptor of the destination process.

补充

kernel/signal.c:
#define __si_special(priv) \
        ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)

int
send_sig(int sig, struct task_struct *p, int priv)
{
        return send_sig_info(sig, __si_special(priv), p);
}


include/linux/sched.h:
/* These can be the second arg to send_sig_info/send_group_sig_info.  */
#define SEND_SIG_NOINFO ((struct siginfo *) 0)
#define SEND_SIG_PRIV  ((struct siginfo *) 1)
#define SEND_SIG_FORCED ((struct siginfo *) 2)


send_sig_info()会调用
specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)

然后参考上面的siginfo解释。



楼上的不对,我priv 试了0,1,2都不行,发送信号的时候还是会死机

结帖了,中断中确实是不能发送信号的
 

RT-Signal 及其应用要点http://www.ibm.com/developerworks/cn/linux/l-rtsignal/

Linux 环境进程间通信(二):信号(上),http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html

Linux 环境进程间通信(二):信号(下),http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html

总结一下,原本我是想在驱动程序的中断服务程序中通知用户程序这个中断发生了,像这样在内核态发信号给用户态的做法有很大的安全隐患,其实可以在用户程序中read这个设备,在驱动程序中阻塞read函数的实现函数,等待中断的发生才让read的实现函数返回,那么在用户程序中就知道了中断发生了。
阅读(2755) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~