blob: 6992575732bc1840c415b7d996996ce3b5bf60d4 [file] [log] [blame]
Kostya Serebryany6fb47af2013-02-27 11:22:40 +00001//===-- 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
Alexey Samsonov10f3ab72013-04-05 07:41:21 +000016#include "sanitizer_common.h"
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000017#include "sanitizer_internal_defs.h"
18
19struct sigaltstack;
20
21namespace __sanitizer {
22// Dirent structure for getdents(). Note that this structure is different from
23// the one in <dirent.h>, which is used by readdir().
24struct linux_dirent;
25
26// Syscall wrappers.
Peter Collingbourne9578a3e2013-05-08 14:43:49 +000027uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
28uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
29uptr internal_sigaltstack(const struct sigaltstack* ss,
30 struct sigaltstack* oss);
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000031
32// This class reads thread IDs from /proc/<pid>/task using only syscalls.
33class ThreadLister {
34 public:
35 explicit ThreadLister(int pid);
36 ~ThreadLister();
37 // GetNextTID returns -1 if the list of threads is exhausted, or if there has
38 // been an error.
39 int GetNextTID();
40 void Reset();
41 bool error();
42
43 private:
44 bool GetDirectoryEntries();
45
46 int pid_;
47 int descriptor_;
Alexey Samsonov10f3ab72013-04-05 07:41:21 +000048 InternalScopedBuffer<char> buffer_;
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000049 bool error_;
50 struct linux_dirent* entry_;
51 int bytes_read_;
52};
Evgeniy Stepanovb9bf7002013-03-19 09:30:52 +000053
54void AdjustStackSizeLinux(void *attr, int verbosity);
55
Sergey Matveev24323de2013-05-07 14:41:43 +000056// Exposed for testing.
57uptr ThreadDescriptorSize();
Sergey Matveev4c086442013-05-29 13:07:42 +000058uptr ThreadSelf();
59uptr ThreadSelfOffset();
Sergey Matveev24323de2013-05-07 14:41:43 +000060
Sergey Matveev3de00862013-05-14 13:24:46 +000061// Matches a library's file name against a base name (stripping path and version
62// information).
63bool LibraryNameIs(const char *full_name, const char *base_name);
64
Peter Collingbourne51c963a2013-05-29 12:11:43 +000065// Read the name of the current binary from /proc/self/exe.
66uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
67
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000068} // namespace __sanitizer
69
70#endif // SANITIZER_LINUX_H