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