sanitizer_linux.h revision cb339108cca40fb4c1ed520656cb6cb75889a237
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===-- sanitizer_linux.h ---------------------------------------*- C++ -*-===// 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The LLVM Compiler Infrastructure 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// License. See LICENSE.TXT for details. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===----------------------------------------------------------------------===// 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Linux-specific syscall wrappers and classes. 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//===----------------------------------------------------------------------===// 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef SANITIZER_LINUX_H 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define SANITIZER_LINUX_H 150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "sanitizer_common.h" 170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "sanitizer_internal_defs.h" 180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct link_map; // Opaque type returned by dlopen(). 200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct sigaltstack; 210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace __sanitizer { 230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Dirent structure for getdents(). Note that this structure is different from 240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// the one in <dirent.h>, which is used by readdir(). 250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct linux_dirent; 260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Syscall wrappers. 280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochuptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count); 290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochuptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5); 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochuptr internal_sigaltstack(const struct sigaltstack* ss, 310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch struct sigaltstack* oss); 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifdef __x86_64__ 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int *parent_tidptr, void *newtls, int *child_tidptr); 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This class reads thread IDs from /proc/<pid>/task using only syscalls. 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass ThreadLister { 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 40 explicit ThreadLister(int pid); 41 ~ThreadLister(); 42 // GetNextTID returns -1 if the list of threads is exhausted, or if there has 43 // been an error. 44 int GetNextTID(); 45 void Reset(); 46 bool error(); 47 48 private: 49 bool GetDirectoryEntries(); 50 51 int pid_; 52 int descriptor_; 53 InternalScopedBuffer<char> buffer_; 54 bool error_; 55 struct linux_dirent* entry_; 56 int bytes_read_; 57}; 58 59void AdjustStackSizeLinux(void *attr, int verbosity); 60 61// Exposed for testing. 62uptr ThreadDescriptorSize(); 63uptr ThreadSelf(); 64uptr ThreadSelfOffset(); 65 66// Matches a library's file name against a base name (stripping path and version 67// information). 68bool LibraryNameIs(const char *full_name, const char *base_name); 69 70// Read the name of the current binary from /proc/self/exe. 71uptr ReadBinaryName(/*out*/char *buf, uptr buf_len); 72 73// Call cb for each region mapped by map. 74void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr)); 75 76} // namespace __sanitizer 77 78#endif // SANITIZER_LINUX_H 79