This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test for errors requiring .ph files.
[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
acfe0abc 16#if defined(PERL_IMPLICIT_SYS)
e9ee4811 17# define DYNAMIC_ENV_FETCH
a6c40364 18# define HAS_GETENV_LEN
e9ee4811 19# define prime_env_iter()
ab39fa9d 20# define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
c5be433b 21# define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
ab39fa9d 22# ifdef PERL_GLOBAL_STRUCT
32e30700 23# error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
ab39fa9d 24# endif
e5a95ffb 25# define win32_get_privlib PerlEnv_lib_path
ab39fa9d 26# define win32_get_sitelib PerlEnv_sitelib_path
4ea817c6 27# define win32_get_vendorlib PerlEnv_vendorlib_path
9d8a25dc
DL
28#endif
29
a835ef8a 30#ifdef __GNUC__
b7c82df9
GS
31# ifndef __int64 /* some versions seem to #define it already */
32# define __int64 long long
33# endif
db15561c 34# define Win32_Winsock
1c85e96a
NIS
35#ifdef __cplusplus
36/* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
3fadfdf1
NIS
37#undef PERL_UNUSED_DECL
38#define PERL_UNUSED_DECL
a835ef8a 39#endif
1c85e96a
NIS
40#endif
41
a835ef8a 42
3fadfdf1 43/* Define DllExport akin to perl's EXT,
8cbe99e5 44 * If we are in the DLL then Export the symbol,
22239a37
NIS
45 * otherwise import it.
46 */
47
5db10396
GS
48/* now even GCC supports __declspec() */
49
8cbe99e5 50#if defined(PERLDLL)
70764c00 51#define DllExport __declspec(dllexport)
3fadfdf1 52#else
22239a37
NIS
53#define DllExport __declspec(dllimport)
54#endif
c69f112c 55
50fd5961
JD
56/* The Perl APIs can only be called directly inside the perl5xx.dll.
57 * All other code has to import them. By declaring them as "dllimport"
58 * we tell the compiler to generate an indirect call instruction and
59 * avoid redirection through a call thunk.
60 *
61 * The XS code in the re extension is special, in that it redefines
62 * core APIs locally, so don't mark them as "dllimport" because GCC
63 * cannot handle this situation.
64 */
65#if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
ad6ab6c5
JD
66# ifdef __cplusplus
67# define PERL_CALLCONV extern "C" __declspec(dllimport)
12a2785c 68# ifdef _MSC_VER
03c98af0 69# define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
12a2785c 70# endif
ad6ab6c5
JD
71# else
72# define PERL_CALLCONV __declspec(dllimport)
12a2785c 73# ifdef _MSC_VER
03c98af0 74# define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
12a2785c 75# endif
ad6ab6c5 76# endif
50e8e1f5
DD
77#else /* MSVC noreturn support inside the interp */
78# ifdef _MSC_VER
79# define PERL_CALLCONV_NO_RET __declspec(noreturn)
80# endif
ad6ab6c5
JD
81#endif
82
0a753a76 83#define WIN32_LEAN_AND_MEAN
84#include <windows.h>
85
fa58a56f
S
86/*
87 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
88 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
89 * to declare GetEnvironmentStringsA.
90 */
91#if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
92#ifdef __cplusplus
93extern "C" {
94#endif
95#undef GetEnvironmentStringsA
96WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
97#define GetEnvironmentStrings GetEnvironmentStringsA
98#ifdef __cplusplus
99}
100#endif
101#endif
102
68dc0745 103#ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
104#define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
68dc0745 105#endif /*WIN32_LEAN_AND_MEAN */
0a753a76 106
eda5ff31
GS
107#ifndef TLS_OUT_OF_INDEXES
108#define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
109#endif
110
0a753a76 111#include <dirent.h>
112#include <io.h>
113#include <process.h>
114#include <stdio.h>
115#include <direct.h>
390b85e7 116#include <stdlib.h>
c623ac67 117#include <stddef.h>
7a1f88ac 118#include <fcntl.h>
390b85e7
GS
119#ifndef EXT
120#include "EXTERN.h"
121#endif
122
c69f112c
NIS
123struct tms {
124 long tms_utime;
125 long tms_stime;
126 long tms_cutime;
127 long tms_cstime;
128};
129
b2af26b1
GS
130#ifndef SYS_NMLN
131#define SYS_NMLN 257
132#endif
133
134struct utsname {
135 char sysname[SYS_NMLN];
136 char nodename[SYS_NMLN];
137 char release[SYS_NMLN];
138 char version[SYS_NMLN];
139 char machine[SYS_NMLN];
140};
141
390b85e7 142#ifndef START_EXTERN_C
b3e5c95e 143#undef EXTERN_C
390b85e7
GS
144#ifdef __cplusplus
145# define START_EXTERN_C extern "C" {
146# define END_EXTERN_C }
147# define EXTERN_C extern "C"
148#else
3fadfdf1
NIS
149# define START_EXTERN_C
150# define END_EXTERN_C
390b85e7
GS
151# define EXTERN_C
152#endif
153#endif
154
155#define STANDARD_C 1
156#define DOSISH 1 /* no escaping our roots */
157#define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
0a753a76 158
f3986ebb
GS
159/* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
160 * real filehandles. XXX Should always be defined (the other version is untested) */
161#define USE_SOCKETS_AS_HANDLES
162
a7092146
GS
163/* read() and write() aren't transparent for socket handles */
164#define PERL_SOCK_SYSREAD_IS_RECV
165#define PERL_SOCK_SYSWRITE_IS_SEND
166
682fc664 167#define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
a7092146 168
902173a3
GS
169#define ENV_IS_CASELESS
170
479b2847
GS
171#define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
172
327c3667
GS
173/* access() mode bits */
174#ifndef R_OK
175# define R_OK 4
176# define W_OK 2
177# define X_OK 1
178# define F_OK 0
179#endif
180
cc236deb
GS
181/* for waitpid() */
182#ifndef WNOHANG
183# define WNOHANG 1
184#endif
185
c44d3fdb
GS
186#define PERL_GET_CONTEXT_DEFINED
187
f3986ebb
GS
188/* Compiler-specific stuff. */
189
654eccd5 190/* VC uses non-standard way to determine the size and alignment if bit-fields */
4eab039d
SH
191/* MinGW will compile with -mms-bitfields, so should use the same types */
192#define PERL_BITFIELD8 unsigned char
193#define PERL_BITFIELD16 unsigned short
194#define PERL_BITFIELD32 unsigned int
654eccd5 195
f3986ebb
GS
196#ifdef _MSC_VER /* Microsoft Visual C++ */
197
f4257e4d 198#ifndef UNDER_CE
0a753a76 199typedef long uid_t;
200typedef long gid_t;
a6c40364 201typedef unsigned short mode_t;
f4257e4d
YO
202#endif
203
c623ac67 204#pragma warning(disable: 4102) /* "unreferenced label" */
f3986ebb 205
5fb4d820 206#define isnan _isnan
80e18237
SH
207#define snprintf _snprintf
208#define vsnprintf _vsnprintf
5fb4d820 209
cab190d4
JD
210#if _MSC_VER < 1300
211/* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
212#define NAN_COMPARE_BROKEN 1
213#endif
214
f3986ebb
GS
215#endif /* _MSC_VER */
216
910dfcc8
GS
217#ifdef __MINGW32__ /* Minimal Gnu-Win32 */
218
219typedef long uid_t;
220typedef long gid_t;
b1d1613b 221#ifndef _environ
3730b96e 222#define _environ environ
b1d1613b 223#endif
3730b96e
GS
224#define flushall _flushall
225#define fcloseall _fcloseall
44604af1 226#ifndef isnan
6940069f 227#define isnan _isnan /* ...same libraries as MSVC */
44604af1 228#endif
910dfcc8 229
ac4c12e7
GS
230#ifndef _O_NOINHERIT
231# define _O_NOINHERIT 0x0080
232# ifndef _NO_OLDNAMES
233# define O_NOINHERIT _O_NOINHERIT
234# endif
235#endif
236
8659febc
S
237/* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
238 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
239#ifdef _STDINT_H
240# ifndef _INTPTR_T_DEFINED
241# define _INTPTR_T_DEFINED
242# endif
243# ifndef _UINTPTR_T_DEFINED
244# define _UINTPTR_T_DEFINED
245# endif
246#endif
247
f8fb7c90
GS
248#ifndef CP_UTF8
249# define CP_UTF8 65001
250#endif
251
70764c00
SH
252#endif /* __MINGW32__ */
253
c623ac67
GS
254#ifndef _INTPTR_T_DEFINED
255typedef int intptr_t;
256# define _INTPTR_T_DEFINED
257#endif
258
259#ifndef _UINTPTR_T_DEFINED
260typedef unsigned int uintptr_t;
261# define _UINTPTR_T_DEFINED
262#endif
263
390b85e7 264START_EXTERN_C
f3986ebb
GS
265
266/* For UNIX compatibility. */
267
0a753a76 268extern uid_t getuid(void);
269extern gid_t getgid(void);
270extern uid_t geteuid(void);
271extern gid_t getegid(void);
0a753a76 272extern int setuid(uid_t uid);
273extern int setgid(gid_t gid);
274extern int kill(int pid, int sig);
542cb85f 275extern int killpg(int pid, int sig);
c623ac67
GS
276#ifndef USE_PERL_SBRK
277extern void *sbrk(ptrdiff_t need);
278# define HAS_SBRK_PROTO
279#endif
e34ffe5a 280extern char * getlogin(void);
b990f8c8 281extern int chown(const char *p, uid_t o, gid_t g);
00b02797 282extern int mkstemp(const char *path);
d55594ae 283
f3986ebb
GS
284#undef Stat
285#define Stat win32_stat
3e3baf6d 286
f3986ebb
GS
287#undef init_os_extras
288#define init_os_extras Perl_init_os_extras
390b85e7 289
22239a37 290DllExport void Perl_win32_init(int *argcp, char ***argvp);
23f519f0 291DllExport void Perl_win32_term(void);
cb359b41 292DllExport void Perl_init_os_extras(void);
c5be433b
GS
293DllExport void win32_str_os_error(void *sv, DWORD err);
294DllExport int RunPerl(int argc, char **argv, char **env);
0551aaa8 295
635bbe87
GS
296typedef struct {
297 HANDLE childStdIn;
298 HANDLE childStdOut;
299 HANDLE childStdErr;
f83751a7
GS
300 /*
301 * the following correspond to the fields of the same name
302 * in the STARTUPINFO structure. Embedders can use these to
303 * control the spawning process' look.
304 * Example - to hide the window of the spawned process:
305 * dwFlags = STARTF_USESHOWWINDOW;
306 * wShowWindow = SW_HIDE;
307 */
308 DWORD dwFlags;
3fadfdf1
NIS
309 DWORD dwX;
310 DWORD dwY;
311 DWORD dwXSize;
312 DWORD dwYSize;
313 DWORD dwXCountChars;
314 DWORD dwYCountChars;
f83751a7 315 DWORD dwFillAttribute;
3fadfdf1 316 WORD wShowWindow;
635bbe87
GS
317} child_IO_table;
318
319DllExport void win32_get_child_IO(child_IO_table* ptr);
b69b0499 320DllExport HWND win32_create_message_window(void);
635bbe87 321
f3986ebb
GS
322#ifndef USE_SOCKETS_AS_HANDLES
323extern FILE * my_fdopen(int, char *);
d55594ae 324#endif
f3986ebb 325extern int my_fclose(FILE *);
e6a0bbf8
NC
326extern char * win32_get_privlib(const char *pl, STRLEN *const len);
327extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
328extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
d55594ae 329
1c0ca838
GS
330#ifdef PERL_IMPLICIT_SYS
331extern void win32_delete_internal_host(void *h);
332#endif
333
f3986ebb 334extern char * staticlinkmodules[];
390b85e7
GS
335
336END_EXTERN_C
d55594ae 337
68dc0745 338typedef char * caddr_t; /* In malloc.c (core address). */
0a753a76 339
68dc0745 340/*
68dc0745 341 * handle socket stuff, assuming socket is always available
342 */
0a753a76 343#include <sys/socket.h>
344#include <netdb.h>
345
bbc8f9de
NIS
346#ifdef MYMALLOC
347#define EMBEDMYMALLOC /**/
348/* #define USE_PERL_SBRK /**/
349/* #define PERL_SBRK_VIA_MALLOC /**/
350#endif
351
e68cb057 352#ifdef PERL_TEXTMODE_SCRIPTS
c39cd008 353# define PERL_SCRIPT_MODE "r"
a868473f 354#else
c39cd008 355# define PERL_SCRIPT_MODE "rb"
a868473f
NIS
356#endif
357
3fadfdf1
NIS
358/*
359 * Now Win32 specific per-thread data stuff
3352bfcb
GS
360 */
361
aeecf691
JD
362/* Leave the first couple ids after WM_USER unused because they
363 * might be used by an embedding application, and on Windows
364 * version before 2000 we might end up eating those messages
365 * if they were not meant for us.
366 */
367#define WM_USER_MIN (WM_USER+30)
368#define WM_USER_MESSAGE (WM_USER_MIN)
369#define WM_USER_KILL (WM_USER_MIN+1)
370#define WM_USER_MAX (WM_USER_MIN+1)
371
3352bfcb
GS
372struct thread_intern {
373 /* XXX can probably use one buffer instead of several */
374 char Wstrerror_buffer[512];
375 struct servent Wservent;
376 char Wgetlogin_buffer[128];
f4257e4d
YO
377# ifdef USE_SOCKETS_AS_HANDLES
378 int Winit_socktype;
379# endif
3352bfcb 380 char Wcrypt_buffer[30];
3352bfcb
GS
381# ifdef USE_RTL_THREAD_API
382 void * retv; /* slot for thread return value */
383# endif
02637f4c
JD
384 BOOL Wuse_showwindow;
385 WORD Wshowwindow;
3352bfcb
GS
386};
387
4b556e6c 388#define HAVE_INTERP_INTERN
0aaad0ff
GS
389typedef struct {
390 long num;
391 DWORD pids[MAXIMUM_WAIT_OBJECTS];
7766f137 392 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
0aaad0ff
GS
393} child_tab;
394
aeecf691
JD
395#ifdef USE_ITHREADS
396typedef struct {
397 long num;
398 DWORD pids[MAXIMUM_WAIT_OBJECTS];
399 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
400 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
8a3cb9c6 401 char sigterm[MAXIMUM_WAIT_OBJECTS];
aeecf691
JD
402} pseudo_child_tab;
403#endif
404
3fadfdf1
NIS
405#ifndef Sighandler_t
406typedef Signal_t (*Sighandler_t) (int);
407#define Sighandler_t Sighandler_t
408#endif
409
4b556e6c 410struct interp_intern {
0aaad0ff
GS
411 char * perlshell_tokens;
412 char ** perlshell_vec;
413 long perlshell_items;
414 struct av * fdpid;
415 child_tab * children;
7766f137
GS
416#ifdef USE_ITHREADS
417 DWORD pseudo_id;
aeecf691 418 pseudo_child_tab * pseudo_children;
7766f137
GS
419#endif
420 void * internal_host;
3352bfcb 421 struct thread_intern thr_intern;
aeecf691 422 HWND message_hwnd;
8fb3fcfb 423 UINT timerid;
05ec9bb3 424 unsigned poll_count;
3fadfdf1 425 Sighandler_t sigtable[SIG_SIZE];
4b556e6c
JD
426};
427
8fb3fcfb
NIS
428DllExport int win32_async_check(pTHX);
429
05ec9bb3 430#define WIN32_POLL_INTERVAL 32768
8fb3fcfb 431#define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
4b556e6c 432
0aaad0ff
GS
433#define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
434#define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
435#define w32_perlshell_items (PL_sys_intern.perlshell_items)
436#define w32_fdpid (PL_sys_intern.fdpid)
437#define w32_children (PL_sys_intern.children)
438#define w32_num_children (w32_children->num)
439#define w32_child_pids (w32_children->pids)
7766f137
GS
440#define w32_child_handles (w32_children->handles)
441#define w32_pseudo_id (PL_sys_intern.pseudo_id)
442#define w32_pseudo_children (PL_sys_intern.pseudo_children)
443#define w32_num_pseudo_children (w32_pseudo_children->num)
444#define w32_pseudo_child_pids (w32_pseudo_children->pids)
445#define w32_pseudo_child_handles (w32_pseudo_children->handles)
aeecf691 446#define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
8a3cb9c6 447#define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
7766f137 448#define w32_internal_host (PL_sys_intern.internal_host)
8fb3fcfb 449#define w32_timerid (PL_sys_intern.timerid)
aeecf691 450#define w32_message_hwnd (PL_sys_intern.message_hwnd)
3fadfdf1 451#define w32_sighandler (PL_sys_intern.sigtable)
05ec9bb3
NIS
452#define w32_poll_count (PL_sys_intern.poll_count)
453#define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
3db8f154
MB
454#define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
455#define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
456#define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
457#define w32_servent (PL_sys_intern.thr_intern.Wservent)
f4257e4d 458#define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
3db8f154
MB
459#define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
460#define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
c53bd28a 461
7766f137 462#ifdef USE_ITHREADS
8a3cb9c6
JD
463void win32_wait_for_children(pTHX);
464# define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
7766f137
GS
465#endif
466
3fadfdf1 467/* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
6e22d046
JH
468#if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
469#undef PERLIO_NOT_STDIO
470#endif
adb71456
NIS
471#define PERLIO_NOT_STDIO 0
472
473#include "perlio.h"
474
4f63d024
GS
475/*
476 * This provides a layer of functions and macros to ensure extensions will
477 * get to use the same RTL functions as the core.
478 */
479#include "win32iop.h"
480
b4748376
NIS
481#define EXEC_ARGV_CAST(x) ((const char *const *) x)
482
f4958739 483DllExport void *win32_signal_context(void);
1018e26f
NIS
484#define PERL_GET_SIG_CONTEXT win32_signal_context()
485
45496817 486#ifdef UNDER_CE
7bd379e8
YO
487#define Win_GetModuleHandle XCEGetModuleHandleA
488#define Win_GetProcAddress XCEGetProcAddressA
489#define Win_GetModuleFileName XCEGetModuleFileNameA
490#define Win_CreateSemaphore CreateSemaphoreW
491#else
492#define Win_GetModuleHandle GetModuleHandle
493#define Win_GetProcAddress GetProcAddress
494#define Win_GetModuleFileName GetModuleFileName
495#define Win_CreateSemaphore CreateSemaphore
496#endif
497
68dc0745 498#endif /* _INC_WIN32_PERL5 */
7a9ec5a3 499