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.

Dependency Surface

Detected Declarations

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

Implementation Notes