This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove redundant PERL_EXPORT_C and PERL_XS_EXPORT_C macros
[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
TC
26
27/* allow minitest to work */
ead233d2 28# define PERL_TEXTMODE_SCRIPTS
19253ae6
DD
29#endif
30
31#ifdef WIN32_NO_SOCKETS
32# undef HAS_SOCKET
33# undef HAS_GETPROTOBYNAME
34# undef HAS_GETPROTOBYNUMBER
35# undef HAS_GETPROTOENT
36# undef HAS_GETNETBYNAME
37# undef HAS_GETNETBYADDR
38# undef HAS_GETNETENT
39# undef HAS_GETSERVBYNAME
40# undef HAS_GETSERVBYPORT
41# undef HAS_GETSERVENT
42# undef HAS_GETHOSTBYNAME
43# undef HAS_GETHOSTBYADDR
44# undef HAS_GETHOSTENT
45# undef HAS_SELECT
46# undef HAS_IOCTL
47# undef HAS_NTOHL
48# undef HAS_HTONL
49# undef HAS_HTONS
50# undef HAS_NTOHS
51# define WIN32SCK_IS_STDSCK
52#endif
53
acfe0abc 54#if defined(PERL_IMPLICIT_SYS)
e9ee4811 55# define DYNAMIC_ENV_FETCH
a6c40364 56# define HAS_GETENV_LEN
e9ee4811 57# define prime_env_iter()
ab39fa9d 58# define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
c5be433b 59# define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
ab39fa9d 60# ifdef PERL_GLOBAL_STRUCT
32e30700 61# error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
ab39fa9d 62# endif
e5a95ffb 63# define win32_get_privlib PerlEnv_lib_path
ab39fa9d 64# define win32_get_sitelib PerlEnv_sitelib_path
4ea817c6 65# define win32_get_vendorlib PerlEnv_vendorlib_path
9d8a25dc
DL
66#endif
67
a835ef8a 68#ifdef __GNUC__
b7c82df9
GS
69# ifndef __int64 /* some versions seem to #define it already */
70# define __int64 long long
71# endif
db15561c 72# define Win32_Winsock
1c85e96a
NIS
73#ifdef __cplusplus
74/* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
3fadfdf1
NIS
75#undef PERL_UNUSED_DECL
76#define PERL_UNUSED_DECL
a835ef8a 77#endif
1c85e96a
NIS
78#endif
79
a835ef8a 80
3fadfdf1 81/* Define DllExport akin to perl's EXT,
8cbe99e5 82 * If we are in the DLL then Export the symbol,
22239a37
NIS
83 * otherwise import it.
84 */
85
5db10396 86/* now even GCC supports __declspec() */
a19baa61
DD
87/* miniperl has no reason to export anything */
88#if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
89# define DllExport
3fadfdf1 90#else
a19baa61
DD
91# if defined(PERLDLL)
92# define DllExport __declspec(dllexport)
93# else
94# define DllExport __declspec(dllimport)
95# endif
22239a37 96#endif
c69f112c 97
50fd5961
JD
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)
ad6ab6c5
JD
108# ifdef __cplusplus
109# define PERL_CALLCONV extern "C" __declspec(dllimport)
12a2785c 110# ifdef _MSC_VER
03c98af0 111# define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
12a2785c 112# endif
ad6ab6c5
JD
113# else
114# define PERL_CALLCONV __declspec(dllimport)
12a2785c 115# ifdef _MSC_VER
03c98af0 116# define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
12a2785c 117# endif
ad6ab6c5 118# endif
50e8e1f5
DD
119#else /* MSVC noreturn support inside the interp */
120# ifdef _MSC_VER
121# define PERL_CALLCONV_NO_RET __declspec(noreturn)
122# endif
ad6ab6c5
JD
123#endif
124
98c015b7
DD
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
0a753a76
PP
130#define WIN32_LEAN_AND_MEAN
131#include <windows.h>
132
fa58a56f
S
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
140extern "C" {
141#endif
142#undef GetEnvironmentStringsA
143WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
144#define GetEnvironmentStrings GetEnvironmentStringsA
145#ifdef __cplusplus
146}
147#endif
148#endif
149
68dc0745
PP
150#ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
151#define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
68dc0745 152#endif /*WIN32_LEAN_AND_MEAN */
0a753a76 153
eda5ff31
GS
154#ifndef TLS_OUT_OF_INDEXES
155#define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
156#endif
157
0a753a76
PP
158#include <dirent.h>
159#include <io.h>
160#include <process.h>
161#include <stdio.h>
162#include <direct.h>
390b85e7 163#include <stdlib.h>
c623ac67 164#include <stddef.h>
7a1f88ac 165#include <fcntl.h>
390b85e7
GS
166#ifndef EXT
167#include "EXTERN.h"
168#endif
169
c69f112c
NIS
170struct tms {
171 long tms_utime;
172 long tms_stime;
173 long tms_cutime;
174 long tms_cstime;
175};
176
b2af26b1
GS
177#ifndef SYS_NMLN
178#define SYS_NMLN 257
179#endif
180
181struct 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
390b85e7 189#ifndef START_EXTERN_C
b3e5c95e 190#undef EXTERN_C
390b85e7
GS
191#ifdef __cplusplus
192# define START_EXTERN_C extern "C" {
193# define END_EXTERN_C }
194# define EXTERN_C extern "C"
195#else
3fadfdf1
NIS
196# define START_EXTERN_C
197# define END_EXTERN_C
390b85e7
GS
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? */
0a753a76 205
a7092146 206/* read() and write() aren't transparent for socket handles */
19253ae6
DD
207#ifndef WIN32_NO_SOCKETS
208# define PERL_SOCK_SYSREAD_IS_RECV
209# define PERL_SOCK_SYSWRITE_IS_SEND
210#endif
a7092146 211
682fc664 212#define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
a7092146 213
902173a3
GS
214#define ENV_IS_CASELESS
215
479b2847
GS
216#define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
217
327c3667
GS
218/* access() mode bits */
219#ifndef R_OK
220# define R_OK 4
221# define W_OK 2
222# define X_OK 1
223# define F_OK 0
224#endif
225
cc236deb
GS
226/* for waitpid() */
227#ifndef WNOHANG
228# define WNOHANG 1
229#endif
230
c44d3fdb
GS
231#define PERL_GET_CONTEXT_DEFINED
232
f3986ebb
GS
233/* Compiler-specific stuff. */
234
654eccd5 235/* VC uses non-standard way to determine the size and alignment if bit-fields */
4eab039d
SH
236/* MinGW will compile with -mms-bitfields, so should use the same types */
237#define PERL_BITFIELD8 unsigned char
238#define PERL_BITFIELD16 unsigned short
239#define PERL_BITFIELD32 unsigned int
654eccd5 240
f3986ebb
GS
241#ifdef _MSC_VER /* Microsoft Visual C++ */
242
f4257e4d 243#ifndef UNDER_CE
0a753a76
PP
244typedef long uid_t;
245typedef long gid_t;
a6c40364 246typedef unsigned short mode_t;
f4257e4d
YO
247#endif
248
3e7c2d43
SH
249#if _MSC_VER < 1800
250#define isnan _isnan /* Defined already in VC++ 12.0 */
251#endif
27329181
DD
252#ifdef UNDER_CE /* revisit what function this becomes celib vs corelibc, prv warning here*/
253# undef snprintf
254#endif
80e18237
SH
255#define snprintf _snprintf
256#define vsnprintf _vsnprintf
5fb4d820 257
8961ec41
DD
258/* on VC2003, msvcrt.lib is missing these symbols */
259#if _MSC_VER >= 1300 && _MSC_VER < 1400
260# pragma intrinsic(_rotl64,_rotr64)
261#endif
262
3c81f0b3
DD
263# pragma warning(push)
264# pragma warning(disable:4756;disable:4056)
265PERL_STATIC_INLINE
266double S_Infinity() {
267 /* this is a real C literal which can get further constant folded
268 unlike using HUGE_VAL/_HUGE which are data symbol imports from the CRT
269 and therefore can not by folded by VC, an example of constant
270 folding INF is creating -INF */
271 return (DBL_MAX+DBL_MAX);
272}
273# pragma warning(pop)
274# define NV_INF S_Infinity()
275
276/* selectany allows duplicate and unused data symbols to be removed by
277 VC linker, if this were static, each translation unit will have its own,
278 usually unused __PL_nan_u, if this were plain extern it will cause link
279 to fail due to multiple definitions, since we dont know if we are being
280 compiled as static or DLL XS, selectany simply always works, the cost of
281 importing __PL_nan_u across DLL boundaries in size in the importing DLL
282 will be more than the 8 bytes it will take up being in each XS DLL if
283 that DLL actually uses __PL_nan_u */
284extern const __declspec(selectany) union { unsigned __int64 __q; double __d; }
285__PL_nan_u = { 0x7FF8000000000000UI64 };
286# define NV_NAN ((NV)__PL_nan_u.__d)
287
f3986ebb
GS
288#endif /* _MSC_VER */
289
910dfcc8
GS
290#ifdef __MINGW32__ /* Minimal Gnu-Win32 */
291
292typedef long uid_t;
293typedef long gid_t;
b1d1613b 294#ifndef _environ
3730b96e 295#define _environ environ
b1d1613b 296#endif
3730b96e
GS
297#define flushall _flushall
298#define fcloseall _fcloseall
44604af1 299#ifndef isnan
6940069f 300#define isnan _isnan /* ...same libraries as MSVC */
44604af1 301#endif
910dfcc8 302
ac4c12e7
GS
303#ifndef _O_NOINHERIT
304# define _O_NOINHERIT 0x0080
305# ifndef _NO_OLDNAMES
306# define O_NOINHERIT _O_NOINHERIT
307# endif
308#endif
309
8659febc
S
310/* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
311 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
312#ifdef _STDINT_H
313# ifndef _INTPTR_T_DEFINED
314# define _INTPTR_T_DEFINED
315# endif
316# ifndef _UINTPTR_T_DEFINED
317# define _UINTPTR_T_DEFINED
318# endif
319#endif
320
f8fb7c90
GS
321#ifndef CP_UTF8
322# define CP_UTF8 65001
323#endif
324
70764c00
SH
325#endif /* __MINGW32__ */
326
c623ac67
GS
327#ifndef _INTPTR_T_DEFINED
328typedef int intptr_t;
329# define _INTPTR_T_DEFINED
330#endif
331
332#ifndef _UINTPTR_T_DEFINED
333typedef unsigned int uintptr_t;
334# define _UINTPTR_T_DEFINED
335#endif
336
390b85e7 337START_EXTERN_C
f3986ebb
GS
338
339/* For UNIX compatibility. */
340
e37d7e38 341#ifdef PERL_CORE
0a753a76
PP
342extern uid_t getuid(void);
343extern gid_t getgid(void);
344extern uid_t geteuid(void);
345extern gid_t getegid(void);
0c38a575
SH
346extern int setuid(uid_t uid);
347extern int setgid(gid_t gid);
0a753a76 348extern int kill(int pid, int sig);
c623ac67
GS
349#ifndef USE_PERL_SBRK
350extern void *sbrk(ptrdiff_t need);
351# define HAS_SBRK_PROTO
352#endif
e34ffe5a 353extern char * getlogin(void);
b990f8c8 354extern int chown(const char *p, uid_t o, gid_t g);
f33b2f58 355#if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4
00b02797 356extern int mkstemp(const char *path);
e37d7e38 357#endif
f33b2f58 358#endif
d55594ae 359
f3986ebb
GS
360#undef Stat
361#define Stat win32_stat
3e3baf6d 362
f3986ebb
GS
363#undef init_os_extras
364#define init_os_extras Perl_init_os_extras
390b85e7 365
22239a37 366DllExport void Perl_win32_init(int *argcp, char ***argvp);
23f519f0 367DllExport void Perl_win32_term(void);
cb359b41 368DllExport void Perl_init_os_extras(void);
c5be433b
GS
369DllExport void win32_str_os_error(void *sv, DWORD err);
370DllExport int RunPerl(int argc, char **argv, char **env);
0551aaa8 371
635bbe87
GS
372typedef struct {
373 HANDLE childStdIn;
374 HANDLE childStdOut;
375 HANDLE childStdErr;
f83751a7
GS
376 /*
377 * the following correspond to the fields of the same name
378 * in the STARTUPINFO structure. Embedders can use these to
379 * control the spawning process' look.
380 * Example - to hide the window of the spawned process:
381 * dwFlags = STARTF_USESHOWWINDOW;
382 * wShowWindow = SW_HIDE;
383 */
384 DWORD dwFlags;
3fadfdf1
NIS
385 DWORD dwX;
386 DWORD dwY;
387 DWORD dwXSize;
388 DWORD dwYSize;
389 DWORD dwXCountChars;
390 DWORD dwYCountChars;
f83751a7 391 DWORD dwFillAttribute;
3fadfdf1 392 WORD wShowWindow;
635bbe87
GS
393} child_IO_table;
394
395DllExport void win32_get_child_IO(child_IO_table* ptr);
b69b0499 396DllExport HWND win32_create_message_window(void);
39c93f11 397DllExport int win32_async_check(pTHX);
635bbe87 398
f3986ebb 399extern int my_fclose(FILE *);
e6a0bbf8
NC
400extern char * win32_get_privlib(const char *pl, STRLEN *const len);
401extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
402extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
d55594ae 403
1c0ca838
GS
404#ifdef PERL_IMPLICIT_SYS
405extern void win32_delete_internal_host(void *h);
406#endif
407
c9beaf97
SH
408extern int win32_get_errno(int err);
409
fe1c5936 410extern const char * const staticlinkmodules[];
390b85e7
GS
411
412END_EXTERN_C
d55594ae 413
68dc0745 414typedef char * caddr_t; /* In malloc.c (core address). */
0a753a76 415
68dc0745 416/*
68dc0745
PP
417 * handle socket stuff, assuming socket is always available
418 */
0a753a76
PP
419#include <sys/socket.h>
420#include <netdb.h>
421
bbc8f9de
NIS
422#ifdef MYMALLOC
423#define EMBEDMYMALLOC /**/
08088357 424/* #define USE_PERL_SBRK / **/
425/* #define PERL_SBRK_VIA_MALLOC / **/
bbc8f9de
NIS
426#endif
427
e68cb057 428#ifdef PERL_TEXTMODE_SCRIPTS
c39cd008 429# define PERL_SCRIPT_MODE "r"
a868473f 430#else
c39cd008 431# define PERL_SCRIPT_MODE "rb"
a868473f
NIS
432#endif
433
3fadfdf1
NIS
434/*
435 * Now Win32 specific per-thread data stuff
3352bfcb
GS
436 */
437
aeecf691
JD
438/* Leave the first couple ids after WM_USER unused because they
439 * might be used by an embedding application, and on Windows
440 * version before 2000 we might end up eating those messages
441 * if they were not meant for us.
442 */
443#define WM_USER_MIN (WM_USER+30)
444#define WM_USER_MESSAGE (WM_USER_MIN)
445#define WM_USER_KILL (WM_USER_MIN+1)
446#define WM_USER_MAX (WM_USER_MIN+1)
447
3352bfcb
GS
448struct thread_intern {
449 /* XXX can probably use one buffer instead of several */
450 char Wstrerror_buffer[512];
451 struct servent Wservent;
452 char Wgetlogin_buffer[128];
f4257e4d 453 int Winit_socktype;
3352bfcb 454 char Wcrypt_buffer[30];
3352bfcb
GS
455# ifdef USE_RTL_THREAD_API
456 void * retv; /* slot for thread return value */
457# endif
02637f4c
JD
458 BOOL Wuse_showwindow;
459 WORD Wshowwindow;
3352bfcb
GS
460};
461
4b556e6c 462#define HAVE_INTERP_INTERN
0aaad0ff
GS
463typedef struct {
464 long num;
465 DWORD pids[MAXIMUM_WAIT_OBJECTS];
7766f137 466 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
0aaad0ff
GS
467} child_tab;
468
aeecf691
JD
469#ifdef USE_ITHREADS
470typedef struct {
471 long num;
472 DWORD pids[MAXIMUM_WAIT_OBJECTS];
473 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
474 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
8a3cb9c6 475 char sigterm[MAXIMUM_WAIT_OBJECTS];
aeecf691
JD
476} pseudo_child_tab;
477#endif
478
3fadfdf1
NIS
479#ifndef Sighandler_t
480typedef Signal_t (*Sighandler_t) (int);
481#define Sighandler_t Sighandler_t
482#endif
483
4b556e6c 484struct interp_intern {
0aaad0ff
GS
485 char * perlshell_tokens;
486 char ** perlshell_vec;
487 long perlshell_items;
488 struct av * fdpid;
489 child_tab * children;
7766f137
GS
490#ifdef USE_ITHREADS
491 DWORD pseudo_id;
aeecf691 492 pseudo_child_tab * pseudo_children;
7766f137
GS
493#endif
494 void * internal_host;
3352bfcb 495 struct thread_intern thr_intern;
aeecf691 496 HWND message_hwnd;
8fb3fcfb 497 UINT timerid;
05ec9bb3 498 unsigned poll_count;
3fadfdf1 499 Sighandler_t sigtable[SIG_SIZE];
4b556e6c
JD
500};
501
05ec9bb3 502#define WIN32_POLL_INTERVAL 32768
8fb3fcfb 503#define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
4b556e6c 504
0aaad0ff
GS
505#define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
506#define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
507#define w32_perlshell_items (PL_sys_intern.perlshell_items)
508#define w32_fdpid (PL_sys_intern.fdpid)
509#define w32_children (PL_sys_intern.children)
510#define w32_num_children (w32_children->num)
511#define w32_child_pids (w32_children->pids)
7766f137
GS
512#define w32_child_handles (w32_children->handles)
513#define w32_pseudo_id (PL_sys_intern.pseudo_id)
514#define w32_pseudo_children (PL_sys_intern.pseudo_children)
515#define w32_num_pseudo_children (w32_pseudo_children->num)
516#define w32_pseudo_child_pids (w32_pseudo_children->pids)
517#define w32_pseudo_child_handles (w32_pseudo_children->handles)
aeecf691 518#define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
8a3cb9c6 519#define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
7766f137 520#define w32_internal_host (PL_sys_intern.internal_host)
8fb3fcfb 521#define w32_timerid (PL_sys_intern.timerid)
aeecf691 522#define w32_message_hwnd (PL_sys_intern.message_hwnd)
3fadfdf1 523#define w32_sighandler (PL_sys_intern.sigtable)
05ec9bb3
NIS
524#define w32_poll_count (PL_sys_intern.poll_count)
525#define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
3db8f154
MB
526#define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
527#define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
528#define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
529#define w32_servent (PL_sys_intern.thr_intern.Wservent)
f4257e4d 530#define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
3db8f154
MB
531#define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
532#define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
c53bd28a 533
7766f137 534#ifdef USE_ITHREADS
8a3cb9c6
JD
535void win32_wait_for_children(pTHX);
536# define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
7766f137
GS
537#endif
538
b47a847f
DD
539#ifdef PERL_CORE
540/* C doesn't like repeat struct definitions */
541#if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
542#undef _CRTIMP
543#endif
544#ifndef _CRTIMP
545#define _CRTIMP __declspec(dllimport)
546#endif
547
548
549/* VV 2005 has multiple ioinfo struct definitions through VC 2005's release life
550 * VC 2008-2012 have been stable but do not assume future VCs will have the
551 * same ioinfo struct, just because past struct stability. If research is done
552 * on the CRTs of future VS, the version check can be bumped up so the newer
553 * VC uses a fixed ioinfo size.
554 */
555#if ! (_MSC_VER < 1400 || (_MSC_VER >= 1500 && _MSC_VER <= 1700) \
556 || defined(__MINGW32__))
557/* size of ioinfo struct is determined at runtime */
558# define WIN32_DYN_IOINFO_SIZE
559#endif
560
561#ifndef WIN32_DYN_IOINFO_SIZE
562/*
563 * Control structure for lowio file handles
564 */
565typedef struct {
566 intptr_t osfhnd;/* underlying OS file HANDLE */
567 char osfile; /* attributes of file (e.g., open in text mode?) */
568 char pipech; /* one char buffer for handles opened on pipes */
569 int lockinitflag;
570 CRITICAL_SECTION lock;
bb0f0a6a 571/* this struct definition breaks ABI compatibility with
b47a847f
DD
572 * not using, cl.exe's native VS version specitfic CRT. */
573# if _MSC_VER >= 1400 && _MSC_VER < 1500
574# error "This ioinfo struct is incomplete for Visual C 2005"
575# endif
bb0f0a6a 576/* VC 2005 CRT has at least 3 different definitions of this struct based on the
b47a847f
DD
577 * CRT DLL's build number. */
578# if _MSC_VER >= 1500
579# ifndef _SAFECRT_IMPL
580 /* Not used in the safecrt downlevel. We do not define them, so we cannot
581 * use them accidentally */
582 char textmode : 7;/* __IOINFO_TM_ANSI or __IOINFO_TM_UTF8 or __IOINFO_TM_UTF16LE */
583 char unicode : 1; /* Was the file opened as unicode? */
584 char pipech2[2]; /* 2 more peak ahead chars for UNICODE mode */
585 __int64 startpos; /* File position that matches buffer start */
586 BOOL utf8translations; /* Buffer contains translations other than CRLF*/
587 char dbcsBuffer; /* Buffer for the lead byte of dbcs when converting from dbcs to unicode */
588 BOOL dbcsBufferUsed; /* Bool for the lead byte buffer is used or not */
589# endif
590# endif
591} ioinfo;
592#else
593typedef intptr_t ioinfo;
594#endif
595
596/*
597 * Array of arrays of control structures for lowio files.
598 */
599EXTERN_C _CRTIMP ioinfo* __pioinfo[];
600
601/*
602 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
603 * array of ioinfo structs.
604 */
605#define IOINFO_L2E 5
606
607/*
608 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
609 */
610#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
611
612/*
613 * Access macros for getting at an ioinfo struct and its fields from a
614 * file handle
615 */
616#ifdef WIN32_DYN_IOINFO_SIZE
617# define _pioinfo(i) ((intptr_t *) \
618 (((Size_t)__pioinfo[(i) >> IOINFO_L2E])/* * to head of array ioinfo [] */\
619 /* offset to the head of a particular ioinfo struct */ \
620 + (((i) & (IOINFO_ARRAY_ELTS - 1)) * w32_ioinfo_size)) \
621 )
622/* first slice of ioinfo is always the OS handle */
623# define _osfhnd(i) (*(_pioinfo(i)))
624#else
625# define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
626# define _osfhnd(i) (_pioinfo(i)->osfhnd)
627#endif
628
629/* since we are not doing a dup2(), this works fine */
630# define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
631#endif /* PERL_CORE */
632
3fadfdf1 633/* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
6e22d046
JH
634#if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
635#undef PERLIO_NOT_STDIO
636#endif
adb71456
NIS
637#define PERLIO_NOT_STDIO 0
638
b4748376
NIS
639#define EXEC_ARGV_CAST(x) ((const char *const *) x)
640
f4958739 641DllExport void *win32_signal_context(void);
1018e26f
NIS
642#define PERL_GET_SIG_CONTEXT win32_signal_context()
643
45496817 644#ifdef UNDER_CE
7bd379e8
YO
645#define Win_GetModuleHandle XCEGetModuleHandleA
646#define Win_GetProcAddress XCEGetProcAddressA
647#define Win_GetModuleFileName XCEGetModuleFileNameA
648#define Win_CreateSemaphore CreateSemaphoreW
649#else
650#define Win_GetModuleHandle GetModuleHandle
651#define Win_GetProcAddress GetProcAddress
652#define Win_GetModuleFileName GetModuleFileName
653#define Win_CreateSemaphore CreateSemaphore
654#endif
655
68dc0745 656#endif /* _INC_WIN32_PERL5 */
7a9ec5a3 657