arch/x86/kernel/unwind_orc.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/unwind_orc.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/unwind_orc.c- Extension
.c- Size
- 20740 bytes
- Lines
- 797
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/objtool.hlinux/module.hlinux/sort.hlinux/bpf.hasm/ptrace.hasm/stacktrace.hasm/unwind.hasm/orc_types.hasm/orc_lookup.hasm/orc_header.h
Detected Declarations
function unwind_debug_cmdlinefunction unwind_dumpfunction orc_ipfunction orc_sort_swapfunction orc_sort_cmpfunction unwind_module_initfunction unwind_initfunction unwind_get_return_addressfunction stack_access_okfunction deref_stack_regfunction deref_stack_regsfunction deref_stack_iret_regsfunction get_regfunction unwind_next_framefunction on_stackfunction __unwind_startexport unwind_get_return_addressexport unwind_next_frameexport __unwind_start
Annotated Snippet
if (unwind_debug && !dumped_before) { \
dumped_before = true; \
unwind_dump(state); \
} \
} \
})
extern int __start_orc_unwind_ip[];
extern int __stop_orc_unwind_ip[];
extern struct orc_entry __start_orc_unwind[];
extern struct orc_entry __stop_orc_unwind[];
static bool orc_init __ro_after_init;
static bool unwind_debug __ro_after_init;
static unsigned int lookup_num_blocks __ro_after_init;
static int __init unwind_debug_cmdline(char *str)
{
unwind_debug = true;
return 0;
}
early_param("unwind_debug", unwind_debug_cmdline);
static void unwind_dump(struct unwind_state *state)
{
static bool dumped_before;
unsigned long word, *sp;
struct stack_info stack_info = {0};
unsigned long visit_mask = 0;
if (dumped_before)
return;
dumped_before = true;
printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
state->stack_info.type, state->stack_info.next_sp,
state->stack_mask, state->graph_idx);
for (sp = __builtin_frame_address(0); sp;
sp = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
if (get_stack_info(sp, state->task, &stack_info, &visit_mask))
break;
for (; sp < stack_info.end; sp++) {
word = READ_ONCE_NOCHECK(*sp);
printk_deferred("%0*lx: %0*lx (%pB)\n", BITS_PER_LONG/4,
(unsigned long)sp, BITS_PER_LONG/4,
word, (void *)word);
}
}
}
static inline unsigned long orc_ip(const int *ip)
{
return (unsigned long)ip + *ip;
}
static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_table,
unsigned int num_entries, unsigned long ip)
{
int *first = ip_table;
int *last = ip_table + num_entries - 1;
int *mid, *found = first;
if (!num_entries)
return NULL;
/*
* Do a binary range search to find the rightmost duplicate of a given
* starting address. Some entries are section terminators which are
* "weak" entries for ensuring there are no gaps. They should be
* ignored when they conflict with a real entry.
*/
while (first <= last) {
mid = first + ((last - first) / 2);
if (orc_ip(mid) <= ip) {
found = mid;
first = mid + 1;
} else
last = mid - 1;
}
return u_table + (found - ip_table);
}
Annotation
- Immediate include surface: `linux/objtool.h`, `linux/module.h`, `linux/sort.h`, `linux/bpf.h`, `asm/ptrace.h`, `asm/stacktrace.h`, `asm/unwind.h`, `asm/orc_types.h`.
- Detected declarations: `function unwind_debug_cmdline`, `function unwind_dump`, `function orc_ip`, `function orc_sort_swap`, `function orc_sort_cmp`, `function unwind_module_init`, `function unwind_init`, `function unwind_get_return_address`, `function stack_access_ok`, `function deref_stack_reg`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.