blob: af7f2f5441c4cd8ac0641c90a7a7b34ea74a0207 [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 Samsonov7847d772013-09-10 14:36:16 +000016#include "sanitizer_platform.h"
17#if SANITIZER_LINUX
Alexey Samsonov10f3ab72013-04-05 07:41:21 +000018#include "sanitizer_common.h"
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000019#include "sanitizer_internal_defs.h"
20
Peter Collingbourne2e75ac92013-07-29 19:09:49 +000021struct link_map; // Opaque type returned by dlopen().
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000022struct sigaltstack;
23
24namespace __sanitizer {
25// Dirent structure for getdents(). Note that this structure is different from
26// the one in <dirent.h>, which is used by readdir().
27struct linux_dirent;
28
29// Syscall wrappers.
Peter Collingbourne9578a3e2013-05-08 14:43:49 +000030uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
31uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
32uptr internal_sigaltstack(const struct sigaltstack* ss,
33 struct sigaltstack* oss);
Sergey Matveevcb339102013-09-02 11:36:19 +000034#ifdef __x86_64__
35uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
36 int *parent_tidptr, void *newtls, int *child_tidptr);
37#endif
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000038
39// This class reads thread IDs from /proc/<pid>/task using only syscalls.
40class ThreadLister {
41 public:
42 explicit ThreadLister(int pid);
43 ~ThreadLister();
44 // GetNextTID returns -1 if the list of threads is exhausted, or if there has
45 // been an error.
46 int GetNextTID();
47 void Reset();
48 bool error();
49
50 private:
51 bool GetDirectoryEntries();
52
53 int pid_;
54 int descriptor_;
Alexey Samsonov10f3ab72013-04-05 07:41:21 +000055 InternalScopedBuffer<char> buffer_;
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000056 bool error_;
57 struct linux_dirent* entry_;
58 int bytes_read_;
59};
Evgeniy Stepanovb9bf7002013-03-19 09:30:52 +000060
61void AdjustStackSizeLinux(void *attr, int verbosity);
62
Sergey Matveev24323de2013-05-07 14:41:43 +000063// Exposed for testing.
64uptr ThreadDescriptorSize();
Sergey Matveev4c086442013-05-29 13:07:42 +000065uptr ThreadSelf();
66uptr ThreadSelfOffset();
Sergey Matveev24323de2013-05-07 14:41:43 +000067
Sergey Matveev3de00862013-05-14 13:24:46 +000068// Matches a library's file name against a base name (stripping path and version
69// information).
70bool LibraryNameIs(const char *full_name, const char *base_name);
71
Peter Collingbourne51c963a2013-05-29 12:11:43 +000072// Read the name of the current binary from /proc/self/exe.
73uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
Alexey Samsonov7847d772013-09-10 14:36:16 +000074// Cache the value of /proc/self/exe.
75void CacheBinaryName();
Peter Collingbourne51c963a2013-05-29 12:11:43 +000076
Peter Collingbourne2e75ac92013-07-29 19:09:49 +000077// Call cb for each region mapped by map.
78void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
79
Sergey Matveev6eb836f2013-10-11 12:09:49 +000080// PTHREAD_DESTRUCTOR_ITERATIONS from glibc.
81const uptr kPthreadDestructorIterations = 4;
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000082} // namespace __sanitizer
83
Alexey Samsonov7847d772013-09-10 14:36:16 +000084#endif // SANITIZER_LINUX
Kostya Serebryany6fb47af2013-02-27 11:22:40 +000085#endif // SANITIZER_LINUX_H