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 | //===----------------------------------------------------------------------===// |
| 14 | #ifdef _WIN32 |
| 15 | #include <windows.h> |
| 16 | |
| 17 | #include <assert.h> |
| 18 | |
Alexey Samsonov | 5bbf829 | 2012-06-05 14:25:27 +0000 | [diff] [blame] | 19 | #include "sanitizer_internal_defs.h" |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 20 | #include "sanitizer_libc.h" |
| 21 | |
| 22 | #define UNIMPLEMENTED_WIN() assert(false) |
| 23 | |
| 24 | namespace __sanitizer { |
| 25 | |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame^] | 26 | int GetPid() { |
| 27 | return GetProcessId(GetCurrentProcess()); |
| 28 | } |
| 29 | |
| 30 | void *MmapOrDie(uptr size) { |
| 31 | void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
| 32 | if (rv == 0) |
| 33 | RawWrite("Failed to map!\n"); |
| 34 | Die(); |
| 35 | return rv; |
| 36 | } |
| 37 | |
| 38 | void UnmapOrDie(void *addr, uptr size) { |
| 39 | // FIXME: Use CHECK here. |
| 40 | RAW_CHECK(VirtualFree(addr, size, MEM_DECOMMIT)); |
| 41 | } |
| 42 | |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 43 | void *internal_mmap(void *addr, uptr length, int prot, int flags, |
| 44 | int fd, u64 offset) { |
| 45 | UNIMPLEMENTED_WIN(); |
| 46 | return 0; |
| 47 | } |
| 48 | |
Alexey Samsonov | 7ac77d6 | 2012-06-05 09:49:25 +0000 | [diff] [blame] | 49 | int internal_munmap(void *addr, uptr length) { |
| 50 | UNIMPLEMENTED_WIN(); |
| 51 | return 0; |
| 52 | } |
| 53 | |
Alexey Samsonov | 03c8b84 | 2012-06-05 08:32:53 +0000 | [diff] [blame] | 54 | int internal_close(fd_t fd) { |
| 55 | UNIMPLEMENTED_WIN(); |
| 56 | return 0; |
| 57 | } |
| 58 | |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 59 | fd_t internal_open(const char *filename, bool write) { |
| 60 | UNIMPLEMENTED_WIN(); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Alexey Samsonov | 03c8b84 | 2012-06-05 08:32:53 +0000 | [diff] [blame] | 64 | uptr internal_read(fd_t fd, void *buf, uptr count) { |
| 65 | UNIMPLEMENTED_WIN(); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | uptr internal_write(fd_t fd, const void *buf, uptr count) { |
| 70 | if (fd != 2) { |
| 71 | UNIMPLEMENTED_WIN(); |
| 72 | return 0; |
| 73 | } |
| 74 | HANDLE err = GetStdHandle(STD_ERROR_HANDLE); |
| 75 | if (err == 0) |
| 76 | return 0; // FIXME: this might not work on some apps. |
| 77 | DWORD ret; |
| 78 | if (!WriteFile(err, buf, count, &ret, 0)) |
| 79 | return 0; |
| 80 | return ret; |
| 81 | } |
| 82 | |
Alexey Samsonov | ca2b5d7 | 2012-06-06 07:30:33 +0000 | [diff] [blame] | 83 | uptr internal_filesize(fd_t fd) { |
| 84 | UNIMPLEMENTED_WIN(); |
| 85 | return -1; |
| 86 | } |
| 87 | |
| 88 | int internal_dup2(int oldfd, int newfd) { |
| 89 | UNIMPLEMENTED_WIN(); |
| 90 | return -1; |
| 91 | } |
| 92 | |
Alexey Samsonov | 7ac77d6 | 2012-06-05 09:49:25 +0000 | [diff] [blame] | 93 | int internal_sscanf(const char *str, const char *format, ...) { |
| 94 | UNIMPLEMENTED_WIN(); |
| 95 | return -1; |
| 96 | } |
| 97 | |
Alexey Samsonov | dde1f11 | 2012-06-05 07:05:10 +0000 | [diff] [blame] | 98 | } // namespace __sanitizer |
| 99 | |
| 100 | #endif // _WIN32 |