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 0x0400 /* needed for TryEnterCriticalSection() etc. */ 14 #endif 15 16 #if defined(PERL_IMPLICIT_SYS) 17 # define DYNAMIC_ENV_FETCH 18 # define HAS_GETENV_LEN 19 # define prime_env_iter() 20 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */ 21 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */ 22 # ifdef PERL_GLOBAL_STRUCT 23 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS 24 # endif 25 # define win32_get_privlib PerlEnv_lib_path 26 # define win32_get_sitelib PerlEnv_sitelib_path 27 # define win32_get_vendorlib PerlEnv_vendorlib_path 28 #endif 29 30 #ifdef __GNUC__ 31 # ifndef __int64 /* some versions seem to #define it already */ 32 # define __int64 long long 33 # endif 34 # define Win32_Winsock 35 #ifdef __cplusplus 36 /* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */ 37 #undef PERL_UNUSED_DECL 38 #define PERL_UNUSED_DECL 39 #endif 40 #endif 41 42 43 /* Define DllExport akin to perl's EXT, 44 * If we are in the DLL or mimicing the DLL for Win95 work round 45 * then Export the symbol, 46 * otherwise import it. 47 */ 48 49 /* now even GCC supports __declspec() */ 50 51 #if defined(PERLDLL) || defined(WIN95FIX) 52 #define DllExport 53 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */ 54 #else 55 #define DllExport __declspec(dllimport) 56 #endif 57 58 #define WIN32_LEAN_AND_MEAN 59 #include <windows.h> 60 61 /* 62 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they 63 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail 64 * to declare GetEnvironmentStringsA. 65 */ 66 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE) 67 #ifdef __cplusplus 68 extern "C" { 69 #endif 70 #undef GetEnvironmentStringsA 71 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID); 72 #define GetEnvironmentStrings GetEnvironmentStringsA 73 #ifdef __cplusplus 74 } 75 #endif 76 #endif 77 78 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */ 79 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */ 80 #endif /*WIN32_LEAN_AND_MEAN */ 81 82 #ifndef TLS_OUT_OF_INDEXES 83 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF 84 #endif 85 86 #include <dirent.h> 87 #include <io.h> 88 #include <process.h> 89 #include <stdio.h> 90 #include <direct.h> 91 #include <stdlib.h> 92 #include <stddef.h> 93 #include <fcntl.h> 94 #ifndef EXT 95 #include "EXTERN.h" 96 #endif 97 98 struct tms { 99 long tms_utime; 100 long tms_stime; 101 long tms_cutime; 102 long tms_cstime; 103 }; 104 105 #ifndef SYS_NMLN 106 #define SYS_NMLN 257 107 #endif 108 109 struct utsname { 110 char sysname[SYS_NMLN]; 111 char nodename[SYS_NMLN]; 112 char release[SYS_NMLN]; 113 char version[SYS_NMLN]; 114 char machine[SYS_NMLN]; 115 }; 116 117 #ifndef START_EXTERN_C 118 #undef EXTERN_C 119 #ifdef __cplusplus 120 # define START_EXTERN_C extern "C" { 121 # define END_EXTERN_C } 122 # define EXTERN_C extern "C" 123 #else 124 # define START_EXTERN_C 125 # define END_EXTERN_C 126 # define EXTERN_C 127 #endif 128 #endif 129 130 #define STANDARD_C 1 131 #define DOSISH 1 /* no escaping our roots */ 132 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */ 133 134 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as 135 * real filehandles. XXX Should always be defined (the other version is untested) */ 136 #define USE_SOCKETS_AS_HANDLES 137 138 /* read() and write() aren't transparent for socket handles */ 139 #define PERL_SOCK_SYSREAD_IS_RECV 140 #define PERL_SOCK_SYSWRITE_IS_SEND 141 142 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */ 143 144 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95. 145 It now uses some black magic to work seamlessly with the DLL CRT and 146 works with MSVC++ 4.0+ or GCC/Mingw32 147 -- BKS 1-24-2000 148 Only use this fix for VC++ 6.x or earlier (and for GCC, which we assume 149 uses MSVCRT.DLL). Later versions use MSVCR70.dll, MSVCR71.dll, etc, which 150 do not require the fix. */ 151 #if (defined(_M_IX86) && _MSC_VER >= 1000 && _MSC_VER <= 1200) || defined(__MINGW32__) 152 #define USE_FIXED_OSFHANDLE 153 #endif 154 155 /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock 156 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0) 157 -- BKS 5-29-2000 */ 158 #if !(defined(_M_IX86) && _MSC_VER >= 1200) 159 #define PERL_WIN32_SOCK_DLOAD 160 #endif 161 #define ENV_IS_CASELESS 162 163 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */ 164 165 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */ 166 #define VER_PLATFORM_WIN32_WINDOWS 1 167 #endif 168 169 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */ 170 #define FILE_SHARE_DELETE 0x00000004 171 #endif 172 173 /* access() mode bits */ 174 #ifndef R_OK 175 # define R_OK 4 176 # define W_OK 2 177 # define X_OK 1 178 # define F_OK 0 179 #endif 180 181 /* for waitpid() */ 182 #ifndef WNOHANG 183 # define WNOHANG 1 184 #endif 185 186 #define PERL_GET_CONTEXT_DEFINED 187 188 /* Compiler-specific stuff. */ 189 190 #if defined(_MSC_VER) || defined(__MINGW32__) 191 /* VC uses non-standard way to determine the size and alignment if bit-fields */ 192 /* MinGW will compiler with -mms-bitfields, so should use the same types */ 193 # define PERL_BITFIELD8 unsigned char 194 # define PERL_BITFIELD16 unsigned short 195 # define PERL_BITFIELD32 unsigned int 196 #endif 197 198 #ifdef __BORLANDC__ /* Borland C++ */ 199 200 #if (__BORLANDC__ <= 0x520) 201 #define _access access 202 #define _chdir chdir 203 #endif 204 205 #define _getpid getpid 206 #define wcsicmp _wcsicmp 207 #include <sys/types.h> 208 209 #ifndef DllMain 210 #define DllMain DllEntryPoint 211 #endif 212 213 #pragma warn -8004 /* "'foo' is assigned a value that is never used" */ 214 #pragma warn -8008 /* "condition is always true/false" */ 215 #pragma warn -8012 /* "comparing signed and unsigned values" */ 216 #pragma warn -8027 /* "functions containing %s are not expanded inline" */ 217 #pragma warn -8057 /* "parameter 'foo' is never used" */ 218 #pragma warn -8060 /* "possibly incorrect assignment" */ 219 #pragma warn -8066 /* "unreachable code" */ 220 #pragma warn -8071 /* "conversion may lose significant digits" */ 221 #pragma warn -8080 /* "'foo' is declared but never used" */ 222 223 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */ 224 #define PERL_MEMBER_PTR_SIZE 12 225 226 #define isnan _isnan 227 228 #endif 229 230 #ifdef _MSC_VER /* Microsoft Visual C++ */ 231 232 #ifndef UNDER_CE 233 typedef long uid_t; 234 typedef long gid_t; 235 typedef unsigned short mode_t; 236 #endif 237 238 #pragma warning(disable: 4102) /* "unreferenced label" */ 239 240 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */ 241 #define PERL_MEMBER_PTR_SIZE 16 242 243 #define isnan _isnan 244 #define snprintf _snprintf 245 #define vsnprintf _vsnprintf 246 247 #if _MSC_VER < 1300 248 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */ 249 #define NAN_COMPARE_BROKEN 1 250 #endif 251 252 #endif /* _MSC_VER */ 253 254 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */ 255 256 typedef long uid_t; 257 typedef long gid_t; 258 #ifndef _environ 259 #define _environ environ 260 #endif 261 #define flushall _flushall 262 #define fcloseall _fcloseall 263 #ifndef isnan 264 #define isnan _isnan /* ...same libraries as MSVC */ 265 #endif 266 267 #ifndef _O_NOINHERIT 268 # define _O_NOINHERIT 0x0080 269 # ifndef _NO_OLDNAMES 270 # define O_NOINHERIT _O_NOINHERIT 271 # endif 272 #endif 273 274 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's 275 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */ 276 #ifdef _STDINT_H 277 # ifndef _INTPTR_T_DEFINED 278 # define _INTPTR_T_DEFINED 279 # endif 280 # ifndef _UINTPTR_T_DEFINED 281 # define _UINTPTR_T_DEFINED 282 # endif 283 #endif 284 285 #endif /* __MINGW32__ */ 286 287 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */ 288 #ifndef CP_UTF8 289 # define CP_UTF8 65001 290 #endif 291 292 /* compatibility stuff for other compilers goes here */ 293 294 #ifndef _INTPTR_T_DEFINED 295 typedef int intptr_t; 296 # define _INTPTR_T_DEFINED 297 #endif 298 299 #ifndef _UINTPTR_T_DEFINED 300 typedef unsigned int uintptr_t; 301 # define _UINTPTR_T_DEFINED 302 #endif 303 304 START_EXTERN_C 305 306 /* For UNIX compatibility. */ 307 308 extern uid_t getuid(void); 309 extern gid_t getgid(void); 310 extern uid_t geteuid(void); 311 extern gid_t getegid(void); 312 extern int setuid(uid_t uid); 313 extern int setgid(gid_t gid); 314 extern int kill(int pid, int sig); 315 extern int killpg(int pid, int sig); 316 #ifndef USE_PERL_SBRK 317 extern void *sbrk(ptrdiff_t need); 318 # define HAS_SBRK_PROTO 319 #endif 320 extern char * getlogin(void); 321 extern int chown(const char *p, uid_t o, gid_t g); 322 extern int mkstemp(const char *path); 323 324 #undef Stat 325 #define Stat win32_stat 326 327 #undef init_os_extras 328 #define init_os_extras Perl_init_os_extras 329 330 DllExport void Perl_win32_init(int *argcp, char ***argvp); 331 DllExport void Perl_win32_term(void); 332 DllExport void Perl_init_os_extras(void); 333 DllExport void win32_str_os_error(void *sv, DWORD err); 334 DllExport int RunPerl(int argc, char **argv, char **env); 335 336 typedef struct { 337 HANDLE childStdIn; 338 HANDLE childStdOut; 339 HANDLE childStdErr; 340 /* 341 * the following correspond to the fields of the same name 342 * in the STARTUPINFO structure. Embedders can use these to 343 * control the spawning process' look. 344 * Example - to hide the window of the spawned process: 345 * dwFlags = STARTF_USESHOWWINDOW; 346 * wShowWindow = SW_HIDE; 347 */ 348 DWORD dwFlags; 349 DWORD dwX; 350 DWORD dwY; 351 DWORD dwXSize; 352 DWORD dwYSize; 353 DWORD dwXCountChars; 354 DWORD dwYCountChars; 355 DWORD dwFillAttribute; 356 WORD wShowWindow; 357 } child_IO_table; 358 359 DllExport void win32_get_child_IO(child_IO_table* ptr); 360 DllExport HWND win32_create_message_window(void); 361 362 #ifndef USE_SOCKETS_AS_HANDLES 363 extern FILE * my_fdopen(int, char *); 364 #endif 365 extern int my_fclose(FILE *); 366 extern int my_fstat(int fd, Stat_t *sbufptr); 367 extern char * win32_get_privlib(const char *pl, STRLEN *const len); 368 extern char * win32_get_sitelib(const char *pl, STRLEN *const len); 369 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len); 370 extern int IsWin95(void); 371 extern int IsWinNT(void); 372 373 #ifdef PERL_IMPLICIT_SYS 374 extern void win32_delete_internal_host(void *h); 375 #endif 376 377 extern char * staticlinkmodules[]; 378 379 END_EXTERN_C 380 381 typedef char * caddr_t; /* In malloc.c (core address). */ 382 383 /* 384 * handle socket stuff, assuming socket is always available 385 */ 386 #include <sys/socket.h> 387 #include <netdb.h> 388 389 #ifdef MYMALLOC 390 #define EMBEDMYMALLOC /**/ 391 /* #define USE_PERL_SBRK /**/ 392 /* #define PERL_SBRK_VIA_MALLOC /**/ 393 #endif 394 395 #ifdef PERL_TEXTMODE_SCRIPTS 396 # define PERL_SCRIPT_MODE "r" 397 #else 398 # define PERL_SCRIPT_MODE "rb" 399 #endif 400 401 /* 402 * Now Win32 specific per-thread data stuff 403 */ 404 405 /* Leave the first couple ids after WM_USER unused because they 406 * might be used by an embedding application, and on Windows 407 * version before 2000 we might end up eating those messages 408 * if they were not meant for us. 409 */ 410 #define WM_USER_MIN (WM_USER+30) 411 #define WM_USER_MESSAGE (WM_USER_MIN) 412 #define WM_USER_KILL (WM_USER_MIN+1) 413 #define WM_USER_MAX (WM_USER_MIN+1) 414 415 struct thread_intern { 416 /* XXX can probably use one buffer instead of several */ 417 char Wstrerror_buffer[512]; 418 struct servent Wservent; 419 char Wgetlogin_buffer[128]; 420 # ifdef USE_SOCKETS_AS_HANDLES 421 int Winit_socktype; 422 # endif 423 # ifdef HAVE_DES_FCRYPT 424 char Wcrypt_buffer[30]; 425 # endif 426 # ifdef USE_RTL_THREAD_API 427 void * retv; /* slot for thread return value */ 428 # endif 429 BOOL Wuse_showwindow; 430 WORD Wshowwindow; 431 }; 432 433 #define HAVE_INTERP_INTERN 434 typedef struct { 435 long num; 436 DWORD pids[MAXIMUM_WAIT_OBJECTS]; 437 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; 438 } child_tab; 439 440 #ifdef USE_ITHREADS 441 typedef struct { 442 long num; 443 DWORD pids[MAXIMUM_WAIT_OBJECTS]; 444 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; 445 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS]; 446 } pseudo_child_tab; 447 #endif 448 449 #ifndef Sighandler_t 450 typedef Signal_t (*Sighandler_t) (int); 451 #define Sighandler_t Sighandler_t 452 #endif 453 454 struct interp_intern { 455 char * perlshell_tokens; 456 char ** perlshell_vec; 457 long perlshell_items; 458 struct av * fdpid; 459 child_tab * children; 460 #ifdef USE_ITHREADS 461 DWORD pseudo_id; 462 pseudo_child_tab * pseudo_children; 463 #endif 464 void * internal_host; 465 struct thread_intern thr_intern; 466 HWND message_hwnd; 467 UINT timerid; 468 unsigned poll_count; 469 Sighandler_t sigtable[SIG_SIZE]; 470 }; 471 472 DllExport int win32_async_check(pTHX); 473 474 #define WIN32_POLL_INTERVAL 32768 475 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX) 476 477 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens) 478 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec) 479 #define w32_perlshell_items (PL_sys_intern.perlshell_items) 480 #define w32_fdpid (PL_sys_intern.fdpid) 481 #define w32_children (PL_sys_intern.children) 482 #define w32_num_children (w32_children->num) 483 #define w32_child_pids (w32_children->pids) 484 #define w32_child_handles (w32_children->handles) 485 #define w32_pseudo_id (PL_sys_intern.pseudo_id) 486 #define w32_pseudo_children (PL_sys_intern.pseudo_children) 487 #define w32_num_pseudo_children (w32_pseudo_children->num) 488 #define w32_pseudo_child_pids (w32_pseudo_children->pids) 489 #define w32_pseudo_child_handles (w32_pseudo_children->handles) 490 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds) 491 #define w32_internal_host (PL_sys_intern.internal_host) 492 #define w32_timerid (PL_sys_intern.timerid) 493 #define w32_message_hwnd (PL_sys_intern.message_hwnd) 494 #define w32_sighandler (PL_sys_intern.sigtable) 495 #define w32_poll_count (PL_sys_intern.poll_count) 496 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL) 497 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer) 498 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer) 499 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer) 500 #define w32_servent (PL_sys_intern.thr_intern.Wservent) 501 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype) 502 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow) 503 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow) 504 505 #ifdef USE_ITHREADS 506 # define PERL_WAIT_FOR_CHILDREN \ 507 STMT_START { \ 508 if (w32_pseudo_children && w32_num_pseudo_children) { \ 509 long children = w32_num_pseudo_children; \ 510 WaitForMultipleObjects(children, \ 511 w32_pseudo_child_handles, \ 512 TRUE, INFINITE); \ 513 while (children) \ 514 CloseHandle(w32_pseudo_child_handles[--children]); \ 515 } \ 516 } STMT_END 517 #endif 518 519 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX) 520 #ifdef PERL_CORE 521 522 /* C doesn't like repeat struct definitions */ 523 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3) 524 #undef _CRTIMP 525 #endif 526 #ifndef _CRTIMP 527 #define _CRTIMP __declspec(dllimport) 528 #endif 529 530 /* 531 * Control structure for lowio file handles 532 */ 533 typedef struct { 534 intptr_t osfhnd;/* underlying OS file HANDLE */ 535 char osfile; /* attributes of file (e.g., open in text mode?) */ 536 char pipech; /* one char buffer for handles opened on pipes */ 537 int lockinitflag; 538 CRITICAL_SECTION lock; 539 } ioinfo; 540 541 542 /* 543 * Array of arrays of control structures for lowio files. 544 */ 545 EXTERN_C _CRTIMP ioinfo* __pioinfo[]; 546 547 /* 548 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each 549 * array of ioinfo structs. 550 */ 551 #define IOINFO_L2E 5 552 553 /* 554 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array 555 */ 556 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) 557 558 /* 559 * Access macros for getting at an ioinfo struct and its fields from a 560 * file handle 561 */ 562 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1))) 563 #define _osfhnd(i) (_pioinfo(i)->osfhnd) 564 #define _osfile(i) (_pioinfo(i)->osfile) 565 #define _pipech(i) (_pioinfo(i)->pipech) 566 567 /* since we are not doing a dup2(), this works fine */ 568 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh) 569 #endif 570 #endif 571 572 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */ 573 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX) 574 #undef PERLIO_NOT_STDIO 575 #endif 576 #define PERLIO_NOT_STDIO 0 577 578 #include "perlio.h" 579 580 /* 581 * This provides a layer of functions and macros to ensure extensions will 582 * get to use the same RTL functions as the core. 583 */ 584 #include "win32iop.h" 585 586 #define EXEC_ARGV_CAST(x) ((const char *const *) x) 587 588 #if !defined(ECONNABORTED) && defined(WSAECONNABORTED) 589 #define ECONNABORTED WSAECONNABORTED 590 #endif 591 #if !defined(ECONNRESET) && defined(WSAECONNRESET) 592 #define ECONNRESET WSAECONNRESET 593 #endif 594 #if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT) 595 #define EAFNOSUPPORT WSAEAFNOSUPPORT 596 #endif 597 /* Why not needed for ECONNREFUSED? --abe */ 598 599 DllExport void *win32_signal_context(void); 600 #define PERL_GET_SIG_CONTEXT win32_signal_context() 601 602 #ifdef UNDER_CE 603 #define Win_GetModuleHandle XCEGetModuleHandleA 604 #define Win_GetProcAddress XCEGetProcAddressA 605 #define Win_GetModuleFileName XCEGetModuleFileNameA 606 #define Win_CreateSemaphore CreateSemaphoreW 607 #else 608 #define Win_GetModuleHandle GetModuleHandle 609 #define Win_GetProcAddress GetProcAddress 610 #define Win_GetModuleFileName GetModuleFileName 611 #define Win_CreateSemaphore CreateSemaphore 612 #endif 613 614 #endif /* _INC_WIN32_PERL5 */ 615 616