blob: db16d857dc42d3e2df300aa2a075bd31377a6bea [file] [log] [blame]
Alexey Samsonov298dd7c2012-06-05 07:46:31 +00001//===-- sanitizer_win.cc --------------------------------------------------===//
Alexey Samsonovdde1f112012-06-05 07:05:10 +00002//
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
Alexey Samsonov201aa362012-06-06 09:43:32 +000017#include "sanitizer_common.h"
Alexey Samsonovdde1f112012-06-05 07:05:10 +000018#include "sanitizer_libc.h"
19
Alexey Samsonovdde1f112012-06-05 07:05:10 +000020namespace __sanitizer {
21
Alexey Samsonovee072902012-06-06 09:26:25 +000022int GetPid() {
23 return GetProcessId(GetCurrentProcess());
24}
25
Alexey Samsonov40d5b772012-06-06 16:15:07 +000026void *MmapOrDie(uptr size, const char *mem_type) {
Alexey Samsonovee072902012-06-06 09:26:25 +000027 void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
Alexey Samsonov40d5b772012-06-06 16:15:07 +000028 if (rv == 0) {
29 Report("ERROR: Failed to allocate 0x%zx (%zd) bytes of %s\n",
30 size, size, mem_type);
31 CHECK("unable to mmap" && 0);
32 }
Alexey Samsonovee072902012-06-06 09:26:25 +000033 return rv;
34}
35
36void UnmapOrDie(void *addr, uptr size) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000037 if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) {
Alexey Samsonov40d5b772012-06-06 16:15:07 +000038 Report("ERROR: Failed to deallocate 0x%zx (%zd) bytes at address %p\n",
39 size, size, addr);
40 CHECK("unable to unmap" && 0);
Alexey Samsonove95e29c2012-06-06 15:47:40 +000041 }
Alexey Samsonovee072902012-06-06 09:26:25 +000042}
43
Alexey Samsonovdde1f112012-06-05 07:05:10 +000044void *internal_mmap(void *addr, uptr length, int prot, int flags,
45 int fd, u64 offset) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000046 UNIMPLEMENTED();
Alexey Samsonovdde1f112012-06-05 07:05:10 +000047}
48
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000049int internal_munmap(void *addr, uptr length) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000050 UNIMPLEMENTED();
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000051}
52
Alexey Samsonov03c8b842012-06-05 08:32:53 +000053int internal_close(fd_t fd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000054 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000055}
56
Alexey Samsonovdde1f112012-06-05 07:05:10 +000057fd_t internal_open(const char *filename, bool write) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000058 UNIMPLEMENTED();
Alexey Samsonovdde1f112012-06-05 07:05:10 +000059}
60
Alexey Samsonov03c8b842012-06-05 08:32:53 +000061uptr internal_read(fd_t fd, void *buf, uptr count) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000062 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000063}
64
65uptr internal_write(fd_t fd, const void *buf, uptr count) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000066 if (fd != 2)
67 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000068 HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
69 if (err == 0)
70 return 0; // FIXME: this might not work on some apps.
71 DWORD ret;
72 if (!WriteFile(err, buf, count, &ret, 0))
73 return 0;
74 return ret;
75}
76
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000077uptr internal_filesize(fd_t fd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000078 UNIMPLEMENTED();
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000079}
80
81int internal_dup2(int oldfd, int newfd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000082 UNIMPLEMENTED();
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000083}
84
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000085int internal_sscanf(const char *str, const char *format, ...) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000086 UNIMPLEMENTED();
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000087}
88
Alexey Samsonovdde1f112012-06-05 07:05:10 +000089} // namespace __sanitizer
90
91#endif // _WIN32