1 /* WIN32.H 2 * 3 * (c) 1995 Microsoft Corporation. All rights reserved. 4 * Developed by hip communications inc. 5 * 6 * You may distribute under the terms of either the GNU General Public 7 * License or the Artistic License, as specified in the README file. 8 */ 9 #ifndef _INC_WIN32_PERL5 10 #define _INC_WIN32_PERL5 11 12 #ifndef _WIN32_WINNT 13 # define _WIN32_WINNT 0x0500 /* needed for CreateHardlink() etc. */ 14 #endif 15 16 /* Win32 only optimizations for faster building */ 17 #ifdef PERL_IS_MINIPERL 18 /* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and 19 * makedef.pl create dependencies that will keep Winsock linked in even with 20 * this macro defined, even though sockets will be umimplemented from a script 21 * level in full perl 22 */ 23 # define WIN32_NO_SOCKETS 24 /* less I/O calls during each require */ 25 # define PERL_DISABLE_PMC 26 27 /* unnecessery for miniperl to lookup anything from an "installed" perl */ 28 # define WIN32_NO_REGISTRY 29 30 /* allow minitest to work */ 31 # define PERL_TEXTMODE_SCRIPTS 32 #endif 33 34 #ifdef WIN32_NO_SOCKETS 35 # undef HAS_SOCKET 36 # undef HAS_GETPROTOBYNAME 37 # undef HAS_GETPROTOBYNUMBER 38 # undef HAS_GETPROTOENT 39 # undef HAS_GETNETBYNAME 40 # undef HAS_GETNETBYADDR 41 # undef HAS_GETNETENT 42 # undef HAS_GETSERVBYNAME 43 # undef HAS_GETSERVBYPORT 44 # undef HAS_GETSERVENT 45 # undef HAS_GETHOSTBYNAME 46 # undef HAS_GETHOSTBYADDR 47 # undef HAS_GETHOSTENT 48 # undef HAS_SELECT 49 # undef HAS_IOCTL 50 # undef HAS_NTOHL 51 # undef HAS_HTONL 52 # undef HAS_HTONS 53 # undef HAS_NTOHS 54 # define WIN32SCK_IS_STDSCK 55 #endif 56 57 #if defined(PERL_IMPLICIT_SYS) 58 # define DYNAMIC_ENV_FETCH 59 # define HAS_GETENV_LEN 60 # define prime_env_iter() 61 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */ 62 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */ 63 # ifdef PERL_GLOBAL_STRUCT 64 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS 65 # endif 66 #endif 67 68 #ifdef __GNUC__ 69 # ifndef __int64 /* some versions seem to #define it already */ 70 # define __int64 long long 71 # endif 72 # define Win32_Winsock 73 #endif 74 75 76 /* Define DllExport akin to perl's EXT, 77 * If we are in the DLL then Export the symbol, 78 * otherwise import it. 79 */ 80 81 /* now even GCC supports __declspec() */ 82 /* miniperl has no reason to export anything */ 83 #if defined(PERL_IS_MINIPERL) 84 # define DllExport 85 #else 86 # if defined(PERLDLL) 87 # define DllExport __declspec(dllexport) 88 # else 89 # define DllExport __declspec(dllimport) 90 # endif 91 #endif 92 93 /* The Perl APIs can only be called directly inside the perl5xx.dll. 94 * All other code has to import them. By declaring them as "dllimport" 95 * we tell the compiler to generate an indirect call instruction and 96 * avoid redirection through a call thunk. 97 * 98 * The XS code in the re extension is special, in that it redefines 99 * core APIs locally, so don't mark them as "dllimport" because GCC 100 * cannot handle this situation. 101 * 102 * Certain old GCCs will not allow the function pointer of dllimport marked 103 * function to be "const". This was fixed later on. Since this is a 104 * deoptimization, target "gcc version 3.4.5 (mingw-vista special r3)" only, 105 * The GCC bug was fixed in GCC patch "varasm.c (initializer_constant_valid_p): 106 * Don't deny DECL_DLLIMPORT_P on functions", which probably was first released 107 * in GCC 4.3.0, this #if can be expanded upto but not including 4.3.0 if more 108 * deployed GCC are found that wont build with the follow error, initializer 109 * element is a PerlIO func exported from perl5xx.dll. 110 * 111 * encoding.xs:610: error: initializer element is not constant 112 * encoding.xs:610: error: (near initialization for `PerlIO_encode.Open') 113 */ 114 115 #if (defined(__GNUC__) && defined(__MINGW32__) && \ 116 !defined(__MINGW64_VERSION_MAJOR) && !defined(__clang__) && \ 117 ((__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ <= 5)))) 118 /* use default fallbacks from perl.h for this particular GCC */ 119 #else 120 # if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD) 121 # ifdef __cplusplus 122 # define PERL_CALLCONV extern "C" __declspec(dllimport) 123 # ifdef _MSC_VER 124 # define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn) 125 # endif 126 # else 127 # define PERL_CALLCONV __declspec(dllimport) 128 # ifdef _MSC_VER 129 # define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn) 130 # endif 131 # endif 132 # else /* MSVC noreturn support inside the interp */ 133 # ifdef _MSC_VER 134 # define PERL_CALLCONV_NO_RET __declspec(noreturn) 135 # endif 136 # endif 137 #endif 138 139 #ifdef _MSC_VER 140 # define PERL_STATIC_NO_RET __declspec(noreturn) static 141 # define PERL_STATIC_INLINE_NO_RET __declspec(noreturn) PERL_STATIC_INLINE 142 # define PERL_STATIC_FORCE_INLINE __forceinline static 143 # define PERL_STATIC_FORCE_INLINE_NO_RET __declspec(noreturn) __forceinline static 144 #endif 145 146 #define WIN32_LEAN_AND_MEAN 147 #include <windows.h> 148 149 /* 150 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they 151 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail 152 * to declare GetEnvironmentStringsA. 153 */ 154 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE) 155 #ifdef __cplusplus 156 extern "C" { 157 #endif 158 #undef GetEnvironmentStringsA 159 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID); 160 #define GetEnvironmentStrings GetEnvironmentStringsA 161 #ifdef __cplusplus 162 } 163 #endif 164 #endif 165 166 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */ 167 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */ 168 #endif /*WIN32_LEAN_AND_MEAN */ 169 170 #ifndef TLS_OUT_OF_INDEXES 171 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF 172 #endif 173 174 #include <dirent.h> 175 #include <io.h> 176 #include <process.h> 177 #include <stdio.h> 178 #include <direct.h> 179 #include <stdlib.h> 180 #include <stddef.h> 181 #include <fcntl.h> 182 #ifndef EXT 183 #include "EXTERN.h" 184 #endif 185 186 struct tms { 187 long tms_utime; 188 long tms_stime; 189 long tms_cutime; 190 long tms_cstime; 191 }; 192 193 #ifndef SYS_NMLN 194 #define SYS_NMLN 257 195 #endif 196 197 struct utsname { 198 char sysname[SYS_NMLN]; 199 char nodename[SYS_NMLN]; 200 char release[SYS_NMLN]; 201 char version[SYS_NMLN]; 202 char machine[SYS_NMLN]; 203 }; 204 205 #ifndef START_EXTERN_C 206 #undef EXTERN_C 207 #ifdef __cplusplus 208 # define START_EXTERN_C extern "C" { 209 # define END_EXTERN_C } 210 # define EXTERN_C extern "C" 211 #else 212 # define START_EXTERN_C 213 # define END_EXTERN_C 214 # define EXTERN_C 215 #endif 216 #endif 217 218 #define DOSISH 1 /* no escaping our roots */ 219 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */ 220 221 /* read() and write() aren't transparent for socket handles */ 222 #ifndef WIN32_NO_SOCKETS 223 # define PERL_SOCK_SYSREAD_IS_RECV 224 # define PERL_SOCK_SYSWRITE_IS_SEND 225 #endif 226 227 #ifdef WIN32_NO_REGISTRY 228 /* the last _ in WIN32_NO_REGISTRY_M_ is like the _ in aTHX_ */ 229 # define WIN32_NO_REGISTRY_M_(x) 230 #else 231 # define WIN32_NO_REGISTRY_M_(x) x, 232 #endif 233 234 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */ 235 236 #define ENV_IS_CASELESS 237 238 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */ 239 240 /* access() mode bits */ 241 #ifndef R_OK 242 # define R_OK 4 243 # define W_OK 2 244 # define X_OK 1 245 # define F_OK 0 246 #endif 247 248 /* for waitpid() */ 249 #ifndef WNOHANG 250 # define WNOHANG 1 251 #endif 252 253 #define PERL_GET_CONTEXT_DEFINED 254 255 /* Compiler-specific stuff. */ 256 257 /* VC uses non-standard way to determine the size and alignment if bit-fields */ 258 /* MinGW will compile with -mms-bitfields, so should use the same types */ 259 #define PERL_BITFIELD8 U8 260 #define PERL_BITFIELD16 U16 261 #define PERL_BITFIELD32 U32 262 263 #ifdef _MSC_VER /* Microsoft Visual C++ */ 264 265 typedef long uid_t; 266 typedef long gid_t; 267 typedef unsigned short mode_t; 268 269 #if _MSC_VER < 1800 270 #define isnan _isnan /* Defined already in VC++ 12.0 */ 271 #endif 272 #define snprintf _snprintf 273 #define vsnprintf _vsnprintf 274 275 /* on VS2003, msvcrt.lib is missing these symbols */ 276 #if _MSC_VER >= 1300 && _MSC_VER < 1400 277 # pragma intrinsic(_rotl64,_rotr64) 278 #endif 279 280 MSVC_DIAG_IGNORE(4756 4056) 281 PERL_STATIC_INLINE 282 double S_Infinity() { 283 /* this is a real C literal which can get further constant folded 284 unlike using HUGE_VAL/_HUGE which are data symbol imports from the CRT 285 and therefore can not by folded by VC, an example of constant 286 folding INF is creating -INF */ 287 return (DBL_MAX+DBL_MAX); 288 } 289 MSVC_DIAG_RESTORE 290 291 #define NV_INF S_Infinity() 292 293 /* selectany allows duplicate and unused data symbols to be removed by 294 VC linker, if this were static, each translation unit will have its own, 295 usually unused __PL_nan_u, if this were plain extern it will cause link 296 to fail due to multiple definitions, since we dont know if we are being 297 compiled as static or DLL XS, selectany simply always works, the cost of 298 importing __PL_nan_u across DLL boundaries in size in the importing DLL 299 will be more than the 8 bytes it will take up being in each XS DLL if 300 that DLL actually uses __PL_nan_u */ 301 extern const __declspec(selectany) union { unsigned __int64 __q; double __d; } 302 __PL_nan_u = { 0x7FF8000000000000UI64 }; 303 #define NV_NAN ((NV)__PL_nan_u.__d) 304 305 /* The CRT was rewritten in VS2015. */ 306 #if _MSC_VER >= 1900 307 308 /* No longer declared in stdio.h */ 309 EXTERN_C char *gets(char* buffer); 310 311 #define tzname _tzname 312 313 /* From corecrt_internal_stdio.h: */ 314 typedef struct 315 { 316 union 317 { 318 FILE _public_file; 319 char* _ptr; 320 }; 321 322 char* _base; 323 int _cnt; 324 long _flags; 325 long _file; 326 int _charbuf; 327 int _bufsiz; 328 char* _tmpfname; 329 CRITICAL_SECTION _lock; 330 } __crt_stdio_stream_data; 331 332 #define PERLIO_FILE_flag_RD 0x0001 /* _IOREAD */ 333 #define PERLIO_FILE_flag_WR 0x0002 /* _IOWRITE */ 334 #define PERLIO_FILE_flag_RW 0x0004 /* _IOUPDATE */ 335 #define PERLIO_FILE_ptr(f) (((__crt_stdio_stream_data*)(f))->_ptr) 336 #define PERLIO_FILE_base(f) (((__crt_stdio_stream_data*)(f))->_base) 337 #define PERLIO_FILE_cnt(f) (((__crt_stdio_stream_data*)(f))->_cnt) 338 #define PERLIO_FILE_flag(f) ((int)(((__crt_stdio_stream_data*)(f))->_flags)) 339 #define PERLIO_FILE_file(f) (*(int*)(&((__crt_stdio_stream_data*)(f))->_file)) 340 341 #endif 342 343 #endif /* _MSC_VER */ 344 345 #if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900) 346 347 /* Note: PERLIO_FILE_ptr/base/cnt are not actually used for GCC or <VS2015 348 * since FILE_ptr/base/cnt do the same thing anyway but it doesn't hurt to 349 * define them all here for completeness. */ 350 #define PERLIO_FILE_flag_RD _IOREAD /* 0x001 */ 351 #define PERLIO_FILE_flag_WR _IOWRT /* 0x002 */ 352 #define PERLIO_FILE_flag_RW _IORW /* 0x080 */ 353 #define PERLIO_FILE_ptr(f) ((f)->_ptr) 354 #define PERLIO_FILE_base(f) ((f)->_base) 355 #define PERLIO_FILE_cnt(f) ((f)->_cnt) 356 #define PERLIO_FILE_flag(f) ((f)->_flag) 357 #define PERLIO_FILE_file(f) ((f)->_file) 358 359 #endif 360 361 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */ 362 363 typedef long uid_t; 364 typedef long gid_t; 365 #ifndef _environ 366 #define _environ environ 367 #endif 368 #define flushall _flushall 369 #define fcloseall _fcloseall 370 #ifndef isnan 371 #define isnan _isnan /* ...same libraries as MSVC */ 372 #endif 373 374 #ifndef _O_NOINHERIT 375 # define _O_NOINHERIT 0x0080 376 # ifndef _NO_OLDNAMES 377 # define O_NOINHERIT _O_NOINHERIT 378 # endif 379 #endif 380 381 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's 382 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */ 383 #ifdef _STDINT_H 384 # ifndef _INTPTR_T_DEFINED 385 # define _INTPTR_T_DEFINED 386 # endif 387 # ifndef _UINTPTR_T_DEFINED 388 # define _UINTPTR_T_DEFINED 389 # endif 390 #endif 391 392 #ifndef CP_UTF8 393 # define CP_UTF8 65001 394 #endif 395 396 #endif /* __MINGW32__ */ 397 398 #ifndef _INTPTR_T_DEFINED 399 typedef int intptr_t; 400 # define _INTPTR_T_DEFINED 401 #endif 402 403 #ifndef _UINTPTR_T_DEFINED 404 typedef unsigned int uintptr_t; 405 # define _UINTPTR_T_DEFINED 406 #endif 407 408 START_EXTERN_C 409 410 /* For UNIX compatibility. */ 411 412 #ifdef PERL_CORE 413 extern uid_t getuid(void); 414 extern gid_t getgid(void); 415 extern uid_t geteuid(void); 416 extern gid_t getegid(void); 417 extern int setuid(uid_t uid); 418 extern int setgid(gid_t gid); 419 extern int kill(int pid, int sig); 420 #ifndef USE_PERL_SBRK 421 extern void *sbrk(ptrdiff_t need); 422 # define HAS_SBRK_PROTO 423 #endif 424 extern char * getlogin(void); 425 extern int chown(const char *p, uid_t o, gid_t g); 426 #if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4 427 extern int mkstemp(const char *path); 428 #endif 429 #endif 430 431 #undef Stat 432 #define Stat win32_stat 433 434 #undef init_os_extras 435 #define init_os_extras Perl_init_os_extras 436 437 DllExport void Perl_win32_init(int *argcp, char ***argvp); 438 DllExport void Perl_win32_term(void); 439 DllExport void Perl_init_os_extras(void); 440 DllExport void win32_str_os_error(void *sv, DWORD err); 441 DllExport int RunPerl(int argc, char **argv, char **env); 442 443 typedef struct { 444 HANDLE childStdIn; 445 HANDLE childStdOut; 446 HANDLE childStdErr; 447 /* 448 * the following correspond to the fields of the same name 449 * in the STARTUPINFO structure. Embedders can use these to 450 * control the spawning process' look. 451 * Example - to hide the window of the spawned process: 452 * dwFlags = STARTF_USESHOWWINDOW; 453 * wShowWindow = SW_HIDE; 454 */ 455 DWORD dwFlags; 456 DWORD dwX; 457 DWORD dwY; 458 DWORD dwXSize; 459 DWORD dwYSize; 460 DWORD dwXCountChars; 461 DWORD dwYCountChars; 462 DWORD dwFillAttribute; 463 WORD wShowWindow; 464 } child_IO_table; 465 466 DllExport void win32_get_child_IO(child_IO_table* ptr); 467 DllExport HWND win32_create_message_window(void); 468 DllExport int win32_async_check(pTHX); 469 470 extern int my_fclose(FILE *); 471 extern char * win32_get_privlib(WIN32_NO_REGISTRY_M_(const char *pl) STRLEN *const len); 472 extern char * win32_get_sitelib(const char *pl, STRLEN *const len); 473 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len); 474 475 #ifdef PERL_IMPLICIT_SYS 476 extern void win32_delete_internal_host(void *h); 477 #endif 478 479 extern int win32_get_errno(int err); 480 481 extern const char * const staticlinkmodules[]; 482 483 END_EXTERN_C 484 485 typedef char * caddr_t; /* In malloc.c (core address). */ 486 487 /* 488 * handle socket stuff, assuming socket is always available 489 */ 490 #include <sys/socket.h> 491 #include <netdb.h> 492 493 #ifdef MYMALLOC 494 #define EMBEDMYMALLOC /**/ 495 /* #define USE_PERL_SBRK / **/ 496 /* #define PERL_SBRK_VIA_MALLOC / **/ 497 #endif 498 499 #ifdef PERL_TEXTMODE_SCRIPTS 500 # define PERL_SCRIPT_MODE "r" 501 #else 502 # define PERL_SCRIPT_MODE "rb" 503 #endif 504 505 /* 506 * Now Win32 specific per-thread data stuff 507 */ 508 509 /* Leave the first couple ids after WM_USER unused because they 510 * might be used by an embedding application, and on Windows 511 * version before 2000 we might end up eating those messages 512 * if they were not meant for us. 513 */ 514 #define WM_USER_MIN (WM_USER+30) 515 #define WM_USER_MESSAGE (WM_USER_MIN) 516 #define WM_USER_KILL (WM_USER_MIN+1) 517 #define WM_USER_MAX (WM_USER_MIN+1) 518 519 struct thread_intern { 520 /* XXX can probably use one buffer instead of several */ 521 char Wstrerror_buffer[512]; 522 struct servent Wservent; 523 char Wgetlogin_buffer[128]; 524 int Winit_socktype; 525 char Wcrypt_buffer[30]; 526 # ifdef USE_RTL_THREAD_API 527 void * retv; /* slot for thread return value */ 528 # endif 529 BOOL Wuse_showwindow; 530 WORD Wshowwindow; 531 }; 532 533 #define HAVE_INTERP_INTERN 534 typedef struct { 535 long num; 536 DWORD pids[MAXIMUM_WAIT_OBJECTS]; 537 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; 538 } child_tab; 539 540 #ifdef USE_ITHREADS 541 typedef struct { 542 long num; 543 DWORD pids[MAXIMUM_WAIT_OBJECTS]; 544 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; 545 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS]; 546 char sigterm[MAXIMUM_WAIT_OBJECTS]; 547 } pseudo_child_tab; 548 #endif 549 550 #ifndef Sighandler_t 551 typedef Signal_t (*Sighandler_t) (int); 552 #define Sighandler_t Sighandler_t 553 #endif 554 555 struct interp_intern { 556 char * perlshell_tokens; 557 char ** perlshell_vec; 558 long perlshell_items; 559 struct av * fdpid; 560 child_tab * children; 561 #ifdef USE_ITHREADS 562 DWORD pseudo_id; 563 pseudo_child_tab * pseudo_children; 564 #endif 565 void * internal_host; 566 struct thread_intern thr_intern; 567 HWND message_hwnd; 568 UINT timerid; 569 unsigned poll_count; 570 Sighandler_t sigtable[SIG_SIZE]; 571 bool sloppystat; 572 }; 573 574 #define WIN32_POLL_INTERVAL 32768 575 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX) 576 577 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens) 578 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec) 579 #define w32_perlshell_items (PL_sys_intern.perlshell_items) 580 #define w32_fdpid (PL_sys_intern.fdpid) 581 #define w32_children (PL_sys_intern.children) 582 #define w32_num_children (w32_children->num) 583 #define w32_child_pids (w32_children->pids) 584 #define w32_child_handles (w32_children->handles) 585 #define w32_pseudo_id (PL_sys_intern.pseudo_id) 586 #define w32_pseudo_children (PL_sys_intern.pseudo_children) 587 #define w32_num_pseudo_children (w32_pseudo_children->num) 588 #define w32_pseudo_child_pids (w32_pseudo_children->pids) 589 #define w32_pseudo_child_handles (w32_pseudo_children->handles) 590 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds) 591 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm) 592 #define w32_internal_host (PL_sys_intern.internal_host) 593 #define w32_timerid (PL_sys_intern.timerid) 594 #define w32_message_hwnd (PL_sys_intern.message_hwnd) 595 #define w32_sighandler (PL_sys_intern.sigtable) 596 #define w32_poll_count (PL_sys_intern.poll_count) 597 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL) 598 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer) 599 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer) 600 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer) 601 #define w32_servent (PL_sys_intern.thr_intern.Wservent) 602 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype) 603 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow) 604 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow) 605 #define w32_sloppystat (PL_sys_intern.sloppystat) 606 607 #ifdef USE_ITHREADS 608 void win32_wait_for_children(pTHX); 609 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX) 610 #endif 611 612 /* The following ioinfo struct manipulations had been removed but were 613 * reinstated to fix RT#120091/118059. However, they do not work with 614 * the rewritten CRT in VS2015 so they are removed once again for VS2015 615 * onwards, which will therefore suffer from the reintroduction of the 616 * close socket bug. */ 617 #if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900) 618 619 #ifdef PERL_CORE 620 621 /* C doesn't like repeat struct definitions */ 622 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3) 623 # undef _CRTIMP 624 #endif 625 #ifndef _CRTIMP 626 # define _CRTIMP __declspec(dllimport) 627 #endif 628 629 630 /* VS2005 has multiple ioinfo struct definitions through VS2005's release life 631 * VS2008-2012 have been stable but do not assume future VSs will have the 632 * same ioinfo struct, just because past struct stability. If research is done 633 * on the CRTs of future VSs, the version check can be bumped up so the newer 634 * VS uses a fixed ioinfo size. (Actually, only VS2013 (_MSC_VER 1800) hasn't 635 * been looked at; after that we cannot use the ioinfo struct anyway (see the 636 * #if above).) 637 */ 638 #if ! (_MSC_VER < 1400 || (_MSC_VER >= 1500 && _MSC_VER <= 1700) \ 639 || defined(__MINGW32__)) 640 /* size of ioinfo struct is determined at runtime */ 641 # define WIN32_DYN_IOINFO_SIZE 642 #endif 643 644 #ifndef WIN32_DYN_IOINFO_SIZE 645 /* 646 * Control structure for lowio file handles 647 */ 648 typedef struct { 649 intptr_t osfhnd;/* underlying OS file HANDLE */ 650 char osfile; /* attributes of file (e.g., open in text mode?) */ 651 char pipech; /* one char buffer for handles opened on pipes */ 652 int lockinitflag; 653 CRITICAL_SECTION lock; 654 /* this struct definition breaks ABI compatibility with 655 * not using, cl.exe's native VS version specitfic CRT. */ 656 # if _MSC_VER >= 1400 && _MSC_VER < 1500 657 # error "This ioinfo struct is incomplete for Visual C 2005" 658 # endif 659 /* VS2005 CRT has at least 3 different definitions of this struct based on the 660 * CRT DLL's build number. */ 661 # if _MSC_VER >= 1500 662 # ifndef _SAFECRT_IMPL 663 /* Not used in the safecrt downlevel. We do not define them, so we cannot 664 * use them accidentally */ 665 char textmode : 7;/* __IOINFO_TM_ANSI or __IOINFO_TM_UTF8 or __IOINFO_TM_UTF16LE */ 666 char unicode : 1; /* Was the file opened as unicode? */ 667 char pipech2[2]; /* 2 more peak ahead chars for UNICODE mode */ 668 __int64 startpos; /* File position that matches buffer start */ 669 BOOL utf8translations; /* Buffer contains translations other than CRLF*/ 670 char dbcsBuffer; /* Buffer for the lead byte of dbcs when converting from dbcs to unicode */ 671 BOOL dbcsBufferUsed; /* Bool for the lead byte buffer is used or not */ 672 # endif 673 # endif 674 } ioinfo; 675 #else 676 typedef intptr_t ioinfo; 677 #endif 678 679 /* 680 * Array of arrays of control structures for lowio files. 681 */ 682 EXTERN_C _CRTIMP ioinfo* __pioinfo[]; 683 684 /* 685 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each 686 * array of ioinfo structs. 687 */ 688 #define IOINFO_L2E 5 689 690 /* 691 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array 692 */ 693 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) 694 695 /* 696 * Access macros for getting at an ioinfo struct and its fields from a 697 * file handle 698 */ 699 #ifdef WIN32_DYN_IOINFO_SIZE 700 # define _pioinfo(i) ((intptr_t *) \ 701 (((Size_t)__pioinfo[(i) >> IOINFO_L2E])/* * to head of array ioinfo [] */\ 702 /* offset to the head of a particular ioinfo struct */ \ 703 + (((i) & (IOINFO_ARRAY_ELTS - 1)) * w32_ioinfo_size)) \ 704 ) 705 /* first slice of ioinfo is always the OS handle */ 706 # define _osfhnd(i) (*(_pioinfo(i))) 707 #else 708 # define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1))) 709 # define _osfhnd(i) (_pioinfo(i)->osfhnd) 710 #endif 711 712 /* since we are not doing a dup2(), this works fine */ 713 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh) 714 715 #endif /* PERL_CORE */ 716 717 #endif /* !defined(_MSC_VER) || _MSC_VER<1900 */ 718 719 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */ 720 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX) 721 #undef PERLIO_NOT_STDIO 722 #endif 723 #define PERLIO_NOT_STDIO 0 724 725 #define EXEC_ARGV_CAST(x) ((const char *const *) x) 726 727 DllExport void *win32_signal_context(void); 728 #define PERL_GET_SIG_CONTEXT win32_signal_context() 729 730 #define Win_GetModuleHandle GetModuleHandle 731 #define Win_GetProcAddress GetProcAddress 732 #define Win_GetModuleFileName GetModuleFileName 733 #define Win_CreateSemaphore CreateSemaphore 734 735 #if defined(PERL_CORE) && !defined(O_ACCMODE) 736 # define O_ACCMODE (O_RDWR | O_WRONLY | O_RDONLY) 737 #endif 738 739 #endif /* _INC_WIN32_PERL5 */ 740 741