blob: 09ad8a985f77e4082f3fed134d85fb8636b1f249 [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
26void *MmapOrDie(uptr size) {
27 void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
28 if (rv == 0)
29 RawWrite("Failed to map!\n");
30 Die();
31 return rv;
32}
33
34void UnmapOrDie(void *addr, uptr size) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000035 if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) {
36 RawWrite("Failed to unmap!\n");
37 Die();
38 }
Alexey Samsonovee072902012-06-06 09:26:25 +000039}
40
Alexey Samsonovdde1f112012-06-05 07:05:10 +000041void *internal_mmap(void *addr, uptr length, int prot, int flags,
42 int fd, u64 offset) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000043 UNIMPLEMENTED();
Alexey Samsonovdde1f112012-06-05 07:05:10 +000044}
45
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000046int internal_munmap(void *addr, uptr length) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000047 UNIMPLEMENTED();
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000048}
49
Alexey Samsonov03c8b842012-06-05 08:32:53 +000050int internal_close(fd_t fd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000051 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000052}
53
Alexey Samsonovdde1f112012-06-05 07:05:10 +000054fd_t internal_open(const char *filename, bool write) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000055 UNIMPLEMENTED();
Alexey Samsonovdde1f112012-06-05 07:05:10 +000056}
57
Alexey Samsonov03c8b842012-06-05 08:32:53 +000058uptr internal_read(fd_t fd, void *buf, uptr count) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000059 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000060}
61
62uptr internal_write(fd_t fd, const void *buf, uptr count) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000063 if (fd != 2)
64 UNIMPLEMENTED();
Alexey Samsonov03c8b842012-06-05 08:32:53 +000065 HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
66 if (err == 0)
67 return 0; // FIXME: this might not work on some apps.
68 DWORD ret;
69 if (!WriteFile(err, buf, count, &ret, 0))
70 return 0;
71 return ret;
72}
73
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000074uptr internal_filesize(fd_t fd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000075 UNIMPLEMENTED();
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000076}
77
78int internal_dup2(int oldfd, int newfd) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000079 UNIMPLEMENTED();
Alexey Samsonovca2b5d72012-06-06 07:30:33 +000080}
81
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000082int internal_sscanf(const char *str, const char *format, ...) {
Alexey Samsonove95e29c2012-06-06 15:47:40 +000083 UNIMPLEMENTED();
Alexey Samsonov7ac77d62012-06-05 09:49:25 +000084}
85
Alexey Samsonovdde1f112012-06-05 07:05:10 +000086} // namespace __sanitizer
87
88#endif // _WIN32