summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/rtl/tsan_platform.h
blob: 9cfe4763f6c887fe4edf38d9c8bf0070984c9fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===-- tsan_platform.h -----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of ThreadSanitizer (TSan), a race detector.
//
// Platform-specific code.
//===----------------------------------------------------------------------===//

#ifndef TSAN_LINUX_H
#define TSAN_LINUX_H
#ifdef __linux__

#include "tsan_rtl.h"

#if __LP64__
namespace __tsan {

// TSAN_COMPAT_SHADOW is intended for COMPAT virtual memory layout,
// when memory addresses are of the 0x2axxxxxxxxxx form.
// The option is enabled with 'setarch x86_64 -L'.
#if defined(TSAN_COMPAT_SHADOW) && TSAN_COMPAT_SHADOW

static const uptr kLinuxAppMemBeg = 0x2a0000000000ULL;
static const uptr kLinuxAppMemEnd = 0x7fffffffffffULL;

#else

static const uptr kLinuxAppMemBeg = 0x7ef000000000ULL;
static const uptr kLinuxAppMemEnd = 0x7fffffffffffULL;

#endif

static const uptr kLinuxAppMemMsk = 0x7c0000000000ULL;

// This has to be a macro to allow constant initialization of constants below.
#define MemToShadow(addr) \
    (((addr) & ~(kLinuxAppMemMsk | (kShadowCell - 1))) * kShadowCnt)

static const uptr kLinuxShadowBeg = MemToShadow(kLinuxAppMemBeg);
static const uptr kLinuxShadowEnd =
  MemToShadow(kLinuxAppMemEnd) | (kPageSize - 1);

static inline bool IsAppMem(uptr mem) {
  return mem >= kLinuxAppMemBeg && mem <= kLinuxAppMemEnd;
}

static inline bool IsShadowMem(uptr mem) {
  return mem >= kLinuxShadowBeg && mem <= kLinuxShadowEnd;
}

static inline uptr ShadowToMem(uptr shadow) {
  CHECK(IsShadowMem(shadow));
#if defined(TSAN_COMPAT_SHADOW) && TSAN_COMPAT_SHADOW
  // COMPAT mapping is not quite one-to-one.
  return (shadow / kShadowCnt) | 0x280000000000ULL;
#else
  return (shadow / kShadowCnt) | kLinuxAppMemMsk;
#endif
}

const char *InitializePlatform();
void FinalizePlatform();
int GetPid();

void sched_yield();

typedef int fd_t;
const fd_t kInvalidFd = -1;
fd_t internal_open(const char *name, bool write);
void internal_close(fd_t fd);
uptr internal_filesize(fd_t fd);  // -1 on error.
uptr internal_read(fd_t fd, void *p, uptr size);
uptr internal_write(fd_t fd, const void *p, uptr size);
const char *internal_getpwd();

uptr GetTlsSize();
void GetThreadStackAndTls(uptr *stk_addr, uptr *stk_size,
                          uptr *tls_addr, uptr *tls_size);

}  // namespace __tsan

#else  // __LP64__
# error "Only 64-bit is supported"
#endif

#endif  // __linux__
#endif  // TSAN_LINUX_H
OpenPOWER on IntegriCloud