linux中断 用户程序,Linux中断发生时给用户程序发信号

为了实现在内核态唤醒用户程序,就尝试用发信号的方式,结果中断发生时,就死机了,不知道这个信号是怎么发出去的,更不知道用户程序有没有收到信号。

烦恼中在网上收集了些信息,附加在这里来分析。

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

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都不行,发送信号的时候还是会死机

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

总结一下,原本我是想在驱动程序的中断服务程序中通知用户程序这个中断发生了,像这样在内核态发信号给用户态的做法有很大的安全隐患,其实可以在用户程序中read这个设备,在驱动程序中阻塞read函数的实现函数,等待中断的发生才让read的实现函数返回,那么在用户程序中就知道了中断发生了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值