Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2/*
3 * timerfd definitions for NOLIBC
4 * Copyright (C) 2025 Thomas Weißschuh <thomas.weissschuh@linutronix.de>
5 */
6
7/* make sure to include all global symbols */
8#include "../nolibc.h"
9
10#ifndef _NOLIBC_SYS_TIMERFD_H
11#define _NOLIBC_SYS_TIMERFD_H
12
13#include "../sys.h"
14#include "../time.h"
15
16#include <linux/timerfd.h>
17
18
19static __attribute__((unused))
20int sys_timerfd_create(int clockid, int flags)
21{
22 return my_syscall2(__NR_timerfd_create, clockid, flags);
23}
24
25static __attribute__((unused))
26int timerfd_create(int clockid, int flags)
27{
28 return __sysret(sys_timerfd_create(clockid, flags));
29}
30
31
32static __attribute__((unused))
33int sys_timerfd_gettime(int fd, struct itimerspec *curr_value)
34{
35#if defined(__NR_timerfd_gettime)
36 return my_syscall2(__NR_timerfd_gettime, fd, curr_value);
37#elif defined(__NR_timerfd_gettime64)
38 struct __kernel_itimerspec kcurr_value;
39 int ret;
40
41 ret = my_syscall2(__NR_timerfd_gettime64, fd, &kcurr_value);
42 __nolibc_timespec_kernel_to_user(&kcurr_value.it_interval, &curr_value->it_interval);
43 __nolibc_timespec_kernel_to_user(&kcurr_value.it_value, &curr_value->it_value);
44 return ret;
45#else
46 return __nolibc_enosys(__func__, fd, curr_value);
47#endif
48}
49
50static __attribute__((unused))
51int timerfd_gettime(int fd, struct itimerspec *curr_value)
52{
53 return __sysret(sys_timerfd_gettime(fd, curr_value));
54}
55
56
57static __attribute__((unused))
58int sys_timerfd_settime(int fd, int flags,
59 const struct itimerspec *new_value, struct itimerspec *old_value)
60{
61#if defined(__NR_timerfd_settime)
62 return my_syscall4(__NR_timerfd_settime, fd, flags, new_value, old_value);
63#elif defined(__NR_timerfd_settime64)
64 struct __kernel_itimerspec knew_value, kold_value;
65 int ret;
66
67 __nolibc_timespec_user_to_kernel(&new_value->it_value, &knew_value.it_value);
68 __nolibc_timespec_user_to_kernel(&new_value->it_interval, &knew_value.it_interval);
69 ret = my_syscall4(__NR_timerfd_settime64, fd, flags, &knew_value, &kold_value);
70 if (old_value) {
71 __nolibc_timespec_kernel_to_user(&kold_value.it_interval, &old_value->it_interval);
72 __nolibc_timespec_kernel_to_user(&kold_value.it_value, &old_value->it_value);
73 }
74 return ret;
75#else
76 return __nolibc_enosys(__func__, fd, flags, new_value, old_value);
77#endif
78}
79
80static __attribute__((unused))
81int timerfd_settime(int fd, int flags,
82 const struct itimerspec *new_value, struct itimerspec *old_value)
83{
84 return __sysret(sys_timerfd_settime(fd, flags, new_value, old_value));
85}
86
87#endif /* _NOLIBC_SYS_TIMERFD_H */