kernel/events/uprobes.c
Source file repositories/reference/linux-study-clean/kernel/events/uprobes.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/events/uprobes.c- Extension
.c- Size
- 75862 bytes
- Lines
- 2915
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/highmem.hlinux/pagemap.hlinux/slab.hlinux/sched.hlinux/sched/mm.hlinux/export.hlinux/rmap.hlinux/mmu_notifier.hlinux/swap.hlinux/ptrace.hlinux/kdebug.hlinux/percpu-rwsem.hlinux/task_work.hlinux/shmem_fs.hlinux/khugepaged.hlinux/rcupdate_trace.hlinux/workqueue.hlinux/srcu.hlinux/oom.hlinux/pagewalk.hlinux/uprobes.h
Detected Declarations
struct uprobestruct delayed_uprobestruct xol_areastruct __uprobe_keystruct map_infofunction uprobe_warnfunction valid_vmafunction offset_to_vaddrfunction vaddr_to_offsetfunction is_swbp_insnfunction instructionsfunction uprobe_copy_from_pagefunction copy_to_pagefunction verify_opcodefunction delayed_uprobe_checkfunction delayed_uprobe_addfunction delayed_uprobe_deletefunction delayed_uprobe_removefunction list_for_each_safefunction valid_ref_ctr_vmafunction find_ref_ctr_vmafunction __update_ref_ctrfunction update_ref_ctr_warnfunction update_ref_ctrfunction orig_page_is_identicalfunction __uprobe_writefunction can_follow_write_ptefunction folio_trylockfunction uprobe_write_opcodefunction uprobe_writefunction set_swbpfunction set_orig_insnfunction uprobe_is_activefunction uprobe_free_rcu_tasks_tracefunction uprobe_free_srcufunction uprobe_free_deferredfunction put_uprobefunction hprobe_init_leasedfunction hprobe_init_stablefunction hprobe_consumefunction hprobe_finalizefunction try_get_uprobefunction hprobe_consumefunction uprobe_cmpfunction __uprobe_cmp_keyfunction __uprobe_cmpfunction existsfunction ref_ctr_mismatch_warn
Annotated Snippet
* Called in context of a new clone/fork from copy_process.
*/
void uprobe_copy_process(struct task_struct *t, u64 flags)
{
struct uprobe_task *utask = current->utask;
struct mm_struct *mm = current->mm;
struct xol_area *area;
t->utask = NULL;
if (!utask || !utask->return_instances)
return;
if (mm == t->mm && !(flags & CLONE_VFORK))
return;
if (dup_utask(t, utask))
return uprobe_warn(t, "dup ret instances");
/* The task can fork() after dup_xol_work() fails */
area = mm->uprobes_state.xol_area;
if (!area)
return uprobe_warn(t, "dup xol area");
if (mm == t->mm)
return;
t->utask->dup_xol_addr = area->vaddr;
init_task_work(&t->utask->dup_xol_work, dup_xol_work);
task_work_add(t, &t->utask->dup_xol_work, TWA_RESUME);
}
/*
* Current area->vaddr notion assume the trampoline address is always
* equal area->vaddr.
*
* Returns -1 in case the xol_area is not allocated.
*/
unsigned long uprobe_get_trampoline_vaddr(void)
{
unsigned long trampoline_vaddr = UPROBE_NO_TRAMPOLINE_VADDR;
struct xol_area *area;
/* Pairs with xol_add_vma() smp_store_release() */
area = READ_ONCE(current->mm->uprobes_state.xol_area); /* ^^^ */
if (area)
trampoline_vaddr = area->vaddr;
return trampoline_vaddr;
}
static void cleanup_return_instances(struct uprobe_task *utask, bool chained,
struct pt_regs *regs)
{
struct return_instance *ri = utask->return_instances, *ri_next;
enum rp_check ctx = chained ? RP_CHECK_CHAIN_CALL : RP_CHECK_CALL;
while (ri && !arch_uretprobe_is_alive(ri, ctx, regs)) {
ri_next = ri->next;
rcu_assign_pointer(utask->return_instances, ri_next);
utask->depth--;
free_ret_instance(utask, ri, true /* cleanup_hprobe */);
ri = ri_next;
}
}
static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs,
struct return_instance *ri)
{
struct uprobe_task *utask = current->utask;
unsigned long orig_ret_vaddr, trampoline_vaddr;
bool chained;
int srcu_idx;
if (!get_xol_area())
goto free;
if (utask->depth >= MAX_URETPROBE_DEPTH) {
printk_ratelimited(KERN_INFO "uprobe: omit uretprobe due to"
" nestedness limit pid/tgid=%d/%d\n",
current->pid, current->tgid);
goto free;
}
trampoline_vaddr = uprobe_get_trampoline_vaddr();
orig_ret_vaddr = arch_uretprobe_hijack_return_addr(trampoline_vaddr, regs);
if (orig_ret_vaddr == -1)
goto free;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/highmem.h`, `linux/pagemap.h`, `linux/slab.h`, `linux/sched.h`, `linux/sched/mm.h`, `linux/export.h`, `linux/rmap.h`.
- Detected declarations: `struct uprobe`, `struct delayed_uprobe`, `struct xol_area`, `struct __uprobe_key`, `struct map_info`, `function uprobe_warn`, `function valid_vma`, `function offset_to_vaddr`, `function vaddr_to_offset`, `function is_swbp_insn`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.