kernel BUG
https://kernelnewbies.org/FAQ/BUG
BUG() and BUG_ON(condition) are used as a debugging help when something in the kernel goes terribly wrong. When a BUG_ON() assertion fails, or the code takes a branch with BUG() in it, the kernel will print out the contents of the registers and a stack trace. After that the current process will die.
The following are examples of how BUG() and BUG_ON() are used, from a piece of code that is not supposed to run in interrupt context. The explicit if with BUG() is the coding style used in older kernels. In the 2.6 kernel, generally BUG_ON() is preferred.
if (in_interrupt())
BUG(); BUG_ON(in_interrupt());
How it works
#define BUG() \
do { \
asm volatile("ud2"); \
unreachable(); \
} while (0)
unreachable():
https://lkml.org/lkml/2016/2/10/821
Hi, I noticed that the use of the function -- unreachable() -- inside of
the BUG() macro in arch/x86/include/asm/bug.h causes compiler output
to be suspect based on review of assembly output for quite a few
areas. if as a test, you remove the call to unreachable() in the BUG() macro,
it seems to generate a large number of build warnings about the use of
uninitialized variables that are apparently masked by the compiler
since it believes this code is going to halt, even in the cases where
the BUG() macro is used conditionally, as in an if (condition) then
BUG() (which the compiler does not seem to understand). This seems to indicate that the use of these built in macros telling
the compiler to create a bunch of infinite jump labels is masking
quite a few bugs lurking around in the regular code since gcc
apparently just throws out the checks for uninitialized variables in
any function if it sees this macro anywhere in the function.
BUG() is defined as an invalid instruction, which means the CPU will throw an invalid opcode exception. This is caught in arch/i386/kernel/entry.S, in the invalid_op entry point, which calls the generated function do_invalid_op from arch/i386/kernel/traps.c. The following macros generate the do_invalid_op() function:
#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
fastcall void do_##name(struct pt_regs * regs, long error_code) \
{ \
siginfo_t info; \
info.si_signo = signr; \
info.si_errno = 0; \
info.si_code = sicode; \
info.si_addr = (void __user *)siaddr; \
if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
== NOTIFY_STOP) \
return; \
do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
} DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip)
The do_trap() function will discover that the trap happened while running in kernel mode, and that there is no fixup for exceptions that happen while running at this address. See FAQ/TestWpBit to learn about exception fixups.
kernel_trap: {
if (!fixup_exception(regs))
die(str, regs, error_code);
return;
}
That in turn means that the current thread dies, printing a register dump and stack trace before it goes. The die() function has some magic of its own, which I won't go into here.
[yaowei@BCLinux linux]$ less arch/x86/kernel/crash
crash.c crash_dump_32.c crash_dump_64.c
[yaowei@BCLinux linux]$ less arch/x86/kernel/dumpstack
dumpstack_32.c dumpstack_64.c dumpstack.c
[yaowei@BCLinux linux]$ less arch/x86/kernel/traps.c
[yaowei@BCLinux linux]$ less kernel/panic.c
kernel BUG的更多相关文章
- 线上centos6出现软死锁 kernel:BUG: soft lockup
线上centos6出现软死锁 kernel:BUG: soft lockup 今天线上一台centos6机器用xshell一直连接不上,然后在xshell上显示 Message from syslog ...
- I.MX6 Kernel BUG at include/linux/netdevice.h:520!
/*************************************************************************** * I.MX6 Kernel BUG at i ...
- RHEL6 kernel bug在hadoop上的测试
最近给hadoop集群升级了RHEL6,发现性能比之前的差了不少.发现淘宝内核组发现并解决了这个问题 原文链接:http://blog.donghao.org/2013/03/20/hadoop%E9 ...
- kernel:NMI watchdog: BUG: soft lockup - CPU#6 stuck for 28s! CentOS7linux中内核被锁死
环境说明:虚拟机 CentOS7中解压一个8G的包时,内核报错 Message from syslogd@cosmo-01 at Apr 25 11:05:59 ... kernel:NMI watc ...
- karottc A Simple linux-virus Analysis、Linux Kernel <= 2.6.37 - Local Privilege Escalation、CVE-2010-4258、CVE-2010-3849、CVE-2010-3850
catalog . 程序功能概述 . 感染文件 . 前置知识 . 获取ROOT权限: Linux Kernel <= - Local Privilege Escalation 1. 程序功能概述 ...
- Linux bug 14258279: scheduling clock overflows in 208 days
早上同事反映数据库不能用.无法正常登录主机.多次尝试后终于登上主机,检查系统日志发现下述错误: BUG: soft lockup - CPU#5 stuck for 17163091988s! 貌似是 ...
- 深入 kernel panic 流程【转】
一.前言 我们在项目开发过程中,很多时候会出现由于某种原因经常会导致手机系统死机重启的情况(重启分Android重启跟kernel重启,而我们这里只讨论kernel重启也就是 kernel panic ...
- CentOS 7.1系统自动重启的Bug定位过程
[问题] 有同事反应最近有多台MongoDB的服务器CentOS 7.1系统会自动重启,分析了下问题原因. [排查过程] 1. 检查系统日志/var/log/message,并没有记录异常信息,jou ...
- 总结一下内核DEBUG中的dump_stack, BUG, BUG_ON以及panic
有点空闲时间,让我们来总结一下内核DEBUG中的各个语句吧.随便找个内核驱动,在init函数里面加入如下代码测试: u8 a = 1, b = 0; printk("----------du ...
随机推荐
- XXXX公司微课大赛技术储备
XXXX公司微课大赛技术储备 发短信验证 http://www.yunpian.com/ 发邮件 http://sendcloud.sohu.com/ flash头像上传组件 http://www.h ...
- css伪类元素:after 的多功能用法——任意大小的底边框
需求用法出现的背景: 由于项目UI的优化,项目中所有tab导航选中的状态都是统一样式书写的,之前都是用的border-bottom,新的需求如果用以前的本办法就是定位一个选中边框在底部,但是涉及的模板 ...
- Vue v-for嵌套数据渲染问题
Vue v-for嵌套数据渲染问题 问题描述: 由于在获取商品子分类的时候,同时需要获取子分类下的商品,那么多层的列表渲染就只能是第一层好用 问题原因: vue在处理多层的渲染的时候,不能直接用等号赋 ...
- DAG动态规划-硬币问题
题目:有n种硬币,面值分别为V1,V2,...Vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为S?输出硬币数目的最小值和最大值! #include <bits/std ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)F 猴子排序的期望【Java/高精度/组合数学+概率论】
链接:https://www.nowcoder.com/acm/contest/116/F 来源:牛客网 题目描述 我们知道有一种神奇的排序方法叫做猴子排序,就是把待排序的数字写在卡片上,然后让猴子把 ...
- eclipse 启动报错 java was started but returned code=13
eclipse启动不了,出现“Java was started but returned exit code=13......”对话框如下 我的解决方法是:去控制面板--程序--卸载程序和功能下面查看 ...
- nginx服务器设置path_info模式
1.find / -name nginx.conf找到nginx配置文件 2. ## The default server#server { listen 80; #填写自己的域名 server_na ...
- ylbtech-WelfareSystem(福利发放管理系统)-数据库设计
ylbtech-DatabaseDesgin:ylbtech-WelfareSystem(福利发放管理系统)-数据库设计 1.A,数据库关系图(Database Diagram) 1.B,数据库设计脚 ...
- Geek改变世界
在10月24号的GeekPwn到来前,主办方 — 来自Keen Team的创始人大牛蛙希望我能为GeekPwn写点东西.作为GeekPwn的顾问,我也非常乐意为这次首秀做一点事情. 正如之前提到过的, ...
- Python-使用Magellan进行数据匹配总结
参考:http://www.biggorilla.org/zh-hans/walkt/ 使用Magellan进行数据匹配过程如下: 假设有两个数据源为A和B, A共有四列数据:(A_Column1,A ...