kernel/unwind/user.c
Source file repositories/reference/linux-study-clean/kernel/unwind/user.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/unwind/user.c- Extension
.c- Size
- 3635 bytes
- Lines
- 162
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/sched.hlinux/sched/task_stack.hlinux/unwind_user.hlinux/uaccess.h
Detected Declarations
function get_user_wordfunction unwind_user_next_commonfunction unwind_user_next_fpfunction unwind_user_nextfunction for_each_set_bitfunction unwind_user_startfunction unwind_userfunction for_each_user_frame
Annotated Snippet
switch (type) {
case UNWIND_USER_TYPE_FP:
if (!unwind_user_next_fp(state))
return 0;
continue;
default:
WARN_ONCE(1, "Undefined unwind bit %d", bit);
break;
}
break;
}
/* No successful unwind method. */
state->current_type = UNWIND_USER_TYPE_NONE;
state->done = true;
return -EINVAL;
}
static int unwind_user_start(struct unwind_user_state *state)
{
struct pt_regs *regs = task_pt_regs(current);
memset(state, 0, sizeof(*state));
if ((current->flags & PF_KTHREAD) || !user_mode(regs)) {
state->done = true;
return -EINVAL;
}
if (IS_ENABLED(CONFIG_HAVE_UNWIND_USER_FP))
state->available_types |= UNWIND_USER_TYPE_FP;
state->ip = instruction_pointer(regs);
state->sp = user_stack_pointer(regs);
state->fp = frame_pointer(regs);
state->ws = unwind_user_word_size(regs);
if (!state->ws) {
state->done = true;
return -EINVAL;
}
state->topmost = true;
return 0;
}
int unwind_user(struct unwind_stacktrace *trace, unsigned int max_entries)
{
struct unwind_user_state state;
trace->nr = 0;
if (!max_entries)
return -EINVAL;
if (current->flags & PF_KTHREAD)
return 0;
for_each_user_frame(&state) {
trace->entries[trace->nr++] = state.ip;
if (trace->nr >= max_entries)
break;
}
return 0;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched.h`, `linux/sched/task_stack.h`, `linux/unwind_user.h`, `linux/uaccess.h`.
- Detected declarations: `function get_user_word`, `function unwind_user_next_common`, `function unwind_user_next_fp`, `function unwind_user_next`, `function for_each_set_bit`, `function unwind_user_start`, `function unwind_user`, `function for_each_user_frame`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.