boinc_win.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. // boinc_win.h : include file for Windows builds.
  18. // Includes standard system include files,
  19. // and aliases function names like getpid -> _getpid
  20. //
  21. // ?? Is this only for Visual Studio, or for MINGW too?
  22. // comments below are contradictory
  23. #ifndef BOINC_BOINC_WIN_H
  24. #define BOINC_BOINC_WIN_H
  25. #ifdef _MSC_VER
  26. #pragma warning(disable: 4996) // deprecated function names
  27. #pragma warning(disable: 4127) // constant conditional expression
  28. #pragma warning(disable: 4244) // conversion from int to char
  29. #define chdir _chdir
  30. #define getpid _getpid
  31. #define getcwd _getcwd
  32. #define strdate _strdate
  33. #define strdup _strdup
  34. #define stricmp _stricmp
  35. #define strtime _strtime
  36. #if _MSC_VER < 1900
  37. #define snprintf _snprintf
  38. #endif
  39. #endif
  40. #ifdef __MINGW32__
  41. #define strdate _strdate
  42. #define strtime _strtime
  43. #endif
  44. #ifndef HAVE_CONFIG_H
  45. // Windows C Runtime Library
  46. // These are Visual Studio version dependent.
  47. // If you aren't using VS, you'll probably need
  48. // to edit this file or create a config.h
  49. // For MINGW32 and MINGW64, it's best to run autoconf if possible.
  50. #ifndef HAVE_STD_MAX
  51. #define HAVE_STD_MAX 1
  52. #endif
  53. #ifndef HAVE_STD_MIN
  54. #define HAVE_STD_MIN 1
  55. #endif
  56. #ifndef HAVE_STD_TRANSFORM
  57. #define HAVE_STD_TRANSFORM 1
  58. #endif
  59. #ifndef HAVE_ALLOCA
  60. #define HAVE_ALLOCA 1
  61. #endif
  62. #ifdef __MINGW32__
  63. #define HAVE_STRCASECMP 1
  64. #endif
  65. /*
  66. * WINSOCK vs WINSOCK2 could be an issue in compiles because we include multiple
  67. * packages that have the same choice. The wx currently packed with BOINC
  68. * uses WINSOCK, so we have to not include WINSOCK2 by undefining
  69. * HAVE_WINSOCK2_H. That limits what CURL in its header file as well. We might
  70. * need something more complicated if CURL and wxWidgets decide to go in
  71. * opposite directions.
  72. */
  73. #define USE_WINSOCK 1
  74. #undef HAVE_WINSOCK2_H
  75. #define HAVE_WINSOCK_H 1
  76. #define HAVE_WINDOWS_H 1
  77. #define HAVE_WS2TCPIP_H 1
  78. #define HAVE_WINHTTP_H 1
  79. #define HAVE_WINTERNL_H 1
  80. #define HAVE_DELAYIMP_H 1
  81. #define HAVE_INTRIN_H 1
  82. #define HAVE_FCNTL_H 1
  83. #define HAVE_CRTDBG_H 1
  84. #define HAVE_DECL_FPRESET 1
  85. #define HAVE_DECL__FPRESET 1
  86. #define HAVE_DECL___CPUID 1
  87. #define HAVE_MSVCRT 1
  88. #define HAVE__CONFIGTHREADLOCALE 1
  89. #define HAVE_DECL___CPUID 1
  90. #if ( _MSC_FULL_VER >= 160040219 )
  91. #define HAVE_DECL__XGETBV 1
  92. #else
  93. #define HAVE_DECL__XGETBV 0
  94. #endif
  95. #else
  96. // Under any system that can run configure we need to include config.h first.
  97. #include "config.h"
  98. #endif
  99. // Windows System Libraries
  100. //
  101. // Visual Studio 2005 has extended the C Run-Time Library by including "secure"
  102. // runtime functions and deprecating the previous function prototypes. Since
  103. // we need to use the previous prototypes to maintain compatibility with other
  104. // platforms we are going to disable the deprecation warnings if we are compiling
  105. // on Visual Studio 2005
  106. #if _MSC_VER >= 1400
  107. #ifndef _CRT_SECURE_NO_DEPRECATE
  108. #define _CRT_SECURE_NO_DEPRECATE
  109. #endif
  110. #ifndef _CRT_SECURE_NO_WARNINGS
  111. #define _CRT_SECURE_NO_WARNINGS
  112. #endif
  113. #endif
  114. // Target Windows XP or better with Internet Explorer 5.01 or better
  115. #ifndef WINVER
  116. #define WINVER 0x0501
  117. #endif
  118. #ifndef _WIN32_WINNT
  119. #define _WIN32_WINNT 0x0501
  120. #endif
  121. #ifndef _WIN32_WINDOWS
  122. #define _WIN32_WINDOWS 0x0501
  123. #endif
  124. #ifndef _WIN32_IE
  125. #define _WIN32_IE 0x0501
  126. #endif
  127. #ifndef SECURITY_WIN32
  128. #define SECURITY_WIN32
  129. #endif
  130. #if !defined(__CYGWIN32__) || defined(USE_WINSOCK)
  131. /* If we're not running under CYGWIN use windows networking */
  132. #undef USE_WINSOCK
  133. #define USE_WINSOCK 1
  134. /* wxWidgets doesn't do winsock 2, so ignore it for now */
  135. #ifdef HAVE_WINSOCK2_H
  136. #include <winsock2.h>
  137. #elif defined(HAVE_WINSOCK_H)
  138. #include <winsock.h>
  139. #endif
  140. #ifndef HAVE_SOCKLEN_T
  141. typedef size_t socklen_t;
  142. #endif
  143. #else
  144. /* Under cygwin, curl was probably compiled to use <sys/socket.h> */
  145. #include <unistd.h>
  146. #include <sys/types.h>
  147. #include <sys/socket.h>
  148. #include <netinet/in.h>
  149. #include <netinet/tcp.h>
  150. #include <arpa/inet.h>
  151. #include <netdb.h>
  152. #define _WINSOCK_H
  153. #define _WINSOCKAPI_
  154. #define _WINSOCK2_H
  155. #define _WININET_H
  156. #define _WININETAPI_
  157. #endif
  158. #include <windows.h>
  159. #ifdef HAVE_WINTERNL_H
  160. #include <winternl.h>
  161. #endif
  162. #include <share.h>
  163. #include <shlobj.h>
  164. #include <userenv.h>
  165. #ifdef HAVE_WINHTTP_H
  166. #include <winhttp.h>
  167. #endif
  168. #include <aclapi.h>
  169. #include <psapi.h>
  170. #include <iphlpapi.h>
  171. #include <wtsapi32.h>
  172. #include <process.h>
  173. #if defined(__MINGW32__) || defined(__CYGWIN32__)
  174. #include <pbt.h>
  175. #endif
  176. #include <commctrl.h>
  177. #include <raserror.h>
  178. #if defined(__MINGW32__)
  179. #include <stdint.h>
  180. #ifdef HAVE_SECURITY_H
  181. #include <security.h>
  182. #endif
  183. #ifdef HAVE_DBGHELP_H
  184. #include <dbghelp.h>
  185. #endif
  186. #include <imagehlp.h>
  187. #else
  188. #include <security.h>
  189. #include <dbghelp.h>
  190. #endif
  191. #include <tlhelp32.h>
  192. #include <io.h>
  193. #if !defined(__CYGWIN32__)
  194. #include <direct.h>
  195. #endif
  196. #if !defined(__CYGWIN32__)
  197. #include <tchar.h>
  198. #else
  199. #ifndef _TCHAR_DEFINED
  200. typedef char TCHAR, *PTCHAR;
  201. typedef unsigned char TBYTE , *PTBYTE ;
  202. #define _TCHAR_DEFINED
  203. #endif /* !_TCHAR_DEFINED */
  204. typedef LPSTR LPTCH, PTCH;
  205. typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
  206. typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
  207. #define __TEXT(quote) quote
  208. #endif
  209. // All projects should be using std::min and std::max instead of the Windows
  210. // version of the symbols.
  211. #undef min
  212. #undef max
  213. // Standard Libraries
  214. //
  215. // C headers
  216. #include <sys/stat.h>
  217. #include <sys/types.h>
  218. #ifdef HAVE_FCNTL_H
  219. #include <fcntl.h>
  220. #endif
  221. #include <malloc.h>
  222. #ifdef HAVE_CRTDBG_H
  223. #include <crtdbg.h>
  224. #endif
  225. #if defined(HAVE_DELAYIMP_H)
  226. #include <delayimp.h>
  227. #endif
  228. #if defined(__MINGW32__) && !defined(HAVE_WINTERNL_H)
  229. #ifdef HAVE_NTAPI_H
  230. #include <ntapi.h>
  231. #elif defined(HAVE_DDK_NTAPI_H)
  232. #include <ddk/ntapi.h>
  233. #endif
  234. #endif
  235. #ifdef __cplusplus
  236. #include <algorithm>
  237. #include <cassert>
  238. #include <cctype>
  239. #include <cerrno>
  240. #include <cmath>
  241. #include <csetjmp>
  242. #include <csignal>
  243. #include <cstdarg>
  244. #include <cstdlib>
  245. #include <cstdio>
  246. #include <cstring>
  247. #include <ctime>
  248. #include <cfloat>
  249. #include <locale>
  250. #else
  251. #include <assert.h>
  252. #include <ctype.h>
  253. #include <errno.h>
  254. #include <math.h>
  255. #include <setjmp.h>
  256. #include <signal.h>
  257. #include <stdarg.h>
  258. #include <stdio.h>
  259. #include <stdlib.h>
  260. #include <string.h>
  261. #include <time.h>
  262. #include <float.h>
  263. #include <locale.h>
  264. #endif
  265. // C++ headers
  266. //
  267. #ifdef __cplusplus
  268. #include <algorithm>
  269. #include <string>
  270. #include <iostream>
  271. #include <fstream>
  272. #include <sstream>
  273. #include <vector>
  274. #include <deque>
  275. #include <list>
  276. #include <map>
  277. #include <set>
  278. #include <stdexcept>
  279. #endif
  280. // Define a generic string type that can be a Unicode string on
  281. // Unicode builds and an ANSI string on ANSI builds
  282. //
  283. #ifdef _UNICODE
  284. #define tstring std::wstring
  285. #else
  286. #define tstring std::string
  287. #endif
  288. #ifndef SIGRTMAX
  289. #if defined(_SIGRTMAX)
  290. #define SIGRTMAX _SIGRTMAX
  291. #elif defined(NSIG)
  292. #define SIGRTMAX (NSIG-1)
  293. #else
  294. #define SIGRTMAX 32
  295. #endif
  296. #endif
  297. #ifndef __GNUC__
  298. #define __attribute__(x)
  299. #endif
  300. #if defined(__MINGW32__)
  301. #ifdef __cplusplus
  302. extern "C" {
  303. #endif
  304. #ifndef __MINGW_NOTHROW
  305. #define __MINGW_NOTHROW
  306. #endif
  307. #if !HAVE_DECL__FPRESET
  308. void __cdecl __MINGW_NOTHROW _fpreset (void);
  309. #endif
  310. #if !HAVE_DECL_FPRESET
  311. void __cdecl __MINGW_NOTHROW fpreset (void);
  312. #endif
  313. #ifdef __cplusplus
  314. }
  315. #endif //cplusplus
  316. #endif //MINGW32
  317. #if defined(__MINGW32__) && (__GNUC__ < 4)
  318. // breaks build on MinGW gcc-4
  319. #define SetClassLongPtr SetClassLong
  320. #define GCLP_HICON GCL_HICON
  321. #define GCLP_HICONSM GCL_HICONSM
  322. #endif //MINGW32 && GNUC < 4
  323. // On the Win32 platform include file and line number information for each
  324. // memory allocation/deallocation
  325. #ifdef _DEBUG
  326. #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
  327. #define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  328. #define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  329. #define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  330. #define free(p) _free_dbg(p, _NORMAL_BLOCK)
  331. #define _msize(p) _msize_dbg(p, _NORMAL_BLOCK)
  332. #define _aligned_malloc(s, a) _aligned_malloc_dbg(s, a, __FILE__, __LINE__)
  333. #define _aligned_realloc(p, s, a) _aligned_realloc_dbg(p, s, a, __FILE__, __LINE__)
  334. #define _aligned_offset_malloc(s, a, o) _aligned_offset_malloc_dbg(s, a, o, __FILE__, __LINE__)
  335. #define _aligned_offset_realloc(p, s, a, o) _aligned_offset_realloc_dbg(p, s, a, o, __FILE__, __LINE__)
  336. #define _aligned_free(p) _aligned_free_dbg(p)
  337. #ifndef DEBUG_NEW
  338. #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
  339. #endif
  340. // The following macros set and clear, respectively, given bits
  341. // of the C runtime library debug flag, as specified by a bitmask.
  342. #define SET_CRT_DEBUG_FIELD(a) _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  343. #define CLEAR_CRT_DEBUG_FIELD(a) _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  344. #else //_DEBUG
  345. #ifndef DEBUG_NEW
  346. #define DEBUG_NEW new
  347. #endif
  348. #define SET_CRT_DEBUG_FIELD(a) ((void) 0)
  349. #define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
  350. #endif //_DEBUG
  351. #define new DEBUG_NEW
  352. #endif //BOINC_BOINC_WIN_H