mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
tools/nolibc: add support for clock_nanosleep() and nanosleep()
Also add some tests. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/r/20250704-nolibc-nanosleep-v1-1-d79c19701952@linutronix.de Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
This commit is contained in:
committed by
Thomas Weißschuh
parent
1536aa0fb1
commit
7c02bc4088
@@ -36,6 +36,8 @@ void __nolibc_timespec_kernel_to_user(const struct __kernel_timespec *kts, struc
|
||||
* int clock_getres(clockid_t clockid, struct timespec *res);
|
||||
* int clock_gettime(clockid_t clockid, struct timespec *tp);
|
||||
* int clock_settime(clockid_t clockid, const struct timespec *tp);
|
||||
* int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,
|
||||
* struct timespec *rmtp)
|
||||
*/
|
||||
|
||||
static __attribute__((unused))
|
||||
@@ -107,6 +109,32 @@ int clock_settime(clockid_t clockid, struct timespec *tp)
|
||||
return __sysret(sys_clock_settime(clockid, tp));
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
int sys_clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,
|
||||
struct timespec *rmtp)
|
||||
{
|
||||
#if defined(__NR_clock_nanosleep)
|
||||
return my_syscall4(__NR_clock_nanosleep, clockid, flags, rqtp, rmtp);
|
||||
#elif defined(__NR_clock_nanosleep_time64)
|
||||
struct __kernel_timespec krqtp, krmtp;
|
||||
int ret;
|
||||
|
||||
__nolibc_timespec_user_to_kernel(rqtp, &krqtp);
|
||||
ret = my_syscall4(__NR_clock_nanosleep_time64, clockid, flags, &krqtp, &krmtp);
|
||||
if (rmtp)
|
||||
__nolibc_timespec_kernel_to_user(&krmtp, rmtp);
|
||||
return ret;
|
||||
#else
|
||||
return __nolibc_enosys(__func__, clockid, flags, rqtp, rmtp);
|
||||
#endif
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp,
|
||||
struct timespec *rmtp)
|
||||
{
|
||||
return __sysret(sys_clock_nanosleep(clockid, flags, rqtp, rmtp));
|
||||
}
|
||||
|
||||
static __inline__
|
||||
double difftime(time_t time1, time_t time2)
|
||||
@@ -114,6 +142,12 @@ double difftime(time_t time1, time_t time2)
|
||||
return time1 - time2;
|
||||
}
|
||||
|
||||
static __inline__
|
||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
return clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp);
|
||||
}
|
||||
|
||||
|
||||
static __attribute__((unused))
|
||||
time_t time(time_t *tptr)
|
||||
|
||||
@@ -1363,6 +1363,7 @@ int run_syscall(int min, int max)
|
||||
CASE_TEST(mmap_bad); EXPECT_PTRER(1, mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL); break;
|
||||
CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap(NULL, 0), -1, EINVAL); break;
|
||||
CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break;
|
||||
CASE_TEST(nanosleep); ts.tv_nsec = -1; EXPECT_SYSER(1, nanosleep(&ts, NULL), -1, EINVAL); break;
|
||||
CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", O_RDONLY), -1); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", O_RDONLY), -1, ENOENT); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break;
|
||||
|
||||
Reference in New Issue
Block a user