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