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