posix-stubs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Dummy stubs used when CONFIG_POSIX_TIMERS=n
  3. *
  4. * Created by: Nicolas Pitre, July 2016
  5. * Copyright: (C) 2016 Linaro Limited
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/linkage.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/errno.h>
  15. #include <linux/syscalls.h>
  16. #include <linux/ktime.h>
  17. #include <linux/timekeeping.h>
  18. #include <linux/posix-timers.h>
  19. asmlinkage long sys_ni_posix_timers(void)
  20. {
  21. pr_err_once("process %d (%s) attempted a POSIX timer syscall "
  22. "while CONFIG_POSIX_TIMERS is not set\n",
  23. current->pid, current->comm);
  24. return -ENOSYS;
  25. }
  26. #define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
  27. SYS_NI(timer_create);
  28. SYS_NI(timer_gettime);
  29. SYS_NI(timer_getoverrun);
  30. SYS_NI(timer_settime);
  31. SYS_NI(timer_delete);
  32. SYS_NI(clock_adjtime);
  33. SYS_NI(getitimer);
  34. SYS_NI(setitimer);
  35. #ifdef __ARCH_WANT_SYS_ALARM
  36. SYS_NI(alarm);
  37. #endif
  38. /*
  39. * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
  40. * as it is easy to remain compatible with little code. CLOCK_BOOTTIME
  41. * is also included for convenience as at least systemd uses it.
  42. */
  43. SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
  44. const struct timespec __user *, tp)
  45. {
  46. struct timespec64 new_tp64;
  47. struct timespec new_tp;
  48. if (which_clock != CLOCK_REALTIME)
  49. return -EINVAL;
  50. if (copy_from_user(&new_tp, tp, sizeof (*tp)))
  51. return -EFAULT;
  52. new_tp64 = timespec_to_timespec64(new_tp);
  53. return do_sys_settimeofday64(&new_tp64, NULL);
  54. }
  55. SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
  56. struct timespec __user *,tp)
  57. {
  58. struct timespec64 kernel_tp64;
  59. struct timespec kernel_tp;
  60. switch (which_clock) {
  61. case CLOCK_REALTIME: ktime_get_real_ts64(&kernel_tp64); break;
  62. case CLOCK_MONOTONIC: ktime_get_ts64(&kernel_tp64); break;
  63. case CLOCK_BOOTTIME: get_monotonic_boottime64(&kernel_tp64); break;
  64. default: return -EINVAL;
  65. }
  66. kernel_tp = timespec64_to_timespec(kernel_tp64);
  67. if (copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
  68. return -EFAULT;
  69. return 0;
  70. }
  71. SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp)
  72. {
  73. struct timespec rtn_tp = {
  74. .tv_sec = 0,
  75. .tv_nsec = hrtimer_resolution,
  76. };
  77. switch (which_clock) {
  78. case CLOCK_REALTIME:
  79. case CLOCK_MONOTONIC:
  80. case CLOCK_BOOTTIME:
  81. if (copy_to_user(tp, &rtn_tp, sizeof(rtn_tp)))
  82. return -EFAULT;
  83. return 0;
  84. default:
  85. return -EINVAL;
  86. }
  87. }
  88. SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
  89. const struct timespec __user *, rqtp,
  90. struct timespec __user *, rmtp)
  91. {
  92. struct timespec t;
  93. switch (which_clock) {
  94. case CLOCK_REALTIME:
  95. case CLOCK_MONOTONIC:
  96. case CLOCK_BOOTTIME:
  97. if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
  98. return -EFAULT;
  99. if (!timespec_valid(&t))
  100. return -EINVAL;
  101. return hrtimer_nanosleep(&t, rmtp, flags & TIMER_ABSTIME ?
  102. HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
  103. which_clock);
  104. default:
  105. return -EINVAL;
  106. }
  107. }
  108. #ifdef CONFIG_COMPAT
  109. long clock_nanosleep_restart(struct restart_block *restart_block)
  110. {
  111. return hrtimer_nanosleep_restart(restart_block);
  112. }
  113. #endif