posix-stubs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 timespec new_tp;
  47. if (which_clock != CLOCK_REALTIME)
  48. return -EINVAL;
  49. if (copy_from_user(&new_tp, tp, sizeof (*tp)))
  50. return -EFAULT;
  51. return do_sys_settimeofday(&new_tp, NULL);
  52. }
  53. SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
  54. struct timespec __user *,tp)
  55. {
  56. struct timespec kernel_tp;
  57. switch (which_clock) {
  58. case CLOCK_REALTIME: ktime_get_real_ts(&kernel_tp); break;
  59. case CLOCK_MONOTONIC: ktime_get_ts(&kernel_tp); break;
  60. case CLOCK_BOOTTIME: get_monotonic_boottime(&kernel_tp); break;
  61. default: return -EINVAL;
  62. }
  63. if (copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
  64. return -EFAULT;
  65. return 0;
  66. }
  67. SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp)
  68. {
  69. struct timespec rtn_tp = {
  70. .tv_sec = 0,
  71. .tv_nsec = hrtimer_resolution,
  72. };
  73. switch (which_clock) {
  74. case CLOCK_REALTIME:
  75. case CLOCK_MONOTONIC:
  76. case CLOCK_BOOTTIME:
  77. if (copy_to_user(tp, &rtn_tp, sizeof(rtn_tp)))
  78. return -EFAULT;
  79. return 0;
  80. default:
  81. return -EINVAL;
  82. }
  83. }
  84. SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
  85. const struct timespec __user *, rqtp,
  86. struct timespec __user *, rmtp)
  87. {
  88. struct timespec t;
  89. switch (which_clock) {
  90. case CLOCK_REALTIME:
  91. case CLOCK_MONOTONIC:
  92. case CLOCK_BOOTTIME:
  93. if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
  94. return -EFAULT;
  95. if (!timespec_valid(&t))
  96. return -EINVAL;
  97. return hrtimer_nanosleep(&t, rmtp, flags & TIMER_ABSTIME ?
  98. HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
  99. which_clock);
  100. default:
  101. return -EINVAL;
  102. }
  103. }
  104. #ifdef CONFIG_COMPAT
  105. long clock_nanosleep_restart(struct restart_block *restart_block)
  106. {
  107. return hrtimer_nanosleep_restart(restart_block);
  108. }
  109. #endif