2013-02-27 19:22:40 +08:00
|
|
|
//===-- sanitizer_linux.h ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Linux-specific syscall wrappers and classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_LINUX_H
|
|
|
|
#define SANITIZER_LINUX_H
|
|
|
|
|
2013-09-10 22:36:16 +08:00
|
|
|
#include "sanitizer_platform.h"
|
2014-03-04 16:55:41 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX
|
2013-04-05 15:41:21 +08:00
|
|
|
#include "sanitizer_common.h"
|
2013-02-27 19:22:40 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2013-10-15 20:57:59 +08:00
|
|
|
#include "sanitizer_platform_limits_posix.h"
|
2013-02-27 19:22:40 +08:00
|
|
|
|
2013-07-30 03:09:49 +08:00
|
|
|
struct link_map; // Opaque type returned by dlopen().
|
2013-02-27 19:22:40 +08:00
|
|
|
struct sigaltstack;
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
// Dirent structure for getdents(). Note that this structure is different from
|
|
|
|
// the one in <dirent.h>, which is used by readdir().
|
|
|
|
struct linux_dirent;
|
|
|
|
|
|
|
|
// Syscall wrappers.
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
|
|
|
|
uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
|
|
|
|
uptr internal_sigaltstack(const struct sigaltstack* ss,
|
|
|
|
struct sigaltstack* oss);
|
2014-01-31 19:29:51 +08:00
|
|
|
uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
|
|
|
|
__sanitizer_sigset_t *oldset);
|
|
|
|
void internal_sigfillset(__sanitizer_sigset_t *set);
|
|
|
|
void internal_sigdelset(__sanitizer_sigset_t *set, int signum);
|
|
|
|
// Used only by sanitizer_stoptheworld. Signal handlers that are actually used
|
|
|
|
// (like the process-wide error reporting SEGV handler) must use
|
|
|
|
// internal_sigaction instead.
|
|
|
|
int internal_sigaction_norestorer(int signum, const void *act, void *oldact);
|
2013-10-15 19:31:51 +08:00
|
|
|
|
2013-09-02 19:36:19 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
|
|
|
|
int *parent_tidptr, void *newtls, int *child_tidptr);
|
|
|
|
#endif
|
2013-02-27 19:22:40 +08:00
|
|
|
|
|
|
|
// This class reads thread IDs from /proc/<pid>/task using only syscalls.
|
|
|
|
class ThreadLister {
|
|
|
|
public:
|
|
|
|
explicit ThreadLister(int pid);
|
|
|
|
~ThreadLister();
|
|
|
|
// GetNextTID returns -1 if the list of threads is exhausted, or if there has
|
|
|
|
// been an error.
|
|
|
|
int GetNextTID();
|
|
|
|
void Reset();
|
|
|
|
bool error();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool GetDirectoryEntries();
|
|
|
|
|
|
|
|
int pid_;
|
|
|
|
int descriptor_;
|
2013-04-05 15:41:21 +08:00
|
|
|
InternalScopedBuffer<char> buffer_;
|
2013-02-27 19:22:40 +08:00
|
|
|
bool error_;
|
|
|
|
struct linux_dirent* entry_;
|
|
|
|
int bytes_read_;
|
|
|
|
};
|
2013-03-19 17:30:52 +08:00
|
|
|
|
2013-05-07 22:41:43 +08:00
|
|
|
// Exposed for testing.
|
|
|
|
uptr ThreadDescriptorSize();
|
2013-05-29 21:07:42 +08:00
|
|
|
uptr ThreadSelf();
|
|
|
|
uptr ThreadSelfOffset();
|
2013-05-07 22:41:43 +08:00
|
|
|
|
2013-05-14 21:24:46 +08:00
|
|
|
// Matches a library's file name against a base name (stripping path and version
|
|
|
|
// information).
|
|
|
|
bool LibraryNameIs(const char *full_name, const char *base_name);
|
|
|
|
|
2013-05-29 20:11:43 +08:00
|
|
|
// Read the name of the current binary from /proc/self/exe.
|
|
|
|
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
|
2013-09-10 22:36:16 +08:00
|
|
|
// Cache the value of /proc/self/exe.
|
|
|
|
void CacheBinaryName();
|
2013-05-29 20:11:43 +08:00
|
|
|
|
2013-07-30 03:09:49 +08:00
|
|
|
// Call cb for each region mapped by map.
|
|
|
|
void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
|
2013-02-27 19:22:40 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2014-03-04 16:55:41 +08:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
|
2013-02-27 19:22:40 +08:00
|
|
|
#endif // SANITIZER_LINUX_H
|