syms.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include <util/system/platform.h>
  2. #include <library/python/symbols/registry/syms.h>
  3. #if !defined(_MSC_VER)
  4. #if __has_include(<aio.h>)
  5. #include <aio.h>
  6. #endif
  7. #include <arpa/inet.h>
  8. #include <dirent.h>
  9. #include <ifaddrs.h>
  10. #include <netdb.h>
  11. #include <pthread.h>
  12. #include <pwd.h>
  13. #include <sched.h>
  14. #include <semaphore.h>
  15. #include <signal.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <time.h>
  20. #include <errno.h>
  21. #include <sys/ipc.h>
  22. #include <dlfcn.h>
  23. #if defined(_linux_)
  24. #include <sys/prctl.h>
  25. #include <sys/ptrace.h>
  26. #include <sys/sendfile.h>
  27. #else
  28. #include <sys/types.h>
  29. #include <sys/socket.h>
  30. #include <sys/uio.h>
  31. #endif
  32. #if defined(_darwin_)
  33. #include <sys/types.h>
  34. #include <sys/sysctl.h>
  35. #include <mach/mach_error.h> // Y_IGNORE
  36. #include <mach/mach_time.h> // Y_IGNORE
  37. #endif
  38. #if defined(_linux_)
  39. #include <sys/inotify.h>
  40. #include <sys/mman.h>
  41. #endif
  42. namespace {
  43. static inline void* ErrnoLocation() {
  44. return &errno;
  45. }
  46. static int ClockGetres(clockid_t clk_id, struct timespec* res) {
  47. #if defined(_darwin_)
  48. static auto func = (decltype(&ClockGetres))dlsym(RTLD_SELF, "_clock_getres");
  49. if (func) {
  50. return func(clk_id, res);
  51. }
  52. // https://opensource.apple.com/source/Libc/Libc-1158.1.2/gen/clock_gettime.c.auto.html
  53. switch (clk_id){
  54. case CLOCK_REALTIME:
  55. case CLOCK_MONOTONIC:
  56. case CLOCK_PROCESS_CPUTIME_ID:
  57. res->tv_nsec = NSEC_PER_USEC;
  58. res->tv_sec = 0;
  59. return 0;
  60. case CLOCK_MONOTONIC_RAW:
  61. case CLOCK_MONOTONIC_RAW_APPROX:
  62. case CLOCK_UPTIME_RAW:
  63. case CLOCK_UPTIME_RAW_APPROX:
  64. case CLOCK_THREAD_CPUTIME_ID: {
  65. mach_timebase_info_data_t tb_info;
  66. if (mach_timebase_info(&tb_info)) {
  67. return -1;
  68. }
  69. res->tv_nsec = tb_info.numer / tb_info.denom + (tb_info.numer % tb_info.denom != 0);
  70. res->tv_sec = 0;
  71. return 0;
  72. }
  73. default:
  74. errno = EINVAL;
  75. return -1;
  76. }
  77. #else
  78. return clock_getres(clk_id, res);
  79. #endif
  80. }
  81. }
  82. BEGIN_SYMS("c")
  83. SYM(calloc)
  84. SYM(clock_gettime)
  85. SYM_2("clock_getres", ClockGetres)
  86. SYM(closedir)
  87. SYM(fdopen)
  88. SYM(fflush)
  89. SYM(freeifaddrs)
  90. SYM(ftok)
  91. SYM(getifaddrs)
  92. SYM(getnameinfo)
  93. SYM(getpwnam)
  94. SYM(inet_ntop)
  95. SYM(opendir)
  96. SYM(printf)
  97. SYM(pthread_kill)
  98. SYM(pthread_self)
  99. SYM(readdir_r)
  100. SYM(sem_close)
  101. SYM(sem_getvalue)
  102. SYM(sem_open)
  103. SYM(sem_post)
  104. SYM(sem_trywait)
  105. SYM(sem_unlink)
  106. SYM(sem_wait)
  107. SYM(siginterrupt)
  108. SYM(strdup)
  109. SYM(sendfile)
  110. SYM(strtod)
  111. SYM_2("__errno_location", ErrnoLocation)
  112. #if defined(_linux_)
  113. SYM(prctl)
  114. SYM(ptrace)
  115. SYM(sched_getaffinity)
  116. SYM(sched_setaffinity)
  117. SYM(sem_timedwait)
  118. SYM(inotify_init)
  119. SYM(inotify_add_watch)
  120. SYM(inotify_rm_watch)
  121. SYM(mlockall)
  122. #endif
  123. #if defined(_darwin_)
  124. SYM(mach_absolute_time)
  125. SYM(mach_timebase_info)
  126. SYM(sysctlbyname)
  127. #endif
  128. #if __has_include(<aio.h>)
  129. SYM(aio_error)
  130. SYM(aio_read)
  131. SYM(aio_return)
  132. SYM(aio_suspend)
  133. #endif
  134. END_SYMS()
  135. #endif