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