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