Mercurial > hg > CbC > CbC_llvm
annotate projects/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc @ 214:0cf2d4ade63d
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Jul 2021 09:53:52 +0900 |
parents | f476a9ba4795 |
children |
rev | line source |
---|---|
131
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
1 //===-- sanitizer_fuchsia.cc ---------------------------------------------===// |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
2 // |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
4 // |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
7 // |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
8 //===---------------------------------------------------------------------===// |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
9 // |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
10 // This file is shared between AddressSanitizer and other sanitizer |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
11 // run-time libraries and implements Fuchsia-specific functions from |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
12 // sanitizer_common.h. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
13 //===---------------------------------------------------------------------===// |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
14 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
15 #include "sanitizer_fuchsia.h" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
16 #if SANITIZER_FUCHSIA |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
17 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
18 #include "sanitizer_common.h" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
19 #include "sanitizer_libc.h" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
20 #include "sanitizer_mutex.h" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
21 #include "sanitizer_stacktrace.h" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
22 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
23 #include <limits.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
24 #include <pthread.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
25 #include <stdlib.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
26 #include <unistd.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
27 #include <unwind.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
28 #include <zircon/errors.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
29 #include <zircon/process.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
30 #include <zircon/syscalls.h> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
31 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
32 namespace __sanitizer { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
33 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
34 void NORETURN internal__exit(int exitcode) { _zx_process_exit(exitcode); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
35 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
36 uptr internal_sched_yield() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
37 zx_status_t status = _zx_nanosleep(0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
38 CHECK_EQ(status, ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
39 return 0; // Why doesn't this return void? |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
40 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
41 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
42 static void internal_nanosleep(zx_time_t ns) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
43 zx_status_t status = _zx_nanosleep(_zx_deadline_after(ns)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
44 CHECK_EQ(status, ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
45 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
46 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
47 unsigned int internal_sleep(unsigned int seconds) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
48 internal_nanosleep(ZX_SEC(seconds)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
49 return 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
50 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
51 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
52 u64 NanoTime() { return _zx_clock_get(ZX_CLOCK_UTC); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
53 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
54 u64 MonotonicNanoTime() { return _zx_clock_get(ZX_CLOCK_MONOTONIC); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
55 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
56 uptr internal_getpid() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
57 zx_info_handle_basic_t info; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
58 zx_status_t status = |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
59 _zx_object_get_info(_zx_process_self(), ZX_INFO_HANDLE_BASIC, &info, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
60 sizeof(info), NULL, NULL); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
61 CHECK_EQ(status, ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
62 uptr pid = static_cast<uptr>(info.koid); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
63 CHECK_EQ(pid, info.koid); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
64 return pid; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
65 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
66 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
67 uptr GetThreadSelf() { return reinterpret_cast<uptr>(thrd_current()); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
68 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
69 uptr GetTid() { return GetThreadSelf(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
70 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
71 void Abort() { abort(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
72 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
73 int Atexit(void (*function)(void)) { return atexit(function); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
74 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
75 void SleepForSeconds(int seconds) { internal_sleep(seconds); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
76 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
77 void SleepForMillis(int millis) { internal_nanosleep(ZX_MSEC(millis)); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
78 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
79 void GetThreadStackTopAndBottom(bool, uptr *stack_top, uptr *stack_bottom) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
80 pthread_attr_t attr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
81 CHECK_EQ(pthread_getattr_np(pthread_self(), &attr), 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
82 void *base; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
83 size_t size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
84 CHECK_EQ(pthread_attr_getstack(&attr, &base, &size), 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
85 CHECK_EQ(pthread_attr_destroy(&attr), 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
86 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
87 *stack_bottom = reinterpret_cast<uptr>(base); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
88 *stack_top = *stack_bottom + size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
89 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
90 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
91 void MaybeReexec() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
92 void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
93 void DisableCoreDumperIfNecessary() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
94 void InstallDeadlySignalHandlers(SignalHandlerType handler) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
95 void StartReportDeadlySignal() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
96 void ReportDeadlySignal(const SignalContext &sig, u32 tid, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
97 UnwindSignalStackCallbackType unwind, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
98 const void *unwind_context) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
99 void SetAlternateSignalStack() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
100 void UnsetAlternateSignalStack() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
101 void InitTlsSize() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
102 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
103 void PrintModuleMap() {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
104 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
105 bool SignalContext::IsStackOverflow() const { return false; } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
106 void SignalContext::DumpAllRegisters(void *context) { UNIMPLEMENTED(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
107 const char *SignalContext::Describe() const { UNIMPLEMENTED(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
108 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
109 struct UnwindTraceArg { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
110 BufferedStackTrace *stack; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
111 u32 max_depth; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
112 }; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
113 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
114 _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
115 UnwindTraceArg *arg = static_cast<UnwindTraceArg *>(param); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
116 CHECK_LT(arg->stack->size, arg->max_depth); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
117 uptr pc = _Unwind_GetIP(ctx); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
118 if (pc < PAGE_SIZE) return _URC_NORMAL_STOP; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
119 arg->stack->trace_buffer[arg->stack->size++] = pc; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
120 return (arg->stack->size == arg->max_depth ? _URC_NORMAL_STOP |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
121 : _URC_NO_REASON); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
122 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
123 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
124 void BufferedStackTrace::SlowUnwindStack(uptr pc, u32 max_depth) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
125 CHECK_GE(max_depth, 2); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
126 size = 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
127 UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)}; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
128 _Unwind_Backtrace(Unwind_Trace, &arg); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
129 CHECK_GT(size, 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
130 // We need to pop a few frames so that pc is on top. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
131 uptr to_pop = LocatePcInTrace(pc); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
132 // trace_buffer[0] belongs to the current function so we always pop it, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
133 // unless there is only 1 frame in the stack trace (1 frame is always better |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
134 // than 0!). |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
135 PopStackFrames(Min(to_pop, static_cast<uptr>(1))); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
136 trace_buffer[0] = pc; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
137 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
138 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
139 void BufferedStackTrace::SlowUnwindStackWithContext(uptr pc, void *context, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
140 u32 max_depth) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
141 CHECK_NE(context, nullptr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
142 UNREACHABLE("signal context doesn't exist"); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
143 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
144 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
145 enum MutexState : int { MtxUnlocked = 0, MtxLocked = 1, MtxSleeping = 2 }; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
146 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
147 BlockingMutex::BlockingMutex() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
148 // NOTE! It's important that this use internal_memset, because plain |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
149 // memset might be intercepted (e.g., actually be __asan_memset). |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
150 // Defining this so the compiler initializes each field, e.g.: |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
151 // BlockingMutex::BlockingMutex() : BlockingMutex(LINKER_INITIALIZED) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
152 // might result in the compiler generating a call to memset, which would |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
153 // have the same problem. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
154 internal_memset(this, 0, sizeof(*this)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
155 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
156 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
157 void BlockingMutex::Lock() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
158 CHECK_EQ(owner_, 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
159 atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
160 if (atomic_exchange(m, MtxLocked, memory_order_acquire) == MtxUnlocked) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
161 return; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
162 while (atomic_exchange(m, MtxSleeping, memory_order_acquire) != MtxUnlocked) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
163 zx_status_t status = _zx_futex_wait(reinterpret_cast<zx_futex_t *>(m), |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
164 MtxSleeping, ZX_TIME_INFINITE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
165 if (status != ZX_ERR_BAD_STATE) // Normal race. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
166 CHECK_EQ(status, ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
167 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
168 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
169 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
170 void BlockingMutex::Unlock() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
171 atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
172 u32 v = atomic_exchange(m, MtxUnlocked, memory_order_release); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
173 CHECK_NE(v, MtxUnlocked); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
174 if (v == MtxSleeping) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
175 zx_status_t status = _zx_futex_wake(reinterpret_cast<zx_futex_t *>(m), 1); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
176 CHECK_EQ(status, ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
177 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
178 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
179 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
180 void BlockingMutex::CheckLocked() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
181 atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
182 CHECK_NE(MtxUnlocked, atomic_load(m, memory_order_relaxed)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
183 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
184 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
185 uptr GetPageSize() { return PAGE_SIZE; } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
186 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
187 uptr GetMmapGranularity() { return PAGE_SIZE; } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
188 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
189 sanitizer_shadow_bounds_t ShadowBounds; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
190 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
191 uptr GetMaxUserVirtualAddress() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
192 ShadowBounds = __sanitizer_shadow_bounds(); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
193 return ShadowBounds.memory_limit - 1; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
194 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
195 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
196 uptr GetMaxVirtualAddress() { return GetMaxUserVirtualAddress(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
197 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
198 static void *DoAnonymousMmapOrDie(uptr size, const char *mem_type, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
199 bool raw_report, bool die_for_nomem) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
200 size = RoundUpTo(size, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
201 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
202 zx_handle_t vmo; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
203 zx_status_t status = _zx_vmo_create(size, 0, &vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
204 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
205 if (status != ZX_ERR_NO_MEMORY || die_for_nomem) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
206 ReportMmapFailureAndDie(size, mem_type, "zx_vmo_create", status, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
207 raw_report); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
208 return nullptr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
209 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
210 _zx_object_set_property(vmo, ZX_PROP_NAME, mem_type, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
211 internal_strlen(mem_type)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
212 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
213 // TODO(mcgrathr): Maybe allocate a VMAR for all sanitizer heap and use that? |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
214 uintptr_t addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
215 status = _zx_vmar_map(_zx_vmar_root_self(), 0, vmo, 0, size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
216 ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE, &addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
217 _zx_handle_close(vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
218 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
219 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
220 if (status != ZX_ERR_NO_MEMORY || die_for_nomem) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
221 ReportMmapFailureAndDie(size, mem_type, "zx_vmar_map", status, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
222 raw_report); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
223 return nullptr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
224 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
225 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
226 IncreaseTotalMmap(size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
227 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
228 return reinterpret_cast<void *>(addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
229 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
230 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
231 void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
232 return DoAnonymousMmapOrDie(size, mem_type, raw_report, true); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
233 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
234 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
235 void *MmapNoReserveOrDie(uptr size, const char *mem_type) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
236 return MmapOrDie(size, mem_type); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
237 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
238 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
239 void *MmapOrDieOnFatalError(uptr size, const char *mem_type) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
240 return DoAnonymousMmapOrDie(size, mem_type, false, false); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
241 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
242 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
243 uptr ReservedAddressRange::Init(uptr init_size, const char *name, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
244 uptr fixed_addr) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
245 init_size = RoundUpTo(init_size, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
246 DCHECK_EQ(os_handle_, ZX_HANDLE_INVALID); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
247 uintptr_t base; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
248 zx_handle_t vmar; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
249 zx_status_t status = |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
250 _zx_vmar_allocate(_zx_vmar_root_self(), 0, init_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
251 ZX_VM_FLAG_CAN_MAP_READ | ZX_VM_FLAG_CAN_MAP_WRITE | |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
252 ZX_VM_FLAG_CAN_MAP_SPECIFIC, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
253 &vmar, &base); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
254 if (status != ZX_OK) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
255 ReportMmapFailureAndDie(init_size, name, "zx_vmar_allocate", status); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
256 base_ = reinterpret_cast<void *>(base); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
257 size_ = init_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
258 name_ = name; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
259 os_handle_ = vmar; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
260 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
261 return reinterpret_cast<uptr>(base_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
262 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
263 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
264 static uptr DoMmapFixedOrDie(zx_handle_t vmar, uptr fixed_addr, uptr map_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
265 void *base, const char *name, bool die_for_nomem) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
266 uptr offset = fixed_addr - reinterpret_cast<uptr>(base); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
267 map_size = RoundUpTo(map_size, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
268 zx_handle_t vmo; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
269 zx_status_t status = _zx_vmo_create(map_size, 0, &vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
270 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
271 if (status != ZX_ERR_NO_MEMORY || die_for_nomem) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
272 ReportMmapFailureAndDie(map_size, name, "zx_vmo_create", status); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
273 return 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
274 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
275 _zx_object_set_property(vmo, ZX_PROP_NAME, name, sizeof(name) - 1); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
276 DCHECK_GE(base + size_, map_size + offset); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
277 uintptr_t addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
278 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
279 status = _zx_vmar_map( |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
280 vmar, offset, vmo, 0, map_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
281 ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE | ZX_VM_FLAG_SPECIFIC, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
282 &addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
283 _zx_handle_close(vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
284 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
285 if (status != ZX_ERR_NO_MEMORY || die_for_nomem) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
286 ReportMmapFailureAndDie(map_size, name, "zx_vmar_map", status); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
287 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
288 return 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
289 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
290 IncreaseTotalMmap(map_size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
291 return addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
292 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
293 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
294 uptr ReservedAddressRange::Map(uptr fixed_addr, uptr map_size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
295 return DoMmapFixedOrDie(os_handle_, fixed_addr, map_size, base_, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
296 name_, false); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
297 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
298 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
299 uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr map_size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
300 return DoMmapFixedOrDie(os_handle_, fixed_addr, map_size, base_, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
301 name_, true); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
302 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
303 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
304 void UnmapOrDieVmar(void *addr, uptr size, zx_handle_t target_vmar) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
305 if (!addr || !size) return; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
306 size = RoundUpTo(size, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
307 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
308 zx_status_t status = |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
309 _zx_vmar_unmap(target_vmar, reinterpret_cast<uintptr_t>(addr), size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
310 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
311 Report("ERROR: %s failed to deallocate 0x%zx (%zd) bytes at address %p\n", |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
312 SanitizerToolName, size, size, addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
313 CHECK("unable to unmap" && 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
314 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
315 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
316 DecreaseTotalMmap(size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
317 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
318 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
319 void ReservedAddressRange::Unmap(uptr fixed_addr, uptr size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
320 uptr offset = fixed_addr - reinterpret_cast<uptr>(base_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
321 uptr addr = reinterpret_cast<uptr>(base_) + offset; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
322 void *addr_as_void = reinterpret_cast<void *>(addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
323 uptr base_as_uptr = reinterpret_cast<uptr>(base_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
324 // Only unmap at the beginning or end of the range. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
325 CHECK((addr_as_void == base_) || (addr + size == base_as_uptr + size_)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
326 CHECK_LE(size, size_); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
327 UnmapOrDieVmar(reinterpret_cast<void *>(addr), size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
328 static_cast<zx_handle_t>(os_handle_)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
329 if (addr_as_void == base_) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
330 base_ = reinterpret_cast<void *>(addr + size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
331 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
332 size_ = size_ - size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
333 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
334 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
335 // This should never be called. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
336 void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
337 UNIMPLEMENTED(); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
338 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
339 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
340 void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
341 const char *mem_type) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
342 CHECK_GE(size, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
343 CHECK(IsPowerOfTwo(size)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
344 CHECK(IsPowerOfTwo(alignment)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
345 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
346 zx_handle_t vmo; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
347 zx_status_t status = _zx_vmo_create(size, 0, &vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
348 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
349 if (status != ZX_ERR_NO_MEMORY) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
350 ReportMmapFailureAndDie(size, mem_type, "zx_vmo_create", status, false); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
351 return nullptr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
352 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
353 _zx_object_set_property(vmo, ZX_PROP_NAME, mem_type, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
354 internal_strlen(mem_type)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
355 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
356 // TODO(mcgrathr): Maybe allocate a VMAR for all sanitizer heap and use that? |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
357 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
358 // Map a larger size to get a chunk of address space big enough that |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
359 // it surely contains an aligned region of the requested size. Then |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
360 // overwrite the aligned middle portion with a mapping from the |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
361 // beginning of the VMO, and unmap the excess before and after. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
362 size_t map_size = size + alignment; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
363 uintptr_t addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
364 status = _zx_vmar_map(_zx_vmar_root_self(), 0, vmo, 0, map_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
365 ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE, &addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
366 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
367 uintptr_t map_addr = addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
368 uintptr_t map_end = map_addr + map_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
369 addr = RoundUpTo(map_addr, alignment); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
370 uintptr_t end = addr + size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
371 if (addr != map_addr) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
372 zx_info_vmar_t info; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
373 status = _zx_object_get_info(_zx_vmar_root_self(), ZX_INFO_VMAR, &info, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
374 sizeof(info), NULL, NULL); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
375 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
376 uintptr_t new_addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
377 status = |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
378 _zx_vmar_map(_zx_vmar_root_self(), addr - info.base, vmo, 0, size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
379 ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE | |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
380 ZX_VM_FLAG_SPECIFIC_OVERWRITE, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
381 &new_addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
382 if (status == ZX_OK) CHECK_EQ(new_addr, addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
383 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
384 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
385 if (status == ZX_OK && addr != map_addr) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
386 status = _zx_vmar_unmap(_zx_vmar_root_self(), map_addr, addr - map_addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
387 if (status == ZX_OK && end != map_end) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
388 status = _zx_vmar_unmap(_zx_vmar_root_self(), end, map_end - end); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
389 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
390 _zx_handle_close(vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
391 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
392 if (status != ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
393 if (status != ZX_ERR_NO_MEMORY) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
394 ReportMmapFailureAndDie(size, mem_type, "zx_vmar_map", status, false); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
395 return nullptr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
396 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
397 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
398 IncreaseTotalMmap(size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
399 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
400 return reinterpret_cast<void *>(addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
401 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
402 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
403 void UnmapOrDie(void *addr, uptr size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
404 UnmapOrDieVmar(addr, size, _zx_vmar_root_self()); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
405 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
406 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
407 // This is used on the shadow mapping, which cannot be changed. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
408 // Zircon doesn't have anything like MADV_DONTNEED. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
409 void ReleaseMemoryPagesToOS(uptr beg, uptr end) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
410 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
411 void DumpProcessMap() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
412 // TODO(mcgrathr): write it |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
413 return; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
414 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
415 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
416 bool IsAccessibleMemoryRange(uptr beg, uptr size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
417 // TODO(mcgrathr): Figure out a better way. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
418 zx_handle_t vmo; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
419 zx_status_t status = _zx_vmo_create(size, 0, &vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
420 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
421 while (size > 0) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
422 size_t wrote; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
423 status = _zx_vmo_write(vmo, reinterpret_cast<const void *>(beg), 0, size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
424 &wrote); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
425 if (status != ZX_OK) break; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
426 CHECK_GT(wrote, 0); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
427 CHECK_LE(wrote, size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
428 beg += wrote; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
429 size -= wrote; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
430 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
431 _zx_handle_close(vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
432 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
433 return status == ZX_OK; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
434 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
435 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
436 // FIXME implement on this platform. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
437 void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {} |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
438 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
439 bool ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
440 uptr *read_len, uptr max_len, error_t *errno_p) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
441 zx_handle_t vmo; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
442 zx_status_t status = __sanitizer_get_configuration(file_name, &vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
443 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
444 uint64_t vmo_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
445 status = _zx_vmo_get_size(vmo, &vmo_size); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
446 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
447 if (vmo_size < max_len) max_len = vmo_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
448 size_t map_size = RoundUpTo(max_len, PAGE_SIZE); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
449 uintptr_t addr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
450 status = _zx_vmar_map(_zx_vmar_root_self(), 0, vmo, 0, map_size, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
451 ZX_VM_FLAG_PERM_READ, &addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
452 if (status == ZX_OK) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
453 *buff = reinterpret_cast<char *>(addr); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
454 *buff_size = map_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
455 *read_len = max_len; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
456 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
457 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
458 _zx_handle_close(vmo); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
459 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
460 if (status != ZX_OK && errno_p) *errno_p = status; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
461 return status == ZX_OK; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
462 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
463 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
464 void RawWrite(const char *buffer) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
465 __sanitizer_log_write(buffer, internal_strlen(buffer)); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
466 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
467 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
468 void CatastrophicErrorWrite(const char *buffer, uptr length) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
469 __sanitizer_log_write(buffer, length); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
470 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
471 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
472 char **StoredArgv; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
473 char **StoredEnviron; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
474 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
475 char **GetArgv() { return StoredArgv; } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
476 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
477 const char *GetEnv(const char *name) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
478 if (StoredEnviron) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
479 uptr NameLen = internal_strlen(name); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
480 for (char **Env = StoredEnviron; *Env != 0; Env++) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
481 if (internal_strncmp(*Env, name, NameLen) == 0 && (*Env)[NameLen] == '=') |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
482 return (*Env) + NameLen + 1; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
483 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
484 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
485 return nullptr; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
486 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
487 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
488 uptr ReadBinaryName(/*out*/ char *buf, uptr buf_len) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
489 const char *argv0 = StoredArgv[0]; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
490 if (!argv0) argv0 = "<UNKNOWN>"; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
491 internal_strncpy(buf, argv0, buf_len); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
492 return internal_strlen(buf); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
493 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
494 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
495 uptr ReadLongProcessName(/*out*/ char *buf, uptr buf_len) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
496 return ReadBinaryName(buf, buf_len); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
497 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
498 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
499 uptr MainThreadStackBase, MainThreadStackSize; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
500 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
501 bool GetRandom(void *buffer, uptr length, bool blocking) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
502 CHECK_LE(length, ZX_CPRNG_DRAW_MAX_LEN); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
503 size_t size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
504 CHECK_EQ(_zx_cprng_draw(buffer, length, &size), ZX_OK); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
505 CHECK_EQ(size, length); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
506 return true; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
507 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
508 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
509 u32 GetNumberOfCPUs() { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
510 return zx_system_get_num_cpus(); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
511 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
512 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
513 uptr GetRSS() { UNIMPLEMENTED(); } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
514 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
515 } // namespace __sanitizer |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
516 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
517 using namespace __sanitizer; // NOLINT |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
518 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
519 extern "C" { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
520 void __sanitizer_startup_hook(int argc, char **argv, char **envp, |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
521 void *stack_base, size_t stack_size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
522 __sanitizer::StoredArgv = argv; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
523 __sanitizer::StoredEnviron = envp; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
524 __sanitizer::MainThreadStackBase = reinterpret_cast<uintptr_t>(stack_base); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
525 __sanitizer::MainThreadStackSize = stack_size; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
526 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
527 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
528 void __sanitizer_set_report_path(const char *path) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
529 // Handle the initialization code in each sanitizer, but no other calls. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
530 // This setting is never consulted on Fuchsia. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
531 DCHECK_EQ(path, common_flags()->log_path); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
532 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
533 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
534 void __sanitizer_set_report_fd(void *fd) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
535 UNREACHABLE("not available on Fuchsia"); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
536 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
537 } // extern "C" |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
538 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
539 #endif // SANITIZER_FUCHSIA |