3 * (c) 1995 Microsoft Corporation. All rights reserved.
4 * Developed by hip communications inc.
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.
9 #ifndef _INC_WIN32_PERL5
10 #define _INC_WIN32_PERL5
13 # define _WIN32_WINNT 0x0500 /* needed for CreateHardlink() etc. */
16 #if defined(PERL_IMPLICIT_SYS)
17 # define DYNAMIC_ENV_FETCH
18 # define HAS_GETENV_LEN
19 # define prime_env_iter()
20 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
21 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
22 # ifdef PERL_GLOBAL_STRUCT
23 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
25 # define win32_get_privlib PerlEnv_lib_path
26 # define win32_get_sitelib PerlEnv_sitelib_path
27 # define win32_get_vendorlib PerlEnv_vendorlib_path
31 # ifndef __int64 /* some versions seem to #define it already */
32 # define __int64 long long
34 # define Win32_Winsock
36 /* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
37 #undef PERL_UNUSED_DECL
38 #define PERL_UNUSED_DECL
43 /* Define DllExport akin to perl's EXT,
44 * If we are in the DLL then Export the symbol,
45 * otherwise import it.
48 /* now even GCC supports __declspec() */
52 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
54 #define DllExport __declspec(dllimport)
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.
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.
66 #if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
68 # define PERL_CALLCONV extern "C" __declspec(dllimport)
70 # define PERL_CALLCONV __declspec(dllimport)
74 #define WIN32_LEAN_AND_MEAN
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.
82 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
86 #undef GetEnvironmentStringsA
87 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
88 #define GetEnvironmentStrings GetEnvironmentStringsA
94 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
95 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
96 #endif /*WIN32_LEAN_AND_MEAN */
98 #ifndef TLS_OUT_OF_INDEXES
99 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
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];
133 #ifndef START_EXTERN_C
136 # define START_EXTERN_C extern "C" {
137 # define END_EXTERN_C }
138 # define EXTERN_C extern "C"
140 # define START_EXTERN_C
141 # define END_EXTERN_C
147 #define DOSISH 1 /* no escaping our roots */
148 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
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
154 /* read() and write() aren't transparent for socket handles */
155 #define PERL_SOCK_SYSREAD_IS_RECV
156 #define PERL_SOCK_SYSWRITE_IS_SEND
158 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
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)
163 #if !(defined(_M_IX86) && _MSC_VER >= 1200)
164 #define PERL_WIN32_SOCK_DLOAD
166 #define ENV_IS_CASELESS
168 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
170 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
171 #define VER_PLATFORM_WIN32_WINDOWS 1
174 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
175 #define FILE_SHARE_DELETE 0x00000004
178 /* access() mode bits */
191 #define PERL_GET_CONTEXT_DEFINED
193 /* Compiler-specific stuff. */
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
203 #ifdef _MSC_VER /* Microsoft Visual C++ */
208 typedef unsigned short mode_t;
211 #pragma warning(disable: 4102) /* "unreferenced label" */
213 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
214 #define PERL_MEMBER_PTR_SIZE 16
217 #define snprintf _snprintf
218 #define vsnprintf _vsnprintf
221 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
222 #define NAN_COMPARE_BROKEN 1
225 #endif /* _MSC_VER */
227 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
232 #define _environ environ
234 #define flushall _flushall
235 #define fcloseall _fcloseall
237 #define isnan _isnan /* ...same libraries as MSVC */
241 # define _O_NOINHERIT 0x0080
242 # ifndef _NO_OLDNAMES
243 # define O_NOINHERIT _O_NOINHERIT
247 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
248 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
250 # ifndef _INTPTR_T_DEFINED
251 # define _INTPTR_T_DEFINED
253 # ifndef _UINTPTR_T_DEFINED
254 # define _UINTPTR_T_DEFINED
258 #endif /* __MINGW32__ */
260 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
262 # define CP_UTF8 65001
265 /* compatibility stuff for other compilers goes here */
267 #ifndef _INTPTR_T_DEFINED
268 typedef int intptr_t;
269 # define _INTPTR_T_DEFINED
272 #ifndef _UINTPTR_T_DEFINED
273 typedef unsigned int uintptr_t;
274 # define _UINTPTR_T_DEFINED
279 /* For UNIX compatibility. */
281 extern uid_t getuid(void);
282 extern gid_t getgid(void);
283 extern uid_t geteuid(void);
284 extern gid_t getegid(void);
285 extern int setuid(uid_t uid);
286 extern int setgid(gid_t gid);
287 extern int kill(int pid, int sig);
288 extern int killpg(int pid, int sig);
289 #ifndef USE_PERL_SBRK
290 extern void *sbrk(ptrdiff_t need);
291 # define HAS_SBRK_PROTO
293 extern char * getlogin(void);
294 extern int chown(const char *p, uid_t o, gid_t g);
295 extern int mkstemp(const char *path);
298 #define Stat win32_stat
300 #undef init_os_extras
301 #define init_os_extras Perl_init_os_extras
303 DllExport void Perl_win32_init(int *argcp, char ***argvp);
304 DllExport void Perl_win32_term(void);
305 DllExport void Perl_init_os_extras(void);
306 DllExport void win32_str_os_error(void *sv, DWORD err);
307 DllExport int RunPerl(int argc, char **argv, char **env);
314 * the following correspond to the fields of the same name
315 * in the STARTUPINFO structure. Embedders can use these to
316 * control the spawning process' look.
317 * Example - to hide the window of the spawned process:
318 * dwFlags = STARTF_USESHOWWINDOW;
319 * wShowWindow = SW_HIDE;
328 DWORD dwFillAttribute;
332 DllExport void win32_get_child_IO(child_IO_table* ptr);
333 DllExport HWND win32_create_message_window(void);
335 #ifndef USE_SOCKETS_AS_HANDLES
336 extern FILE * my_fdopen(int, char *);
338 extern int my_fclose(FILE *);
339 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
340 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
341 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
343 #ifdef PERL_IMPLICIT_SYS
344 extern void win32_delete_internal_host(void *h);
347 extern char * staticlinkmodules[];
351 typedef char * caddr_t; /* In malloc.c (core address). */
354 * handle socket stuff, assuming socket is always available
356 #include <sys/socket.h>
360 #define EMBEDMYMALLOC /**/
361 /* #define USE_PERL_SBRK /**/
362 /* #define PERL_SBRK_VIA_MALLOC /**/
365 #ifdef PERL_TEXTMODE_SCRIPTS
366 # define PERL_SCRIPT_MODE "r"
368 # define PERL_SCRIPT_MODE "rb"
372 * Now Win32 specific per-thread data stuff
375 /* Leave the first couple ids after WM_USER unused because they
376 * might be used by an embedding application, and on Windows
377 * version before 2000 we might end up eating those messages
378 * if they were not meant for us.
380 #define WM_USER_MIN (WM_USER+30)
381 #define WM_USER_MESSAGE (WM_USER_MIN)
382 #define WM_USER_KILL (WM_USER_MIN+1)
383 #define WM_USER_MAX (WM_USER_MIN+1)
385 struct thread_intern {
386 /* XXX can probably use one buffer instead of several */
387 char Wstrerror_buffer[512];
388 struct servent Wservent;
389 char Wgetlogin_buffer[128];
390 # ifdef USE_SOCKETS_AS_HANDLES
393 char Wcrypt_buffer[30];
394 # ifdef USE_RTL_THREAD_API
395 void * retv; /* slot for thread return value */
397 BOOL Wuse_showwindow;
401 #define HAVE_INTERP_INTERN
404 DWORD pids[MAXIMUM_WAIT_OBJECTS];
405 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
411 DWORD pids[MAXIMUM_WAIT_OBJECTS];
412 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
413 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
414 char sigterm[MAXIMUM_WAIT_OBJECTS];
419 typedef Signal_t (*Sighandler_t) (int);
420 #define Sighandler_t Sighandler_t
423 struct interp_intern {
424 char * perlshell_tokens;
425 char ** perlshell_vec;
426 long perlshell_items;
428 child_tab * children;
431 pseudo_child_tab * pseudo_children;
433 void * internal_host;
434 struct thread_intern thr_intern;
438 Sighandler_t sigtable[SIG_SIZE];
441 DllExport int win32_async_check(pTHX);
443 #define WIN32_POLL_INTERVAL 32768
444 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
446 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
447 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
448 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
449 #define w32_fdpid (PL_sys_intern.fdpid)
450 #define w32_children (PL_sys_intern.children)
451 #define w32_num_children (w32_children->num)
452 #define w32_child_pids (w32_children->pids)
453 #define w32_child_handles (w32_children->handles)
454 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
455 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
456 #define w32_num_pseudo_children (w32_pseudo_children->num)
457 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
458 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
459 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
460 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
461 #define w32_internal_host (PL_sys_intern.internal_host)
462 #define w32_timerid (PL_sys_intern.timerid)
463 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
464 #define w32_sighandler (PL_sys_intern.sigtable)
465 #define w32_poll_count (PL_sys_intern.poll_count)
466 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
467 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
468 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
469 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
470 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
471 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
472 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
473 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
476 void win32_wait_for_children(pTHX);
477 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
480 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
481 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
482 #undef PERLIO_NOT_STDIO
484 #define PERLIO_NOT_STDIO 0
489 * This provides a layer of functions and macros to ensure extensions will
490 * get to use the same RTL functions as the core.
492 #include "win32iop.h"
494 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
496 DllExport void *win32_signal_context(void);
497 #define PERL_GET_SIG_CONTEXT win32_signal_context()
500 #define Win_GetModuleHandle XCEGetModuleHandleA
501 #define Win_GetProcAddress XCEGetProcAddressA
502 #define Win_GetModuleFileName XCEGetModuleFileNameA
503 #define Win_CreateSemaphore CreateSemaphoreW
505 #define Win_GetModuleHandle GetModuleHandle
506 #define Win_GetProcAddress GetProcAddress
507 #define Win_GetModuleFileName GetModuleFileName
508 #define Win_CreateSemaphore CreateSemaphore
511 #endif /* _INC_WIN32_PERL5 */