当前位置:网站首页>当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函数相关实现
边栏推荐
猜你喜欢
随机推荐
Linux系统重启和停止Mysql服务教程
How to make a video gif?Try this video making gif artifact
BUG | 接口返回异常数据
【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
The Record of Reminding myself
正则表达式绕过
【3D建模制作技巧分享】如何使用ZBrush导出效果图
使用cpolar优化树莓派上的网页(2)
3D激光SLAM:LeGO-LOAM---两步优化的帧间里程计及代码分析
字节跳动秋招提前批高频面试问题汇总!(内附答案!)
Will we still need browsers in the future?(feat. Maple words Maple language)
【论文笔记KDD2021】MixGCF: An Improved Training Method for Graph Neural Network-based Recommender Systems
Qt中的常用控件
Redis understanding
Latex fast insert author ORCID
边缘检测——(纯享版)
MySQL的JSON 数据类型1
2022/8/4 树上差分+线段树
JVM内存配置参数GC日志
轮播图动态渲染









