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