Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ptp.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2014 Stefan Sørensen <stefan.sorensen@spectralink.com>
  3. * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
  4. * Copyright (c) 2014-2019 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #ifdef HAVE_STRUCT_PTP_SYS_OFFSET
  11. # include "print_fields.h"
  12. # include <linux/ioctl.h>
  13. # include <linux/ptp_clock.h>
  14. # ifndef PTP_CLOCK_GETCAPS2
  15. # define PTP_CLOCK_GETCAPS2 _IOR(PTP_CLK_MAGIC, 10, struct ptp_clock_caps)
  16. # endif
  17. # ifndef PTP_EXTTS_REQUEST2
  18. # define PTP_EXTTS_REQUEST2 _IOW(PTP_CLK_MAGIC, 11, struct ptp_extts_request)
  19. # endif
  20. # ifndef PTP_PEROUT_REQUEST2
  21. # define PTP_PEROUT_REQUEST2 _IOW(PTP_CLK_MAGIC, 12, struct ptp_perout_request)
  22. # endif
  23. # ifndef PTP_ENABLE_PPS2
  24. # define PTP_ENABLE_PPS2 _IOW(PTP_CLK_MAGIC, 13, int)
  25. # endif
  26. # ifndef PTP_SYS_OFFSET2
  27. # define PTP_SYS_OFFSET2 _IOW(PTP_CLK_MAGIC, 14, struct ptp_sys_offset)
  28. # endif
  29. # include "xlat/ptp_extts_flags.h"
  30. # include "xlat/ptp_perout_flags.h"
  31. int
  32. ptp_ioctl(struct tcb *const tcp, const unsigned int code,
  33. const kernel_ulong_t arg)
  34. {
  35. if (!verbose(tcp))
  36. return RVAL_DECODED;
  37. switch (code) {
  38. case PTP_EXTTS_REQUEST:
  39. case PTP_EXTTS_REQUEST2: {
  40. struct ptp_extts_request extts;
  41. tprints(", ");
  42. if (umove_or_printaddr(tcp, arg, &extts))
  43. break;
  44. PRINT_FIELD_D("{", extts, index);
  45. PRINT_FIELD_FLAGS(", ", extts, flags, ptp_extts_flags, "PTP_???");
  46. tprints("}");
  47. break;
  48. }
  49. case PTP_PEROUT_REQUEST:
  50. case PTP_PEROUT_REQUEST2: {
  51. struct ptp_perout_request perout;
  52. tprints(", ");
  53. if (umove_or_printaddr(tcp, arg, &perout))
  54. break;
  55. PRINT_FIELD_D("{start={", perout.start, sec);
  56. PRINT_FIELD_U(", ", perout.start, nsec);
  57. PRINT_FIELD_D("}, period={", perout.period, sec);
  58. PRINT_FIELD_U(", ", perout.period, nsec);
  59. PRINT_FIELD_D("}, ", perout, index);
  60. PRINT_FIELD_FLAGS(", ", perout, flags, ptp_perout_flags, "PTP_???");
  61. tprints("}");
  62. break;
  63. }
  64. case PTP_ENABLE_PPS:
  65. case PTP_ENABLE_PPS2:
  66. tprintf(", %" PRI_kld, arg);
  67. break;
  68. case PTP_SYS_OFFSET:
  69. case PTP_SYS_OFFSET2: {
  70. struct ptp_sys_offset sysoff;
  71. if (entering(tcp)) {
  72. tprints(", ");
  73. if (umove_or_printaddr(tcp, arg, &sysoff))
  74. break;
  75. PRINT_FIELD_U("{", sysoff, n_samples);
  76. return 0;
  77. } else {
  78. unsigned int n_samples, i;
  79. if (syserror(tcp)) {
  80. tprints("}");
  81. break;
  82. }
  83. tprints(", ");
  84. if (umove(tcp, arg, &sysoff) < 0) {
  85. tprints("???}");
  86. break;
  87. }
  88. tprints("ts=[");
  89. n_samples = sysoff.n_samples > PTP_MAX_SAMPLES ?
  90. PTP_MAX_SAMPLES : sysoff.n_samples;
  91. for (i = 0; i < 2 * n_samples + 1; ++i) {
  92. if (i > 0)
  93. tprints(", ");
  94. PRINT_FIELD_D("{", sysoff.ts[i], sec);
  95. PRINT_FIELD_U(", ", sysoff.ts[i], nsec);
  96. tprints("}");
  97. }
  98. if (sysoff.n_samples > PTP_MAX_SAMPLES)
  99. tprints(", ...");
  100. tprints("]}");
  101. break;
  102. }
  103. }
  104. case PTP_CLOCK_GETCAPS:
  105. case PTP_CLOCK_GETCAPS2: {
  106. struct ptp_clock_caps caps;
  107. if (entering(tcp))
  108. return 0;
  109. tprints(", ");
  110. if (umove_or_printaddr(tcp, arg, &caps))
  111. break;
  112. PRINT_FIELD_D("{", caps, max_adj);
  113. PRINT_FIELD_D(", ", caps, n_alarm);
  114. PRINT_FIELD_D(", ", caps, n_ext_ts);
  115. PRINT_FIELD_D(", ", caps, n_per_out);
  116. PRINT_FIELD_D(", ", caps, pps);
  117. tprints("}");
  118. break;
  119. }
  120. default:
  121. return RVAL_DECODED;
  122. }
  123. return RVAL_IOCTL_DECODED;
  124. }
  125. #endif /* HAVE_STRUCT_PTP_SYS_OFFSET */