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