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