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