kernel/time/namespace.c
Source file repositories/reference/linux-study-clean/kernel/time/namespace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/namespace.c- Extension
.c- Size
- 7983 bytes
- Lines
- 361
- 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.
- 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/time_namespace.hlinux/user_namespace.hlinux/sched/signal.hlinux/sched/task.hlinux/clocksource.hlinux/seq_file.hlinux/proc_ns.hlinux/export.hlinux/nstree.hlinux/time.hlinux/slab.hlinux/cred.hlinux/err.hlinux/mm.hlinux/cleanup.hnamespace_internal.h
Detected Declarations
function do_timens_ktime_to_hostfunction dec_time_namespacesfunction free_time_nsfunction timens_putfunction timens_installfunction timens_on_forkfunction show_offsetfunction proc_timens_show_offsetsfunction proc_timens_set_offsetfunction time_ns_initexport do_timens_ktime_to_hostexport init_time_ns
Annotated Snippet
switch (off->clockid) {
case CLOCK_MONOTONIC:
ktime_get_ts64(&tp);
break;
case CLOCK_BOOTTIME:
ktime_get_boottime_ts64(&tp);
break;
default:
return -EINVAL;
}
if (off->val.tv_sec > KTIME_SEC_MAX ||
off->val.tv_sec < -KTIME_SEC_MAX)
return -ERANGE;
tp = timespec64_add(tp, off->val);
/*
* KTIME_SEC_MAX is divided by 2 to be sure that KTIME_MAX is
* still unreachable.
*/
if (tp.tv_sec < 0 || tp.tv_sec > KTIME_SEC_MAX / 2)
return -ERANGE;
}
guard(mutex)(&timens_offset_lock);
if (time_ns->frozen_offsets)
return -EACCES;
/* Don't report errors after this line */
for (i = 0; i < noffsets; i++) {
struct proc_timens_offset *off = &offsets[i];
struct timespec64 *offset = NULL;
switch (off->clockid) {
case CLOCK_MONOTONIC:
offset = &time_ns->offsets.monotonic;
break;
case CLOCK_BOOTTIME:
offset = &time_ns->offsets.boottime;
break;
}
*offset = off->val;
}
return 0;
}
const struct proc_ns_operations timens_operations = {
.name = "time",
.get = timens_get,
.put = timens_put,
.install = timens_install,
.owner = timens_owner,
};
const struct proc_ns_operations timens_for_children_operations = {
.name = "time_for_children",
.real_ns_name = "time",
.get = timens_for_children_get,
.put = timens_put,
.install = timens_install,
.owner = timens_owner,
};
struct time_namespace init_time_ns = {
.ns = NS_COMMON_INIT(init_time_ns),
.user_ns = &init_user_ns,
.frozen_offsets = true,
};
EXPORT_SYMBOL_GPL(init_time_ns);
void __init time_ns_init(void)
{
ns_tree_add(&init_time_ns);
}
Annotation
- Immediate include surface: `linux/time_namespace.h`, `linux/user_namespace.h`, `linux/sched/signal.h`, `linux/sched/task.h`, `linux/clocksource.h`, `linux/seq_file.h`, `linux/proc_ns.h`, `linux/export.h`.
- Detected declarations: `function do_timens_ktime_to_host`, `function dec_time_namespaces`, `function free_time_ns`, `function timens_put`, `function timens_install`, `function timens_on_fork`, `function show_offset`, `function proc_timens_show_offsets`, `function proc_timens_set_offset`, `function time_ns_init`.
- 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.
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.