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