Alexey Samsonov | 298dd7c | 2012-06-05 07:46:31 +0000 | [diff] [blame] | 1 | //===-- sanitizer_win.cc --------------------------------------------------===// |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 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 | // This file is shared between AddressSanitizer and ThreadSanitizer |
| 11 | // run-time libraries and implements windows-specific functions from |
| 12 | // sanitizer_libc.h. |
| 13 | //===----------------------------------------------------------------------===// |
Evgeniy Stepanov | 0af6723 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 14 | |
| 15 | #include "sanitizer_platform.h" |
| 16 | #if SANITIZER_WINDOWS |
| 17 | |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 18 | #define WIN32_LEAN_AND_MEAN |
| 19 | #define NOGDI |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 20 | #include <windows.h> |
Timur Iskhodzhanov | 19853dd | 2014-07-11 11:57:41 +0000 | [diff] [blame] | 21 | #include <dbghelp.h> |
| 22 | #include <io.h> |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 23 | #include <psapi.h> |
Timur Iskhodzhanov | 19853dd | 2014-07-11 11:57:41 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 25 | |
Alexey Samsonov | 201aa36 | 2012-06-06 09:43:32 +0000 | [diff] [blame] | 26 | #include "sanitizer_common.h" |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 27 | #include "sanitizer_libc.h" |
Dmitry Vyukov | ff19809 | 2013-01-14 14:28:06 +0000 | [diff] [blame] | 28 | #include "sanitizer_mutex.h" |
Sergey Matveev | af179b8 | 2013-05-08 12:45:55 +0000 | [diff] [blame] | 29 | #include "sanitizer_placement_new.h" |
| 30 | #include "sanitizer_stacktrace.h" |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 31 | |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 32 | namespace __sanitizer { |
| 33 | |
Peter Collingbourne | 6f4be19 | 2013-05-08 14:43:49 +0000 | [diff] [blame] | 34 | #include "sanitizer_syscall_generic.inc" |
| 35 | |
Alexey Samsonov | 4b1f103 | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 36 | // --------------------- sanitizer_common.h |
Kostya Serebryany | f22c697 | 2012-11-23 15:38:49 +0000 | [diff] [blame] | 37 | uptr GetPageSize() { |
| 38 | return 1U << 14; // FIXME: is this configurable? |
| 39 | } |
| 40 | |
| 41 | uptr GetMmapGranularity() { |
| 42 | return 1U << 16; // FIXME: is this configurable? |
| 43 | } |
| 44 | |
Timur Iskhodzhanov | 4245f78 | 2013-07-16 09:47:39 +0000 | [diff] [blame] | 45 | uptr GetMaxVirtualAddress() { |
| 46 | SYSTEM_INFO si; |
| 47 | GetSystemInfo(&si); |
| 48 | return (uptr)si.lpMaximumApplicationAddress; |
| 49 | } |
| 50 | |
Alexey Samsonov | ae9b18b | 2012-11-09 14:45:30 +0000 | [diff] [blame] | 51 | bool FileExists(const char *filename) { |
| 52 | UNIMPLEMENTED(); |
| 53 | } |
| 54 | |
Peter Collingbourne | ffaf2ea | 2013-05-17 16:56:53 +0000 | [diff] [blame] | 55 | uptr internal_getpid() { |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 56 | return GetProcessId(GetCurrentProcess()); |
| 57 | } |
| 58 | |
Timur Iskhodzhanov | 2dee3dd | 2013-03-25 22:04:29 +0000 | [diff] [blame] | 59 | // In contrast to POSIX, on Windows GetCurrentThreadId() |
| 60 | // returns a system-unique identifier. |
| 61 | uptr GetTid() { |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 62 | return GetCurrentThreadId(); |
| 63 | } |
| 64 | |
Timur Iskhodzhanov | 2dee3dd | 2013-03-25 22:04:29 +0000 | [diff] [blame] | 65 | uptr GetThreadSelf() { |
| 66 | return GetTid(); |
| 67 | } |
| 68 | |
Dmitry Vyukov | aa8fa60 | 2014-09-01 11:44:59 +0000 | [diff] [blame] | 69 | #if !SANITIZER_GO |
Alexey Samsonov | cf4d3a0 | 2012-06-07 07:32:00 +0000 | [diff] [blame] | 70 | void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, |
Alexey Samsonov | 4b1f103 | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 71 | uptr *stack_bottom) { |
| 72 | CHECK(stack_top); |
| 73 | CHECK(stack_bottom); |
| 74 | MEMORY_BASIC_INFORMATION mbi; |
Kostya Serebryany | 98390d0 | 2012-06-20 15:19:17 +0000 | [diff] [blame] | 75 | CHECK_NE(VirtualQuery(&mbi /* on stack */, &mbi, sizeof(mbi)), 0); |
Alexey Samsonov | 4b1f103 | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 76 | // FIXME: is it possible for the stack to not be a single allocation? |
| 77 | // Are these values what ASan expects to get (reserved, not committed; |
| 78 | // including stack guard page) ? |
| 79 | *stack_top = (uptr)mbi.BaseAddress + mbi.RegionSize; |
| 80 | *stack_bottom = (uptr)mbi.AllocationBase; |
| 81 | } |
Dmitry Vyukov | aa8fa60 | 2014-09-01 11:44:59 +0000 | [diff] [blame] | 82 | #endif // #if !SANITIZER_GO |
Alexey Samsonov | 4b1f103 | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 83 | |
Alexey Samsonov | 40d5b77 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 84 | void *MmapOrDie(uptr size, const char *mem_type) { |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 85 | void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
Alexey Samsonov | 40d5b77 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 86 | if (rv == 0) { |
Timur Iskhodzhanov | 364b8b8 | 2014-03-19 08:23:00 +0000 | [diff] [blame] | 87 | Report("ERROR: %s failed to " |
| 88 | "allocate 0x%zx (%zd) bytes of %s (error code: %d)\n", |
| 89 | SanitizerToolName, size, size, mem_type, GetLastError()); |
Alexey Samsonov | 40d5b77 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 90 | CHECK("unable to mmap" && 0); |
| 91 | } |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 92 | return rv; |
| 93 | } |
| 94 | |
| 95 | void UnmapOrDie(void *addr, uptr size) { |
Timur Iskhodzhanov | 89608af | 2015-03-31 16:39:20 +0000 | [diff] [blame] | 96 | if (!size || !addr) |
| 97 | return; |
| 98 | |
Alexey Samsonov | e95e29c | 2012-06-06 15:47:40 +0000 | [diff] [blame] | 99 | if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) { |
Timur Iskhodzhanov | 364b8b8 | 2014-03-19 08:23:00 +0000 | [diff] [blame] | 100 | Report("ERROR: %s failed to " |
| 101 | "deallocate 0x%zx (%zd) bytes at address %p (error code: %d)\n", |
| 102 | SanitizerToolName, size, size, addr, GetLastError()); |
Alexey Samsonov | 40d5b77 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 103 | CHECK("unable to unmap" && 0); |
Alexey Samsonov | e95e29c | 2012-06-06 15:47:40 +0000 | [diff] [blame] | 104 | } |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Evgeniy Stepanov | 8e9c70b | 2015-05-29 22:31:28 +0000 | [diff] [blame] | 107 | void *MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) { |
Kostya Serebryany | 9806628 | 2012-12-13 05:36:00 +0000 | [diff] [blame] | 108 | // FIXME: is this really "NoReserve"? On Win32 this does not matter much, |
| 109 | // but on Win64 it does. |
Evgeniy Stepanov | 8e9c70b | 2015-05-29 22:31:28 +0000 | [diff] [blame] | 110 | (void)name; // unsupported |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 111 | void *p = VirtualAlloc((LPVOID)fixed_addr, size, |
| 112 | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
| 113 | if (p == 0) |
Timur Iskhodzhanov | 364b8b8 | 2014-03-19 08:23:00 +0000 | [diff] [blame] | 114 | Report("ERROR: %s failed to " |
| 115 | "allocate %p (%zd) bytes at %p (error code: %d)\n", |
| 116 | SanitizerToolName, size, size, fixed_addr, GetLastError()); |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 117 | return p; |
Alexey Samsonov | c70d108 | 2012-06-14 14:42:58 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Kostya Serebryany | 9806628 | 2012-12-13 05:36:00 +0000 | [diff] [blame] | 120 | void *MmapFixedOrDie(uptr fixed_addr, uptr size) { |
Kostya Serebryany | a167087 | 2012-12-13 05:51:02 +0000 | [diff] [blame] | 121 | return MmapFixedNoReserve(fixed_addr, size); |
Kostya Serebryany | 9806628 | 2012-12-13 05:36:00 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kostya Serebryany | 57bfdb0 | 2013-12-13 15:03:49 +0000 | [diff] [blame] | 124 | void *MmapNoReserveOrDie(uptr size, const char *mem_type) { |
| 125 | // FIXME: make this really NoReserve? |
| 126 | return MmapOrDie(size, mem_type); |
| 127 | } |
| 128 | |
Evgeniy Stepanov | 8e9c70b | 2015-05-29 22:31:28 +0000 | [diff] [blame] | 129 | void *MmapNoAccess(uptr fixed_addr, uptr size, const char *name) { |
| 130 | (void)name; // unsupported |
Timur Iskhodzhanov | e5935ef | 2015-02-02 15:04:23 +0000 | [diff] [blame] | 131 | void *res = VirtualAlloc((LPVOID)fixed_addr, size, |
| 132 | MEM_RESERVE | MEM_COMMIT, PAGE_NOACCESS); |
| 133 | if (res == 0) |
| 134 | Report("WARNING: %s failed to " |
| 135 | "mprotect %p (%zd) bytes at %p (error code: %d)\n", |
| 136 | SanitizerToolName, size, size, fixed_addr, GetLastError()); |
| 137 | return res; |
Alexey Samsonov | c70d108 | 2012-06-14 14:42:58 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Timur Iskhodzhanov | ea1f332 | 2015-04-10 15:02:19 +0000 | [diff] [blame] | 140 | bool MprotectNoAccess(uptr addr, uptr size) { |
| 141 | DWORD old_protection; |
| 142 | return VirtualProtect((LPVOID)addr, size, PAGE_NOACCESS, &old_protection); |
| 143 | } |
| 144 | |
| 145 | |
Timur Iskhodzhanov | 167f9e4 | 2013-02-08 12:02:00 +0000 | [diff] [blame] | 146 | void FlushUnneededShadowMemory(uptr addr, uptr size) { |
| 147 | // This is almost useless on 32-bits. |
Yury Gribov | 8f848ff | 2015-02-03 10:15:15 +0000 | [diff] [blame] | 148 | // FIXME: add madvise-analog when we move to 64-bits. |
Timur Iskhodzhanov | 167f9e4 | 2013-02-08 12:02:00 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Kostya Serebryany | c6338ac | 2015-01-21 02:05:31 +0000 | [diff] [blame] | 151 | void NoHugePagesInRegion(uptr addr, uptr size) { |
| 152 | // FIXME: probably similar to FlushUnneededShadowMemory. |
| 153 | } |
| 154 | |
Yury Gribov | 8f848ff | 2015-02-03 10:15:15 +0000 | [diff] [blame] | 155 | void DontDumpShadowMemory(uptr addr, uptr length) { |
| 156 | // This is almost useless on 32-bits. |
| 157 | // FIXME: add madvise-analog when we move to 64-bits. |
| 158 | } |
| 159 | |
Alexey Samsonov | 40e5128 | 2012-06-15 07:29:14 +0000 | [diff] [blame] | 160 | bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) { |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 161 | MEMORY_BASIC_INFORMATION mbi; |
| 162 | CHECK(VirtualQuery((void *)range_start, &mbi, sizeof(mbi))); |
Timur Iskhodzhanov | e5935ef | 2015-02-02 15:04:23 +0000 | [diff] [blame] | 163 | return mbi.Protect == PAGE_NOACCESS && |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 164 | (uptr)mbi.BaseAddress + mbi.RegionSize >= range_end; |
Alexey Samsonov | 40e5128 | 2012-06-15 07:29:14 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Alexey Samsonov | 961276a | 2012-07-03 08:24:14 +0000 | [diff] [blame] | 167 | void *MapFileToMemory(const char *file_name, uptr *buff_size) { |
| 168 | UNIMPLEMENTED(); |
| 169 | } |
| 170 | |
Timur Iskhodzhanov | daa9e2d | 2015-04-08 16:03:22 +0000 | [diff] [blame] | 171 | void *MapWritableFileToMemory(void *addr, uptr size, fd_t fd, uptr offset) { |
Evgeniy Stepanov | a00ff19 | 2014-05-28 08:26:24 +0000 | [diff] [blame] | 172 | UNIMPLEMENTED(); |
| 173 | } |
| 174 | |
Alexey Samsonov | 7d23854 | 2013-03-14 11:29:06 +0000 | [diff] [blame] | 175 | static const int kMaxEnvNameLength = 128; |
Dmitry Vyukov | e979c54 | 2013-06-10 10:02:02 +0000 | [diff] [blame] | 176 | static const DWORD kMaxEnvValueLength = 32767; |
Alexey Samsonov | 83e7622 | 2013-03-14 11:10:23 +0000 | [diff] [blame] | 177 | |
| 178 | namespace { |
| 179 | |
| 180 | struct EnvVariable { |
| 181 | char name[kMaxEnvNameLength]; |
| 182 | char value[kMaxEnvValueLength]; |
| 183 | }; |
| 184 | |
| 185 | } // namespace |
| 186 | |
| 187 | static const int kEnvVariables = 5; |
| 188 | static EnvVariable env_vars[kEnvVariables]; |
| 189 | static int num_env_vars; |
| 190 | |
Alexey Samsonov | 0c53a38 | 2012-06-14 14:07:21 +0000 | [diff] [blame] | 191 | const char *GetEnv(const char *name) { |
Alexey Samsonov | 83e7622 | 2013-03-14 11:10:23 +0000 | [diff] [blame] | 192 | // Note: this implementation caches the values of the environment variables |
| 193 | // and limits their quantity. |
| 194 | for (int i = 0; i < num_env_vars; i++) { |
| 195 | if (0 == internal_strcmp(name, env_vars[i].name)) |
| 196 | return env_vars[i].value; |
| 197 | } |
| 198 | CHECK_LT(num_env_vars, kEnvVariables); |
| 199 | DWORD rv = GetEnvironmentVariableA(name, env_vars[num_env_vars].value, |
| 200 | kMaxEnvValueLength); |
| 201 | if (rv > 0 && rv < kMaxEnvValueLength) { |
| 202 | CHECK_LT(internal_strlen(name), kMaxEnvNameLength); |
| 203 | internal_strncpy(env_vars[num_env_vars].name, name, kMaxEnvNameLength); |
| 204 | num_env_vars++; |
| 205 | return env_vars[num_env_vars - 1].value; |
| 206 | } |
Alexey Samsonov | 0c53a38 | 2012-06-14 14:07:21 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
Alexey Samsonov | 58a3c58 | 2012-06-18 08:44:30 +0000 | [diff] [blame] | 210 | const char *GetPwd() { |
| 211 | UNIMPLEMENTED(); |
| 212 | } |
| 213 | |
Alexey Samsonov | 9211bd3 | 2013-02-18 07:17:12 +0000 | [diff] [blame] | 214 | u32 GetUid() { |
| 215 | UNIMPLEMENTED(); |
| 216 | } |
| 217 | |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 218 | namespace { |
| 219 | struct ModuleInfo { |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 220 | const char *filepath; |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 221 | uptr base_address; |
| 222 | uptr end_address; |
| 223 | }; |
| 224 | |
| 225 | int CompareModulesBase(const void *pl, const void *pr) { |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 226 | const ModuleInfo *l = (ModuleInfo *)pl, *r = (ModuleInfo *)pr; |
| 227 | if (l->base_address < r->base_address) |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 228 | return -1; |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 229 | return l->base_address > r->base_address; |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 230 | } |
Timur Iskhodzhanov | a023e06 | 2014-12-30 15:30:19 +0000 | [diff] [blame] | 231 | } // namespace |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 232 | |
Dmitry Vyukov | b3381fa | 2015-02-16 13:51:17 +0000 | [diff] [blame] | 233 | #ifndef SANITIZER_GO |
Alexey Samsonov | ae1e171 | 2012-06-15 06:08:19 +0000 | [diff] [blame] | 234 | void DumpProcessMap() { |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 235 | Report("Dumping process modules:\n"); |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 236 | InternalScopedBuffer<LoadedModule> modules(kMaxNumberOfModules); |
| 237 | uptr num_modules = |
| 238 | GetListOfModules(modules.data(), kMaxNumberOfModules, nullptr); |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 239 | |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 240 | InternalScopedBuffer<ModuleInfo> module_infos(num_modules); |
| 241 | for (size_t i = 0; i < num_modules; ++i) { |
| 242 | module_infos[i].filepath = modules[i].full_name(); |
| 243 | module_infos[i].base_address = modules[i].base_address(); |
| 244 | module_infos[i].end_address = modules[i].ranges().next()->end; |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 245 | } |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 246 | qsort(module_infos.data(), num_modules, sizeof(ModuleInfo), |
| 247 | CompareModulesBase); |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 248 | |
| 249 | for (size_t i = 0; i < num_modules; ++i) { |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 250 | const ModuleInfo &mi = module_infos[i]; |
Timur Iskhodzhanov | 64fc8e4 | 2014-12-30 14:44:12 +0000 | [diff] [blame] | 251 | if (mi.end_address != 0) { |
| 252 | Printf("\t%p-%p %s\n", mi.base_address, mi.end_address, |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 253 | mi.filepath[0] ? mi.filepath : "[no name]"); |
Timur Iskhodzhanov | 1931b62 | 2015-04-06 12:54:06 +0000 | [diff] [blame] | 254 | } else if (mi.filepath[0]) { |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 255 | Printf("\t??\?-??? %s\n", mi.filepath); |
Timur Iskhodzhanov | a04b33b | 2014-12-26 14:28:32 +0000 | [diff] [blame] | 256 | } else { |
| 257 | Printf("\t???\n"); |
| 258 | } |
| 259 | } |
Alexey Samsonov | ae1e171 | 2012-06-15 06:08:19 +0000 | [diff] [blame] | 260 | } |
Dmitry Vyukov | b3381fa | 2015-02-16 13:51:17 +0000 | [diff] [blame] | 261 | #endif |
Alexey Samsonov | ae1e171 | 2012-06-15 06:08:19 +0000 | [diff] [blame] | 262 | |
Alexey Samsonov | 34e2b28 | 2014-08-12 22:31:19 +0000 | [diff] [blame] | 263 | void DisableCoreDumperIfNecessary() { |
Timur Iskhodzhanov | 7d5c81d | 2014-05-06 08:21:50 +0000 | [diff] [blame] | 264 | // Do nothing. |
Alexey Samsonov | ae1e171 | 2012-06-15 06:08:19 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Alexey Samsonov | 97ca306 | 2012-09-17 09:12:39 +0000 | [diff] [blame] | 267 | void ReExec() { |
| 268 | UNIMPLEMENTED(); |
| 269 | } |
| 270 | |
Sergey Matveev | 6cb47a08 | 2014-05-19 12:53:03 +0000 | [diff] [blame] | 271 | void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) { |
Timur Iskhodzhanov | d0be0a9 | 2015-04-23 12:58:11 +0000 | [diff] [blame] | 272 | #if !SANITIZER_GO |
| 273 | CovPrepareForSandboxing(args); |
| 274 | #endif |
Alexander Potapenko | 1746f55 | 2012-12-10 13:10:40 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Alexey Samsonov | 97ca306 | 2012-09-17 09:12:39 +0000 | [diff] [blame] | 277 | bool StackSizeIsUnlimited() { |
| 278 | UNIMPLEMENTED(); |
Alexey Samsonov | 97ca306 | 2012-09-17 09:12:39 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void SetStackSizeLimitInBytes(uptr limit) { |
| 282 | UNIMPLEMENTED(); |
| 283 | } |
| 284 | |
Alexey Samsonov | 34e2b28 | 2014-08-12 22:31:19 +0000 | [diff] [blame] | 285 | bool AddressSpaceIsUnlimited() { |
| 286 | UNIMPLEMENTED(); |
| 287 | } |
| 288 | |
| 289 | void SetAddressSpaceUnlimited() { |
| 290 | UNIMPLEMENTED(); |
| 291 | } |
| 292 | |
Alexey Samsonov | de647dd | 2013-09-03 13:20:48 +0000 | [diff] [blame] | 293 | char *FindPathToBinary(const char *name) { |
Timur Iskhodzhanov | 2eea589 | 2013-09-03 15:50:13 +0000 | [diff] [blame] | 294 | // Nothing here for now. |
| 295 | return 0; |
Alexey Samsonov | de647dd | 2013-09-03 13:20:48 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Anna Zaks | 2249049 | 2015-02-27 03:12:19 +0000 | [diff] [blame] | 298 | uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { |
| 299 | // Nothing here for now. |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | bool IsPathSeparator(const char c) { |
| 304 | return c == '\\' || c == '/'; |
| 305 | } |
| 306 | |
| 307 | bool IsAbsolutePath(const char *path) { |
| 308 | UNIMPLEMENTED(); |
| 309 | } |
| 310 | |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 311 | void SleepForSeconds(int seconds) { |
| 312 | Sleep(seconds * 1000); |
| 313 | } |
| 314 | |
Alexey Samsonov | 58a3c58 | 2012-06-18 08:44:30 +0000 | [diff] [blame] | 315 | void SleepForMillis(int millis) { |
| 316 | Sleep(millis); |
| 317 | } |
| 318 | |
Dmitry Vyukov | e979c54 | 2013-06-10 10:02:02 +0000 | [diff] [blame] | 319 | u64 NanoTime() { |
| 320 | return 0; |
| 321 | } |
| 322 | |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 323 | void Abort() { |
Timur Iskhodzhanov | b8373bc | 2014-12-26 12:25:54 +0000 | [diff] [blame] | 324 | if (::IsDebuggerPresent()) |
| 325 | __debugbreak(); |
| 326 | internal__exit(3); |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Alexey Samsonov | 7a36e61 | 2013-09-10 14:36:16 +0000 | [diff] [blame] | 329 | uptr GetListOfModules(LoadedModule *modules, uptr max_modules, |
| 330 | string_predicate_t filter) { |
Timur Iskhodzhanov | b97bcc4 | 2015-04-06 12:49:30 +0000 | [diff] [blame] | 331 | HANDLE cur_process = GetCurrentProcess(); |
| 332 | |
| 333 | // Query the list of modules. Start by assuming there are no more than 256 |
| 334 | // modules and retry if that's not sufficient. |
| 335 | HMODULE *hmodules = 0; |
| 336 | uptr modules_buffer_size = sizeof(HMODULE) * 256; |
| 337 | DWORD bytes_required; |
| 338 | while (!hmodules) { |
| 339 | hmodules = (HMODULE *)MmapOrDie(modules_buffer_size, __FUNCTION__); |
| 340 | CHECK(EnumProcessModules(cur_process, hmodules, modules_buffer_size, |
| 341 | &bytes_required)); |
| 342 | if (bytes_required > modules_buffer_size) { |
| 343 | // Either there turned out to be more than 256 hmodules, or new hmodules |
| 344 | // could have loaded since the last try. Retry. |
| 345 | UnmapOrDie(hmodules, modules_buffer_size); |
| 346 | hmodules = 0; |
| 347 | modules_buffer_size = bytes_required; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // |num_modules| is the number of modules actually present, |
| 352 | // |count| is the number of modules we return. |
| 353 | size_t nun_modules = bytes_required / sizeof(HMODULE), |
| 354 | count = 0; |
| 355 | for (size_t i = 0; i < nun_modules && count < max_modules; ++i) { |
| 356 | HMODULE handle = hmodules[i]; |
| 357 | MODULEINFO mi; |
| 358 | if (!GetModuleInformation(cur_process, handle, &mi, sizeof(mi))) |
| 359 | continue; |
| 360 | |
| 361 | char module_name[MAX_PATH]; |
| 362 | bool got_module_name = |
| 363 | GetModuleFileNameA(handle, module_name, sizeof(module_name)); |
| 364 | if (!got_module_name) |
| 365 | module_name[0] = '\0'; |
| 366 | |
| 367 | if (filter && !filter(module_name)) |
| 368 | continue; |
| 369 | |
| 370 | uptr base_address = (uptr)mi.lpBaseOfDll; |
| 371 | uptr end_address = (uptr)mi.lpBaseOfDll + mi.SizeOfImage; |
| 372 | LoadedModule *cur_module = &modules[count]; |
| 373 | cur_module->set(module_name, base_address); |
| 374 | // We add the whole module as one single address range. |
| 375 | cur_module->addAddressRange(base_address, end_address, /*executable*/ true); |
| 376 | count++; |
| 377 | } |
| 378 | UnmapOrDie(hmodules, modules_buffer_size); |
| 379 | |
| 380 | return count; |
Alexey Samsonov | 7a36e61 | 2013-09-10 14:36:16 +0000 | [diff] [blame] | 381 | }; |
| 382 | |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 383 | #ifndef SANITIZER_GO |
Timur Iskhodzhanov | ad3ec82 | 2015-04-02 14:48:08 +0000 | [diff] [blame] | 384 | // We can't use atexit() directly at __asan_init time as the CRT is not fully |
| 385 | // initialized at this point. Place the functions into a vector and use |
| 386 | // atexit() as soon as it is ready for use (i.e. after .CRT$XIC initializers). |
| 387 | InternalMmapVectorNoCtor<void (*)(void)> atexit_functions; |
| 388 | |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 389 | int Atexit(void (*function)(void)) { |
Timur Iskhodzhanov | ad3ec82 | 2015-04-02 14:48:08 +0000 | [diff] [blame] | 390 | atexit_functions.push_back(function); |
| 391 | return 0; |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 392 | } |
Timur Iskhodzhanov | ad3ec82 | 2015-04-02 14:48:08 +0000 | [diff] [blame] | 393 | |
| 394 | static int RunAtexit() { |
| 395 | int ret = 0; |
| 396 | for (uptr i = 0; i < atexit_functions.size(); ++i) { |
| 397 | ret |= atexit(atexit_functions[i]); |
| 398 | } |
| 399 | return ret; |
| 400 | } |
| 401 | |
| 402 | #pragma section(".CRT$XID", long, read) // NOLINT |
| 403 | static __declspec(allocate(".CRT$XID")) int (*__run_atexit)() = RunAtexit; |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 404 | #endif |
Alexey Samsonov | 70afb91 | 2012-06-15 06:37:34 +0000 | [diff] [blame] | 405 | |
Alexey Samsonov | 4b1f103 | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 406 | // ------------------ sanitizer_libc.h |
Timur Iskhodzhanov | 864308a | 2015-04-09 12:37:05 +0000 | [diff] [blame] | 407 | fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *last_error) { |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 408 | if (mode != WrOnly) |
| 409 | UNIMPLEMENTED(); |
| 410 | fd_t res = CreateFile(filename, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, |
| 411 | FILE_ATTRIBUTE_NORMAL, nullptr); |
| 412 | CHECK(res != kStdoutFd || kStdoutFd == kInvalidFd); |
| 413 | CHECK(res != kStderrFd || kStderrFd == kInvalidFd); |
Timur Iskhodzhanov | 8a67368 | 2015-04-23 12:57:29 +0000 | [diff] [blame] | 414 | if (res == kInvalidFd && last_error) |
| 415 | *last_error = GetLastError(); |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 416 | return res; |
Alexey Samsonov | 03c8b84 | 2012-06-05 08:32:53 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Timur Iskhodzhanov | 864308a | 2015-04-09 12:37:05 +0000 | [diff] [blame] | 419 | void CloseFile(fd_t fd) { |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 420 | CloseHandle(fd); |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Timur Iskhodzhanov | 2b39169 | 2015-04-09 13:38:14 +0000 | [diff] [blame] | 423 | bool ReadFromFile(fd_t fd, void *buff, uptr buff_size, uptr *bytes_read, |
| 424 | error_t *error_p) { |
| 425 | UNIMPLEMENTED(); |
| 426 | } |
| 427 | |
Timur Iskhodzhanov | c2c9ea5 | 2015-04-08 17:42:57 +0000 | [diff] [blame] | 428 | bool SupportsColoredOutput(fd_t fd) { |
| 429 | // FIXME: support colored output. |
| 430 | return false; |
| 431 | } |
| 432 | |
Timur Iskhodzhanov | e8a6fbb | 2015-04-09 14:11:25 +0000 | [diff] [blame] | 433 | bool WriteToFile(fd_t fd, const void *buff, uptr buff_size, uptr *bytes_written, |
| 434 | error_t *error_p) { |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 435 | CHECK(fd != kInvalidFd); |
Timur Iskhodzhanov | aeefb6a | 2014-02-04 23:28:30 +0000 | [diff] [blame] | 436 | |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 437 | if (fd == kStdoutFd) { |
| 438 | fd = GetStdHandle(STD_OUTPUT_HANDLE); |
| 439 | if (fd == 0) fd = kInvalidFd; |
| 440 | } else if (fd == kStderrFd) { |
| 441 | fd = GetStdHandle(STD_ERROR_HANDLE); |
| 442 | if (fd == 0) fd = kInvalidFd; |
Timur Iskhodzhanov | aeefb6a | 2014-02-04 23:28:30 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Timur Iskhodzhanov | e8a6fbb | 2015-04-09 14:11:25 +0000 | [diff] [blame] | 445 | DWORD internal_bytes_written; |
Timur Iskhodzhanov | 007435c | 2015-04-09 15:25:21 +0000 | [diff] [blame] | 446 | if (fd == kInvalidFd || |
| 447 | WriteFile(fd, buff, buff_size, &internal_bytes_written, 0)) { |
| 448 | if (error_p) *error_p = GetLastError(); |
| 449 | return false; |
| 450 | } else { |
Timur Iskhodzhanov | e8a6fbb | 2015-04-09 14:11:25 +0000 | [diff] [blame] | 451 | if (bytes_written) *bytes_written = internal_bytes_written; |
| 452 | return true; |
| 453 | } |
Alexey Samsonov | 03c8b84 | 2012-06-05 08:32:53 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Timur Iskhodzhanov | a6600a9 | 2015-04-09 14:45:17 +0000 | [diff] [blame] | 456 | bool RenameFile(const char *oldpath, const char *newpath, error_t *error_p) { |
| 457 | UNIMPLEMENTED(); |
| 458 | } |
| 459 | |
Peter Collingbourne | 6f4be19 | 2013-05-08 14:43:49 +0000 | [diff] [blame] | 460 | uptr internal_sched_yield() { |
Dmitry Vyukov | 0ff6d2d | 2012-11-06 13:19:59 +0000 | [diff] [blame] | 461 | Sleep(0); |
| 462 | return 0; |
Alexey Samsonov | 58a3c58 | 2012-06-18 08:44:30 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Alexey Samsonov | aadd1f2 | 2013-02-20 13:54:32 +0000 | [diff] [blame] | 465 | void internal__exit(int exitcode) { |
Timur Iskhodzhanov | 895392d | 2013-11-26 09:40:39 +0000 | [diff] [blame] | 466 | ExitProcess(exitcode); |
Alexey Samsonov | aadd1f2 | 2013-02-20 13:54:32 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Evgeniy Stepanov | a00ff19 | 2014-05-28 08:26:24 +0000 | [diff] [blame] | 469 | uptr internal_ftruncate(fd_t fd, uptr size) { |
| 470 | UNIMPLEMENTED(); |
| 471 | } |
| 472 | |
Kostya Serebryany | 6c54a6b | 2014-12-09 01:22:59 +0000 | [diff] [blame] | 473 | uptr GetRSS() { |
| 474 | return 0; |
| 475 | } |
| 476 | |
Kostya Serebryany | 43eb773 | 2014-12-16 19:13:01 +0000 | [diff] [blame] | 477 | void *internal_start_thread(void (*func)(void *arg), void *arg) { return 0; } |
Hans Wennborg | 7dd9457 | 2014-12-16 20:46:05 +0000 | [diff] [blame] | 478 | void internal_join_thread(void *th) { } |
Kostya Serebryany | 43eb773 | 2014-12-16 19:13:01 +0000 | [diff] [blame] | 479 | |
Dmitry Vyukov | f22982b | 2013-01-14 07:51:39 +0000 | [diff] [blame] | 480 | // ---------------------- BlockingMutex ---------------- {{{1 |
Dmitry Vyukov | fa67ed4 | 2013-02-04 10:42:38 +0000 | [diff] [blame] | 481 | const uptr LOCK_UNINITIALIZED = 0; |
| 482 | const uptr LOCK_READY = (uptr)-1; |
Dmitry Vyukov | f22982b | 2013-01-14 07:51:39 +0000 | [diff] [blame] | 483 | |
| 484 | BlockingMutex::BlockingMutex(LinkerInitialized li) { |
| 485 | // FIXME: see comments in BlockingMutex::Lock() for the details. |
| 486 | CHECK(li == LINKER_INITIALIZED || owner_ == LOCK_UNINITIALIZED); |
| 487 | |
| 488 | CHECK(sizeof(CRITICAL_SECTION) <= sizeof(opaque_storage_)); |
| 489 | InitializeCriticalSection((LPCRITICAL_SECTION)opaque_storage_); |
| 490 | owner_ = LOCK_READY; |
| 491 | } |
| 492 | |
Alexey Samsonov | a097f7b | 2013-03-14 13:30:56 +0000 | [diff] [blame] | 493 | BlockingMutex::BlockingMutex() { |
| 494 | CHECK(sizeof(CRITICAL_SECTION) <= sizeof(opaque_storage_)); |
| 495 | InitializeCriticalSection((LPCRITICAL_SECTION)opaque_storage_); |
| 496 | owner_ = LOCK_READY; |
| 497 | } |
| 498 | |
Dmitry Vyukov | f22982b | 2013-01-14 07:51:39 +0000 | [diff] [blame] | 499 | void BlockingMutex::Lock() { |
| 500 | if (owner_ == LOCK_UNINITIALIZED) { |
| 501 | // FIXME: hm, global BlockingMutex objects are not initialized?!? |
| 502 | // This might be a side effect of the clang+cl+link Frankenbuild... |
| 503 | new(this) BlockingMutex((LinkerInitialized)(LINKER_INITIALIZED + 1)); |
| 504 | |
| 505 | // FIXME: If it turns out the linker doesn't invoke our |
| 506 | // constructors, we should probably manually Lock/Unlock all the global |
| 507 | // locks while we're starting in one thread to avoid double-init races. |
| 508 | } |
| 509 | EnterCriticalSection((LPCRITICAL_SECTION)opaque_storage_); |
Dmitry Vyukov | 7981ea8 | 2013-02-04 08:07:45 +0000 | [diff] [blame] | 510 | CHECK_EQ(owner_, LOCK_READY); |
Dmitry Vyukov | f22982b | 2013-01-14 07:51:39 +0000 | [diff] [blame] | 511 | owner_ = GetThreadSelf(); |
| 512 | } |
| 513 | |
| 514 | void BlockingMutex::Unlock() { |
Dmitry Vyukov | 7981ea8 | 2013-02-04 08:07:45 +0000 | [diff] [blame] | 515 | CHECK_EQ(owner_, GetThreadSelf()); |
Dmitry Vyukov | f22982b | 2013-01-14 07:51:39 +0000 | [diff] [blame] | 516 | owner_ = LOCK_READY; |
| 517 | LeaveCriticalSection((LPCRITICAL_SECTION)opaque_storage_); |
| 518 | } |
| 519 | |
Alexey Samsonov | db7d965 | 2013-03-11 15:45:20 +0000 | [diff] [blame] | 520 | void BlockingMutex::CheckLocked() { |
| 521 | CHECK_EQ(owner_, GetThreadSelf()); |
| 522 | } |
| 523 | |
Evgeniy Stepanov | 5697b58 | 2013-03-13 08:19:53 +0000 | [diff] [blame] | 524 | uptr GetTlsSize() { |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | void InitTlsSize() { |
| 529 | } |
| 530 | |
Sergey Matveev | 954c6ef1 | 2013-05-07 14:41:43 +0000 | [diff] [blame] | 531 | void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size, |
| 532 | uptr *tls_addr, uptr *tls_size) { |
Dmitry Vyukov | b278f12 | 2013-06-10 10:30:54 +0000 | [diff] [blame] | 533 | #ifdef SANITIZER_GO |
| 534 | *stk_addr = 0; |
| 535 | *stk_size = 0; |
| 536 | *tls_addr = 0; |
| 537 | *tls_size = 0; |
| 538 | #else |
Sergey Matveev | 954c6ef1 | 2013-05-07 14:41:43 +0000 | [diff] [blame] | 539 | uptr stack_top, stack_bottom; |
| 540 | GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom); |
| 541 | *stk_addr = stack_bottom; |
| 542 | *stk_size = stack_top - stack_bottom; |
| 543 | *tls_addr = 0; |
| 544 | *tls_size = 0; |
Dmitry Vyukov | b278f12 | 2013-06-10 10:30:54 +0000 | [diff] [blame] | 545 | #endif |
Sergey Matveev | 954c6ef1 | 2013-05-07 14:41:43 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Dmitry Vyukov | aa8fa60 | 2014-09-01 11:44:59 +0000 | [diff] [blame] | 548 | #if !SANITIZER_GO |
Evgeniy Stepanov | 8eb8204 | 2015-01-22 13:47:12 +0000 | [diff] [blame] | 549 | void BufferedStackTrace::SlowUnwindStack(uptr pc, u32 max_depth) { |
Alexey Samsonov | 3e8467b | 2014-03-04 12:21:28 +0000 | [diff] [blame] | 550 | CHECK_GE(max_depth, 2); |
Sergey Matveev | af179b8 | 2013-05-08 12:45:55 +0000 | [diff] [blame] | 551 | // FIXME: CaptureStackBackTrace might be too slow for us. |
| 552 | // FIXME: Compare with StackWalk64. |
| 553 | // FIXME: Look at LLVMUnhandledExceptionFilter in Signals.inc |
Timur Iskhodzhanov | 1f1c7ec | 2013-11-09 13:59:12 +0000 | [diff] [blame] | 554 | size = CaptureStackBackTrace(2, Min(max_depth, kStackTraceMax), |
| 555 | (void**)trace, 0); |
Timur Iskhodzhanov | 89a346c | 2013-12-10 08:30:39 +0000 | [diff] [blame] | 556 | if (size == 0) |
| 557 | return; |
| 558 | |
Sergey Matveev | af179b8 | 2013-05-08 12:45:55 +0000 | [diff] [blame] | 559 | // Skip the RTL frames by searching for the PC in the stacktrace. |
Timur Iskhodzhanov | 1f1c7ec | 2013-11-09 13:59:12 +0000 | [diff] [blame] | 560 | uptr pc_location = LocatePcInTrace(pc); |
| 561 | PopStackFrames(pc_location); |
Sergey Matveev | af179b8 | 2013-05-08 12:45:55 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Alexey Samsonov | 9c85927 | 2014-10-26 03:35:14 +0000 | [diff] [blame] | 564 | void BufferedStackTrace::SlowUnwindStackWithContext(uptr pc, void *context, |
Evgeniy Stepanov | 8eb8204 | 2015-01-22 13:47:12 +0000 | [diff] [blame] | 565 | u32 max_depth) { |
Timur Iskhodzhanov | 19853dd | 2014-07-11 11:57:41 +0000 | [diff] [blame] | 566 | CONTEXT ctx = *(CONTEXT *)context; |
| 567 | STACKFRAME64 stack_frame; |
| 568 | memset(&stack_frame, 0, sizeof(stack_frame)); |
| 569 | size = 0; |
| 570 | #if defined(_WIN64) |
| 571 | int machine_type = IMAGE_FILE_MACHINE_AMD64; |
| 572 | stack_frame.AddrPC.Offset = ctx.Rip; |
| 573 | stack_frame.AddrFrame.Offset = ctx.Rbp; |
| 574 | stack_frame.AddrStack.Offset = ctx.Rsp; |
| 575 | #else |
| 576 | int machine_type = IMAGE_FILE_MACHINE_I386; |
| 577 | stack_frame.AddrPC.Offset = ctx.Eip; |
| 578 | stack_frame.AddrFrame.Offset = ctx.Ebp; |
| 579 | stack_frame.AddrStack.Offset = ctx.Esp; |
| 580 | #endif |
| 581 | stack_frame.AddrPC.Mode = AddrModeFlat; |
| 582 | stack_frame.AddrFrame.Mode = AddrModeFlat; |
| 583 | stack_frame.AddrStack.Mode = AddrModeFlat; |
| 584 | while (StackWalk64(machine_type, GetCurrentProcess(), GetCurrentThread(), |
| 585 | &stack_frame, &ctx, NULL, &SymFunctionTableAccess64, |
| 586 | &SymGetModuleBase64, NULL) && |
| 587 | size < Min(max_depth, kStackTraceMax)) { |
Hans Wennborg | f89a3f86 | 2014-10-26 19:27:02 +0000 | [diff] [blame] | 588 | trace_buffer[size++] = (uptr)stack_frame.AddrPC.Offset; |
Timur Iskhodzhanov | 19853dd | 2014-07-11 11:57:41 +0000 | [diff] [blame] | 589 | } |
Evgeniy Stepanov | e5a447d | 2014-02-11 13:57:17 +0000 | [diff] [blame] | 590 | } |
Dmitry Vyukov | aa8fa60 | 2014-09-01 11:44:59 +0000 | [diff] [blame] | 591 | #endif // #if !SANITIZER_GO |
Evgeniy Stepanov | e5a447d | 2014-02-11 13:57:17 +0000 | [diff] [blame] | 592 | |
Alexey Samsonov | 3a41ed1 | 2014-12-11 18:30:25 +0000 | [diff] [blame] | 593 | void ReportFile::Write(const char *buffer, uptr length) { |
| 594 | SpinMutexLock l(mu); |
| 595 | ReopenIfNecessary(); |
Timur Iskhodzhanov | e8a6fbb | 2015-04-09 14:11:25 +0000 | [diff] [blame] | 596 | if (!WriteToFile(fd, buffer, length)) { |
Reid Kleckner | d483c07 | 2013-09-05 03:19:57 +0000 | [diff] [blame] | 597 | // stderr may be closed, but we may be able to print to the debugger |
| 598 | // instead. This is the case when launching a program from Visual Studio, |
| 599 | // and the following routine should write to its console. |
| 600 | OutputDebugStringA(buffer); |
| 601 | } |
| 602 | } |
| 603 | |
Alexander Potapenko | d8d490e | 2014-01-28 11:12:29 +0000 | [diff] [blame] | 604 | void SetAlternateSignalStack() { |
| 605 | // FIXME: Decide what to do on Windows. |
| 606 | } |
| 607 | |
| 608 | void UnsetAlternateSignalStack() { |
| 609 | // FIXME: Decide what to do on Windows. |
| 610 | } |
| 611 | |
Alexander Potapenko | ea4a0db | 2014-01-31 15:11:11 +0000 | [diff] [blame] | 612 | void InstallDeadlySignalHandlers(SignalHandlerType handler) { |
| 613 | (void)handler; |
Alexander Potapenko | 789e3e1 | 2014-01-31 13:10:07 +0000 | [diff] [blame] | 614 | // FIXME: Decide what to do on Windows. |
| 615 | } |
| 616 | |
| 617 | bool IsDeadlySignal(int signum) { |
| 618 | // FIXME: Decide what to do on Windows. |
| 619 | return false; |
| 620 | } |
| 621 | |
Alexey Samsonov | 1947bf9 | 2014-09-17 17:56:15 +0000 | [diff] [blame] | 622 | bool IsAccessibleMemoryRange(uptr beg, uptr size) { |
| 623 | // FIXME: Actually implement this function. |
| 624 | return true; |
| 625 | } |
| 626 | |
Dmitry Vyukov | df01bdc | 2015-03-02 17:45:18 +0000 | [diff] [blame] | 627 | SignalContext SignalContext::Create(void *siginfo, void *context) { |
| 628 | EXCEPTION_RECORD *exception_record = (EXCEPTION_RECORD*)siginfo; |
| 629 | CONTEXT *context_record = (CONTEXT*)context; |
| 630 | |
| 631 | uptr pc = (uptr)exception_record->ExceptionAddress; |
| 632 | #ifdef _WIN64 |
| 633 | uptr bp = (uptr)context_record->Rbp; |
| 634 | uptr sp = (uptr)context_record->Rsp; |
| 635 | #else |
| 636 | uptr bp = (uptr)context_record->Ebp; |
| 637 | uptr sp = (uptr)context_record->Esp; |
| 638 | #endif |
| 639 | uptr access_addr = exception_record->ExceptionInformation[1]; |
| 640 | |
| 641 | return SignalContext(context, access_addr, pc, sp, bp); |
| 642 | } |
| 643 | |
Yury Gribov | c019a57 | 2015-06-04 07:29:43 +0000 | [diff] [blame^] | 644 | uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { |
| 645 | // FIXME: Actually implement this function. |
| 646 | CHECK_GT(buf_len, 0); |
| 647 | buf[0] = 0; |
| 648 | return 0; |
| 649 | } |
| 650 | |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 651 | } // namespace __sanitizer |
| 652 | |
| 653 | #endif // _WIN32 |