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