当前位置:网站首页>当panic或者die被执行时,或者发生未定义指令时,如何被回调到
当panic或者die被执行时,或者发生未定义指令时,如何被回调到
2022-08-04 22:50:00 【szembed】
Panic是Linux kernel提供的一种复位机制,内核开发者在开发过程中,可以在异常流程中主动调用。
另外,还有一部分模块或者子系统,希望系统在panic时,能主动通知一下本模块,以便做一些复位前的准备动作,相应的kernel也提供了该机制,就是让大家注册回调。每次panic在执行过程中,会遍历注册的回调函数并回调之。
实现机制:
1、在panic.c代码中,有一个链表的定义,
ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
EXPORT_SYMBOL(panic_notifier_list);
该链表存储各个模块注册的panic回调函数,以便panic在发生时回调对应回调函数。
2、有了链表头,那么注册就简单了。
1)首先定义自己的回调函数
int my_panic_ notify(struct notifier_block *nb,
unsigned long event, void *buf)
{
………
return 0;
}
static struct notifier_block my_panic_block = {
.notifier_call = my_panic_ notify,
.priority = INT_MAX,
};
然后,在合适的地方,注册到panic链表中(通常是在本模块初始化)
………….
atomic_notifier_chain_register(&panic_notifier_list, & my_panic_block);
…………
3、注册完成后,当系统中有调用panic函数时,panic在执行过程中就会回调注册的函数。
…………..
/*
* Run any panic handlers, including those that might need to
* add information to the kmsg dump output.
*/
atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
…………….
附:同样,在die函数被调用时,也有类似的机制,不做详细介绍,大家可以看一下register_die_notifier/ unregister_die_notifier的相关实现。
未定义指令异常,参考register_undef_hook函数相关实现
边栏推荐
猜你喜欢
随机推荐
文献阅读十——Detect Rumors on Twitter by Promoting Information Campaigns with Generative Adversarial Learn
panic: reflect: reflect.Value.SetString using value obtained using unexported field
【组成原理 六 存储器类型】
Latex快速插入作者ORCID
【无标题】
视频gif如何制作?试试这个视频制作gif神器
JVM内存配置参数GC日志
SQL Server calls WebService
SRv6网络的安全解决方案
今天又做了三个梦,其中一个梦梦里的我还有意识会思考?
历史上的今天:PHP公开发布;iPhone 4 问世;万维网之父诞生
逆序对的数量
QT[一] 信号与槽
Detailed usage of LocalDateTime
直播带货为农产品开拓销售渠道
If you can't get your heart, use "distributed lock" to lock your people
得不到你的心,就用“分布式锁”锁住你的人
【3D建模制作技巧分享】ZBrush如何使用Z球
postman接口测试
【3D建模制作技巧分享】在zbrush中如何雕刻头发 ZBrush头发雕刻小技巧