sanitizer_linux.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //===-- sanitizer_linux.h ---------------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // Linux-specific syscall wrappers and classes.
  9. //
  10. //===----------------------------------------------------------------------===//
  11. #ifndef SANITIZER_LINUX_H
  12. #define SANITIZER_LINUX_H
  13. #include "sanitizer_platform.h"
  14. #if SANITIZER_FREEBSD || SANITIZER_LINUX
  15. #include "sanitizer_common.h"
  16. #include "sanitizer_internal_defs.h"
  17. #include "sanitizer_platform_limits_posix.h"
  18. struct link_map; // Opaque type returned by dlopen().
  19. struct sigaltstack;
  20. namespace __sanitizer {
  21. // Dirent structure for getdents(). Note that this structure is different from
  22. // the one in <dirent.h>, which is used by readdir().
  23. struct linux_dirent;
  24. // Syscall wrappers.
  25. uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
  26. uptr internal_sigaltstack(const struct sigaltstack* ss,
  27. struct sigaltstack* oss);
  28. uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
  29. __sanitizer_sigset_t *oldset);
  30. void internal_sigfillset(__sanitizer_sigset_t *set);
  31. // Linux-only syscalls.
  32. #if SANITIZER_LINUX
  33. uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
  34. // Used only by sanitizer_stoptheworld. Signal handlers that are actually used
  35. // (like the process-wide error reporting SEGV handler) must use
  36. // internal_sigaction instead.
  37. int internal_sigaction_norestorer(int signum, const void *act, void *oldact);
  38. void internal_sigdelset(__sanitizer_sigset_t *set, int signum);
  39. #if defined(__x86_64__)
  40. uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
  41. int *parent_tidptr, void *newtls, int *child_tidptr);
  42. #endif
  43. #endif // SANITIZER_LINUX
  44. // This class reads thread IDs from /proc/<pid>/task using only syscalls.
  45. class ThreadLister {
  46. public:
  47. explicit ThreadLister(int pid);
  48. ~ThreadLister();
  49. // GetNextTID returns -1 if the list of threads is exhausted, or if there has
  50. // been an error.
  51. int GetNextTID();
  52. void Reset();
  53. bool error();
  54. private:
  55. bool GetDirectoryEntries();
  56. int pid_;
  57. int descriptor_;
  58. InternalScopedBuffer<char> buffer_;
  59. bool error_;
  60. struct linux_dirent* entry_;
  61. int bytes_read_;
  62. };
  63. // Exposed for testing.
  64. uptr ThreadDescriptorSize();
  65. uptr ThreadSelf();
  66. uptr ThreadSelfOffset();
  67. // Matches a library's file name against a base name (stripping path and version
  68. // information).
  69. bool LibraryNameIs(const char *full_name, const char *base_name);
  70. // Read the name of the current binary from /proc/self/exe.
  71. uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
  72. // Cache the value of /proc/self/exe.
  73. void CacheBinaryName();
  74. // Call cb for each region mapped by map.
  75. void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
  76. } // namespace __sanitizer
  77. #endif // SANITIZER_FREEBSD || SANITIZER_LINUX
  78. #endif // SANITIZER_LINUX_H