clock_adjtime.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include <sys/timex.h>
  2. #include <time.h>
  3. #include <errno.h>
  4. #include "syscall.h"
  5. #define IS32BIT(x) !((x)+0x80000000ULL>>32)
  6. struct ktimex64 {
  7. unsigned modes;
  8. int :32;
  9. long long offset, freq, maxerror, esterror;
  10. int status;
  11. int :32;
  12. long long constant, precision, tolerance;
  13. long long time_sec, time_usec;
  14. long long tick, ppsfreq, jitter;
  15. int shift;
  16. int :32;
  17. long long stabil, jitcnt, calcnt, errcnt, stbcnt;
  18. int tai;
  19. int __padding[11];
  20. };
  21. struct ktimex {
  22. unsigned modes;
  23. long offset, freq, maxerror, esterror;
  24. int status;
  25. long constant, precision, tolerance;
  26. long time_sec, time_usec;
  27. long tick, ppsfreq, jitter;
  28. int shift;
  29. long stabil, jitcnt, calcnt, errcnt, stbcnt;
  30. int tai;
  31. int __padding[11];
  32. };
  33. int clock_adjtime (clockid_t clock_id, struct timex *utx)
  34. {
  35. int r = -ENOSYS;
  36. #ifdef SYS_clock_adjtime64
  37. struct ktimex64 ktx = {
  38. .modes = utx->modes,
  39. .offset = utx->offset,
  40. .freq = utx->freq,
  41. .maxerror = utx->maxerror,
  42. .esterror = utx->esterror,
  43. .status = utx->status,
  44. .constant = utx->constant,
  45. .precision = utx->precision,
  46. .tolerance = utx->tolerance,
  47. .time_sec = utx->time.tv_sec,
  48. .time_usec = utx->time.tv_usec,
  49. .tick = utx->tick,
  50. .ppsfreq = utx->ppsfreq,
  51. .jitter = utx->jitter,
  52. .shift = utx->shift,
  53. .stabil = utx->stabil,
  54. .jitcnt = utx->jitcnt,
  55. .calcnt = utx->calcnt,
  56. .errcnt = utx->errcnt,
  57. .stbcnt = utx->stbcnt,
  58. .tai = utx->tai,
  59. };
  60. r = __syscall(SYS_clock_adjtime64, clock_id, &ktx);
  61. if (r>=0) {
  62. utx->modes = ktx.modes;
  63. utx->offset = ktx.offset;
  64. utx->freq = ktx.freq;
  65. utx->maxerror = ktx.maxerror;
  66. utx->esterror = ktx.esterror;
  67. utx->status = ktx.status;
  68. utx->constant = ktx.constant;
  69. utx->precision = ktx.precision;
  70. utx->tolerance = ktx.tolerance;
  71. utx->time.tv_sec = ktx.time_sec;
  72. utx->time.tv_usec = ktx.time_usec;
  73. utx->tick = ktx.tick;
  74. utx->ppsfreq = ktx.ppsfreq;
  75. utx->jitter = ktx.jitter;
  76. utx->shift = ktx.shift;
  77. utx->stabil = ktx.stabil;
  78. utx->jitcnt = ktx.jitcnt;
  79. utx->calcnt = ktx.calcnt;
  80. utx->errcnt = ktx.errcnt;
  81. utx->stbcnt = ktx.stbcnt;
  82. utx->tai = ktx.tai;
  83. }
  84. if (SYS_clock_adjtime == SYS_clock_adjtime64 || r!=-ENOSYS)
  85. return __syscall_ret(r);
  86. if ((utx->modes & ADJ_SETOFFSET) && !IS32BIT(utx->time.tv_sec))
  87. return __syscall_ret(-ENOTSUP);
  88. #endif
  89. if (sizeof(time_t) > sizeof(long)) {
  90. struct ktimex ktx = {
  91. .modes = utx->modes,
  92. .offset = utx->offset,
  93. .freq = utx->freq,
  94. .maxerror = utx->maxerror,
  95. .esterror = utx->esterror,
  96. .status = utx->status,
  97. .constant = utx->constant,
  98. .precision = utx->precision,
  99. .tolerance = utx->tolerance,
  100. .time_sec = utx->time.tv_sec,
  101. .time_usec = utx->time.tv_usec,
  102. .tick = utx->tick,
  103. .ppsfreq = utx->ppsfreq,
  104. .jitter = utx->jitter,
  105. .shift = utx->shift,
  106. .stabil = utx->stabil,
  107. .jitcnt = utx->jitcnt,
  108. .calcnt = utx->calcnt,
  109. .errcnt = utx->errcnt,
  110. .stbcnt = utx->stbcnt,
  111. .tai = utx->tai,
  112. };
  113. #ifdef SYS_adjtimex
  114. if (clock_id==CLOCK_REALTIME) r = __syscall(SYS_adjtimex, &ktx);
  115. else
  116. #endif
  117. r = __syscall(SYS_clock_adjtime, clock_id, &ktx);
  118. if (r>=0) {
  119. utx->modes = ktx.modes;
  120. utx->offset = ktx.offset;
  121. utx->freq = ktx.freq;
  122. utx->maxerror = ktx.maxerror;
  123. utx->esterror = ktx.esterror;
  124. utx->status = ktx.status;
  125. utx->constant = ktx.constant;
  126. utx->precision = ktx.precision;
  127. utx->tolerance = ktx.tolerance;
  128. utx->time.tv_sec = ktx.time_sec;
  129. utx->time.tv_usec = ktx.time_usec;
  130. utx->tick = ktx.tick;
  131. utx->ppsfreq = ktx.ppsfreq;
  132. utx->jitter = ktx.jitter;
  133. utx->shift = ktx.shift;
  134. utx->stabil = ktx.stabil;
  135. utx->jitcnt = ktx.jitcnt;
  136. utx->calcnt = ktx.calcnt;
  137. utx->errcnt = ktx.errcnt;
  138. utx->stbcnt = ktx.stbcnt;
  139. utx->tai = ktx.tai;
  140. }
  141. return __syscall_ret(r);
  142. }
  143. #ifdef SYS_adjtimex
  144. if (clock_id==CLOCK_REALTIME) return syscall(SYS_adjtimex, utx);
  145. #endif
  146. return syscall(SYS_clock_adjtime, clock_id, utx);
  147. }