lib/bug.c
Source file repositories/reference/linux-study-clean/lib/bug.c
File Facts
- System
- Linux kernel
- Corpus path
lib/bug.c- Extension
.c- Size
- 7822 bytes
- Lines
- 316
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/list.hlinux/module.hlinux/kernel.hlinux/bug.hlinux/sched.hlinux/rculist.hlinux/ftrace.hlinux/context_tracking.hkunit/test-bug.h
Detected Declarations
function bug_addrfunction module_bug_finalizefunction module_bug_cleanupfunction bug_get_file_linefunction __printffunction __report_bugfunction BUGfunction report_bug_entryfunction report_bugfunction clear_once_tablefunction generic_bug_clear_oncefunction scoped_guard
Annotated Snippet
if (args) {
vprintk(fmt, *args);
return;
}
}
#endif
pr_warn("%s", fmt);
}
static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long bugaddr, struct pt_regs *regs)
{
bool warning, once, done, no_cut, has_args;
const char *file, *fmt;
unsigned int line;
if (!bug) {
if (!is_valid_bugaddr(bugaddr))
return BUG_TRAP_TYPE_NONE;
bug = find_bug(bugaddr);
if (!bug)
return BUG_TRAP_TYPE_NONE;
}
bug_get_file_line(bug, &file, &line);
fmt = bug_get_format(bug);
warning = bug->flags & BUGFLAG_WARNING;
once = bug->flags & BUGFLAG_ONCE;
done = bug->flags & BUGFLAG_DONE;
no_cut = bug->flags & BUGFLAG_NO_CUT_HERE;
has_args = bug->flags & BUGFLAG_ARGS;
#ifdef CONFIG_KUNIT
/*
* Before the once logic so suppressed warnings do not consume
* the single-fire budget of WARN_ON_ONCE().
*/
if (warning && kunit_is_suppressed_warning(true))
return BUG_TRAP_TYPE_WARN;
#endif
disable_trace_on_warning();
if (warning && once) {
if (done)
return BUG_TRAP_TYPE_WARN;
/*
* Since this is the only store, concurrency is not an issue.
*/
bug->flags |= BUGFLAG_DONE;
}
/*
* BUG() and WARN_ON() families don't print a custom debug message
* before triggering the exception handler, so we must add the
* "cut here" line now. WARN() issues its own "cut here" before the
* extra debugging message it writes before triggering the handler.
*/
if (!no_cut) {
pr_info(CUT_HERE);
__warn_printf(fmt, has_args ? regs : NULL);
}
if (warning) {
/* this is a WARN_ON rather than BUG/BUG_ON */
__warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
NULL);
return BUG_TRAP_TYPE_WARN;
}
if (file)
pr_crit("kernel BUG at %s:%u!\n", file, line);
else
pr_crit("kernel BUG at %pB [verbose debug info unavailable]\n",
(void *)bugaddr);
return BUG_TRAP_TYPE_BUG;
}
enum bug_trap_type report_bug_entry(struct bug_entry *bug, struct pt_regs *regs)
{
enum bug_trap_type ret;
bool rcu;
rcu = warn_rcu_enter();
ret = __report_bug(bug, bug_addr(bug), regs);
warn_rcu_exit(rcu);
Annotation
- Immediate include surface: `linux/list.h`, `linux/module.h`, `linux/kernel.h`, `linux/bug.h`, `linux/sched.h`, `linux/rculist.h`, `linux/ftrace.h`, `linux/context_tracking.h`.
- Detected declarations: `function bug_addr`, `function module_bug_finalize`, `function module_bug_cleanup`, `function bug_get_file_line`, `function __printf`, `function __report_bug`, `function BUG`, `function report_bug_entry`, `function report_bug`, `function clear_once_table`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.