kernel/time/time.c
Source file repositories/reference/linux-study-clean/kernel/time/time.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/time.c- Extension
.c- Size
- 27269 bytes
- Lines
- 1053
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/kernel.hlinux/timex.hlinux/capability.hlinux/timekeeper_internal.hlinux/errno.hlinux/syscalls.hlinux/security.hlinux/fs.hlinux/math64.hlinux/ptrace.hlinux/uaccess.hlinux/compat.hasm/unistd.hgenerated/timeconst.htimekeeping.h
Detected Declarations
syscall timesyscall stimesyscall time32syscall stime32syscall gettimeofdaysyscall settimeofdaysyscall adjtimexsyscall adjtimex_time32function sys_timefunction sys_stimefunction do_sys_settimeofday64function get_old_timex32function put_old_timex32function jiffies_to_msecsfunction jiffies_to_usecsfunction Gaussfunction ns_to_kernel_old_timevalfunction set_normalized_timespec64function ns_to_timespec64function _msecs_to_jiffiesfunction __usecs_to_jiffiesfunction timespec64_to_jiffiesfunction jiffies_to_timespec64function jiffies_to_clock_tfunction clock_t_to_jiffiesfunction jiffies_64_to_clock_tfunction nsec_to_clock_tfunction jiffies64_to_nsecsfunction jiffies64_to_msecsfunction nsecs_to_jiffies64function nsecs_to_jiffiesfunction timespec64_add_safefunction get_timespec64function put_timespec64function __get_old_timespec32function __put_old_timespec32function get_old_timespec32function put_old_timespec32function get_itimerspec64function put_itimerspec64function get_old_itimerspec32function put_old_itimerspec32export sys_tzexport jiffies_to_msecsexport jiffies_to_usecsexport mktime64export ns_to_kernel_old_timevalexport set_normalized_timespec64
Annotated Snippet
SYSCALL_DEFINE1(time, __kernel_old_time_t __user *, tloc)
{
__kernel_old_time_t i = (__kernel_old_time_t)ktime_get_real_seconds();
if (tloc) {
if (put_user(i,tloc))
return -EFAULT;
}
force_successful_syscall_return();
return i;
}
/*
* sys_stime() can be implemented in user-level using
* sys_settimeofday(). Is this for backwards compatibility? If so,
* why not move it into the appropriate arch directory (for those
* architectures that need it).
*/
SYSCALL_DEFINE1(stime, __kernel_old_time_t __user *, tptr)
{
struct timespec64 tv;
int err;
if (get_user(tv.tv_sec, tptr))
return -EFAULT;
tv.tv_nsec = 0;
err = security_settime64(&tv, NULL);
if (err)
return err;
do_settimeofday64(&tv);
return 0;
}
#endif /* __ARCH_WANT_SYS_TIME */
#ifdef CONFIG_COMPAT_32BIT_TIME
#ifdef __ARCH_WANT_SYS_TIME32
/* old_time32_t is a 32 bit "long" and needs to get converted. */
SYSCALL_DEFINE1(time32, old_time32_t __user *, tloc)
{
old_time32_t i;
i = (old_time32_t)ktime_get_real_seconds();
if (tloc) {
if (put_user(i,tloc))
return -EFAULT;
}
force_successful_syscall_return();
return i;
}
SYSCALL_DEFINE1(stime32, old_time32_t __user *, tptr)
{
struct timespec64 tv;
int err;
if (get_user(tv.tv_sec, tptr))
return -EFAULT;
tv.tv_nsec = 0;
err = security_settime64(&tv, NULL);
if (err)
return err;
do_settimeofday64(&tv);
return 0;
}
#endif /* __ARCH_WANT_SYS_TIME32 */
#endif
SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
struct timezone __user *, tz)
{
if (likely(tv != NULL)) {
struct timespec64 ts;
ktime_get_real_ts64(&ts);
if (put_user(ts.tv_sec, &tv->tv_sec) ||
put_user(ts.tv_nsec / 1000, &tv->tv_usec))
return -EFAULT;
}
if (unlikely(tz != NULL)) {
Annotation
- Immediate include surface: `linux/export.h`, `linux/kernel.h`, `linux/timex.h`, `linux/capability.h`, `linux/timekeeper_internal.h`, `linux/errno.h`, `linux/syscalls.h`, `linux/security.h`.
- Detected declarations: `syscall time`, `syscall stime`, `syscall time32`, `syscall stime32`, `syscall gettimeofday`, `syscall settimeofday`, `syscall adjtimex`, `syscall adjtimex_time32`, `function sys_time`, `function sys_stime`.
- 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.
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.