kernel/nstree.c
Source file repositories/reference/linux-study-clean/kernel/nstree.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/nstree.c- Extension
.c- Size
- 18828 bytes
- Lines
- 793
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/nstree.hlinux/proc_ns.hlinux/rculist.hlinux/vfsdebug.hlinux/syscalls.hlinux/user_namespace.h
Detected Declarations
syscall listnsstruct klistnsfunction ns_tree_node_initfunction ns_tree_root_initfunction ns_tree_node_emptyfunction intfunction ns_tree_node_delfunction ns_id_cmpfunction ns_cmpfunction ns_cmp_unifiedfunction ns_cmp_ownerfunction __ns_tree_add_rawfunction __ns_tree_removefunction ns_findfunction ns_find_unifiedfunction __ns_tree_gen_idfunction __free_klistns_freefunction copy_ns_id_reqfunction prepare_klistnsfunction ns_requestedfunction may_list_nsfunction ns_putfunction legitimize_nsfunction do_listns_usernsfunction ns_common_is_headfunction do_listnsexport net_ns_treeexport __ns_tree_remove
Annotated Snippet
SYSCALL_DEFINE4(listns, const struct ns_id_req __user *, req,
u64 __user *, ns_ids, size_t, nr_ns_ids, unsigned int, flags)
{
struct klistns klns __free(klistns_free) = {};
const size_t maxcount = 1000000;
struct ns_id_req kreq;
ssize_t ret;
if (flags)
return -EINVAL;
if (unlikely(nr_ns_ids > maxcount))
return -EOVERFLOW;
if (!access_ok(ns_ids, nr_ns_ids * sizeof(*ns_ids)))
return -EFAULT;
ret = copy_ns_id_req(req, &kreq);
if (ret)
return ret;
ret = prepare_klistns(&klns, &kreq, ns_ids, nr_ns_ids);
if (ret)
return ret;
if (kreq.user_ns_id)
return do_listns_userns(&klns);
return do_listns(&klns);
}
Annotation
- Immediate include surface: `linux/nstree.h`, `linux/proc_ns.h`, `linux/rculist.h`, `linux/vfsdebug.h`, `linux/syscalls.h`, `linux/user_namespace.h`.
- Detected declarations: `syscall listns`, `struct klistns`, `function ns_tree_node_init`, `function ns_tree_root_init`, `function ns_tree_node_empty`, `function int`, `function ns_tree_node_del`, `function ns_id_cmp`, `function ns_cmp`, `function ns_cmp_unified`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core 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.