1 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_BASE_WIN32_HEADERS_H_ 6 #define V8_BASE_WIN32_HEADERS_H_ 7 8 // This file contains defines and typedefs that allow popular Windows types to 9 // be used without the overhead of including windows.h. 10 // This file no longer includes windows.h but it still sets the defines that 11 // tell windows.h to omit some includes so that the V8 source files that do 12 // include windows.h will still get the minimal version. 13 14 #ifndef WIN32_LEAN_AND_MEAN 15 // WIN32_LEAN_AND_MEAN implies NOCRYPT and NOGDI. 16 #define WIN32_LEAN_AND_MEAN 17 #endif 18 #ifndef NOMINMAX 19 #define NOMINMAX 20 #endif 21 #ifndef NOKERNEL 22 #define NOKERNEL 23 #endif 24 #ifndef NOUSER 25 #define NOUSER 26 #endif 27 #ifndef NOSERVICE 28 #define NOSERVICE 29 #endif 30 #ifndef NOSOUND 31 #define NOSOUND 32 #endif 33 #ifndef NOMCX 34 #define NOMCX 35 #endif 36 #ifndef _WIN32_WINNT 37 #error This should be set in build config files. See build\config\win\BUILD.gn 38 #endif 39 40 #include <signal.h> // For raise(). 41 #include <time.h> // For LocalOffset() implementation. 42 #if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) 43 #include <errno.h> // For STRUNCATE 44 #endif // !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) 45 #include <limits.h> // For INT_MAX and al. 46 #include <process.h> // For _beginthreadex(). 47 #include <stdlib.h> 48 49 // typedef and define the most commonly used Windows integer types. 50 51 typedef int BOOL; // NOLINT(runtime/int) 52 typedef unsigned long DWORD; // NOLINT(runtime/int) 53 typedef long LONG; // NOLINT(runtime/int) 54 typedef void* LPVOID; 55 typedef void* PVOID; 56 typedef void* HANDLE; 57 58 #define WINAPI __stdcall 59 60 #if defined(_WIN64) 61 typedef unsigned __int64 ULONG_PTR, *PULONG_PTR; 62 #else 63 typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR; // NOLINT(runtime/int) 64 #endif 65 66 typedef struct _RTL_SRWLOCK SRWLOCK; 67 typedef struct _RTL_CONDITION_VARIABLE CONDITION_VARIABLE; 68 typedef struct _RTL_CRITICAL_SECTION CRITICAL_SECTION; 69 typedef struct _RTL_CRITICAL_SECTION_DEBUG* PRTL_CRITICAL_SECTION_DEBUG; 70 71 // Declare V8 versions of some Windows structures. These are needed for 72 // when we need a concrete type but don't want to pull in Windows.h. We can't 73 // declare the Windows types so we declare our types and cast to the Windows 74 // types in a few places. The sizes must match the Windows types so we verify 75 // that with static asserts in platform-win32.cc. 76 // ChromeToWindowsType functions are provided for pointer conversions. 77 78 struct V8_SRWLOCK { 79 PVOID Ptr; 80 }; 81 82 struct V8_CONDITION_VARIABLE { 83 PVOID Ptr; 84 }; 85 86 struct V8_CRITICAL_SECTION { 87 PRTL_CRITICAL_SECTION_DEBUG DebugInfo; 88 LONG LockCount; 89 LONG RecursionCount; 90 HANDLE OwningThread; 91 HANDLE LockSemaphore; 92 ULONG_PTR SpinCount; 93 }; 94 V8ToWindowsType(V8_SRWLOCK * p)95inline SRWLOCK* V8ToWindowsType(V8_SRWLOCK* p) { 96 return reinterpret_cast<SRWLOCK*>(p); 97 } 98 V8ToWindowsType(const V8_SRWLOCK * p)99inline const SRWLOCK* V8ToWindowsType(const V8_SRWLOCK* p) { 100 return reinterpret_cast<const SRWLOCK*>(p); 101 } 102 V8ToWindowsType(V8_CONDITION_VARIABLE * p)103inline CONDITION_VARIABLE* V8ToWindowsType(V8_CONDITION_VARIABLE* p) { 104 return reinterpret_cast<CONDITION_VARIABLE*>(p); 105 } 106 V8ToWindowsType(const V8_CONDITION_VARIABLE * p)107inline const CONDITION_VARIABLE* V8ToWindowsType( 108 const V8_CONDITION_VARIABLE* p) { 109 return reinterpret_cast<const CONDITION_VARIABLE*>(p); 110 } 111 V8ToWindowsType(V8_CRITICAL_SECTION * p)112inline CRITICAL_SECTION* V8ToWindowsType(V8_CRITICAL_SECTION* p) { 113 return reinterpret_cast<CRITICAL_SECTION*>(p); 114 } 115 V8ToWindowsType(const V8_CRITICAL_SECTION * p)116inline const CRITICAL_SECTION* V8ToWindowsType(const V8_CRITICAL_SECTION* p) { 117 return reinterpret_cast<const CRITICAL_SECTION*>(p); 118 } 119 120 #endif // V8_BASE_WIN32_HEADERS_H_ 121