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 #ifdef PERL_IS_MINIPERL
17 /* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and
18 * makedef.pl create dependencies that will keep Winsock linked in even with
19 * this macro defined, even though sockets will be umimplemented from a script
22 # define WIN32_NO_SOCKETS
25 #ifdef WIN32_NO_SOCKETS
27 # undef HAS_GETPROTOBYNAME
28 # undef HAS_GETPROTOBYNUMBER
29 # undef HAS_GETPROTOENT
30 # undef HAS_GETNETBYNAME
31 # undef HAS_GETNETBYADDR
33 # undef HAS_GETSERVBYNAME
34 # undef HAS_GETSERVBYPORT
35 # undef HAS_GETSERVENT
36 # undef HAS_GETHOSTBYNAME
37 # undef HAS_GETHOSTBYADDR
38 # undef HAS_GETHOSTENT
45 # define WIN32SCK_IS_STDSCK
48 #if defined(PERL_IMPLICIT_SYS)
49 # define DYNAMIC_ENV_FETCH
50 # define HAS_GETENV_LEN
51 # define prime_env_iter()
52 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
53 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
54 # ifdef PERL_GLOBAL_STRUCT
55 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
57 # define win32_get_privlib PerlEnv_lib_path
58 # define win32_get_sitelib PerlEnv_sitelib_path
59 # define win32_get_vendorlib PerlEnv_vendorlib_path
63 # ifndef __int64 /* some versions seem to #define it already */
64 # define __int64 long long
66 # define Win32_Winsock
68 /* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
69 #undef PERL_UNUSED_DECL
70 #define PERL_UNUSED_DECL
75 /* Define DllExport akin to perl's EXT,
76 * If we are in the DLL then Export the symbol,
77 * otherwise import it.
80 /* now even GCC supports __declspec() */
81 /* miniperl has no reason to export anything */
82 #if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
86 # define DllExport __declspec(dllexport)
88 # define DllExport __declspec(dllimport)
92 /* The Perl APIs can only be called directly inside the perl5xx.dll.
93 * All other code has to import them. By declaring them as "dllimport"
94 * we tell the compiler to generate an indirect call instruction and
95 * avoid redirection through a call thunk.
97 * The XS code in the re extension is special, in that it redefines
98 * core APIs locally, so don't mark them as "dllimport" because GCC
99 * cannot handle this situation.
101 #if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
103 # define PERL_CALLCONV extern "C" __declspec(dllimport)
105 # define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
108 # define PERL_CALLCONV __declspec(dllimport)
110 # define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
113 #else /* MSVC noreturn support inside the interp */
115 # define PERL_CALLCONV_NO_RET __declspec(noreturn)
120 # define PERL_STATIC_NO_RET __declspec(noreturn) static
121 # define PERL_STATIC_INLINE_NO_RET __declspec(noreturn) PERL_STATIC_INLINE
124 #define WIN32_LEAN_AND_MEAN
128 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
129 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
130 * to declare GetEnvironmentStringsA.
132 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
136 #undef GetEnvironmentStringsA
137 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
138 #define GetEnvironmentStrings GetEnvironmentStringsA
144 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
145 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
146 #endif /*WIN32_LEAN_AND_MEAN */
148 #ifndef TLS_OUT_OF_INDEXES
149 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
176 char sysname[SYS_NMLN];
177 char nodename[SYS_NMLN];
178 char release[SYS_NMLN];
179 char version[SYS_NMLN];
180 char machine[SYS_NMLN];
183 #ifndef START_EXTERN_C
186 # define START_EXTERN_C extern "C" {
187 # define END_EXTERN_C }
188 # define EXTERN_C extern "C"
190 # define START_EXTERN_C
191 # define END_EXTERN_C
197 #define DOSISH 1 /* no escaping our roots */
198 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
200 /* read() and write() aren't transparent for socket handles */
201 #ifndef WIN32_NO_SOCKETS
202 # define PERL_SOCK_SYSREAD_IS_RECV
203 # define PERL_SOCK_SYSWRITE_IS_SEND
206 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
208 #define ENV_IS_CASELESS
210 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
212 /* access() mode bits */
225 #define PERL_GET_CONTEXT_DEFINED
227 /* Compiler-specific stuff. */
229 /* VC uses non-standard way to determine the size and alignment if bit-fields */
230 /* MinGW will compile with -mms-bitfields, so should use the same types */
231 #define PERL_BITFIELD8 unsigned char
232 #define PERL_BITFIELD16 unsigned short
233 #define PERL_BITFIELD32 unsigned int
235 #ifdef _MSC_VER /* Microsoft Visual C++ */
240 typedef unsigned short mode_t;
243 #pragma warning(disable: 4102) /* "unreferenced label" */
246 #define snprintf _snprintf
247 #define vsnprintf _vsnprintf
250 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
251 #define NAN_COMPARE_BROKEN 1
254 #endif /* _MSC_VER */
256 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
261 #define _environ environ
263 #define flushall _flushall
264 #define fcloseall _fcloseall
266 #define isnan _isnan /* ...same libraries as MSVC */
270 # define _O_NOINHERIT 0x0080
271 # ifndef _NO_OLDNAMES
272 # define O_NOINHERIT _O_NOINHERIT
276 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
277 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
279 # ifndef _INTPTR_T_DEFINED
280 # define _INTPTR_T_DEFINED
282 # ifndef _UINTPTR_T_DEFINED
283 # define _UINTPTR_T_DEFINED
288 # define CP_UTF8 65001
291 #endif /* __MINGW32__ */
293 #ifndef _INTPTR_T_DEFINED
294 typedef int intptr_t;
295 # define _INTPTR_T_DEFINED
298 #ifndef _UINTPTR_T_DEFINED
299 typedef unsigned int uintptr_t;
300 # define _UINTPTR_T_DEFINED
305 /* For UNIX compatibility. */
308 extern uid_t getuid(void);
309 extern gid_t getgid(void);
310 extern uid_t geteuid(void);
311 extern gid_t getegid(void);
312 extern int setuid(uid_t uid);
313 extern int setgid(gid_t gid);
314 extern int kill(int pid, int sig);
315 extern int killpg(int pid, int sig);
316 #ifndef USE_PERL_SBRK
317 extern void *sbrk(ptrdiff_t need);
318 # define HAS_SBRK_PROTO
320 extern char * getlogin(void);
321 extern int chown(const char *p, uid_t o, gid_t g);
322 extern int mkstemp(const char *path);
326 #define Stat win32_stat
328 #undef init_os_extras
329 #define init_os_extras Perl_init_os_extras
331 DllExport void Perl_win32_init(int *argcp, char ***argvp);
332 DllExport void Perl_win32_term(void);
333 DllExport void Perl_init_os_extras(void);
334 DllExport void win32_str_os_error(void *sv, DWORD err);
335 DllExport int RunPerl(int argc, char **argv, char **env);
342 * the following correspond to the fields of the same name
343 * in the STARTUPINFO structure. Embedders can use these to
344 * control the spawning process' look.
345 * Example - to hide the window of the spawned process:
346 * dwFlags = STARTF_USESHOWWINDOW;
347 * wShowWindow = SW_HIDE;
356 DWORD dwFillAttribute;
360 DllExport void win32_get_child_IO(child_IO_table* ptr);
361 DllExport HWND win32_create_message_window(void);
363 extern int my_fclose(FILE *);
364 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
365 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
366 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
368 #ifdef PERL_IMPLICIT_SYS
369 extern void win32_delete_internal_host(void *h);
372 extern const char * const staticlinkmodules[];
376 typedef char * caddr_t; /* In malloc.c (core address). */
379 * handle socket stuff, assuming socket is always available
381 #include <sys/socket.h>
385 #define EMBEDMYMALLOC /**/
386 /* #define USE_PERL_SBRK /**/
387 /* #define PERL_SBRK_VIA_MALLOC /**/
390 #ifdef PERL_TEXTMODE_SCRIPTS
391 # define PERL_SCRIPT_MODE "r"
393 # define PERL_SCRIPT_MODE "rb"
397 * Now Win32 specific per-thread data stuff
400 /* Leave the first couple ids after WM_USER unused because they
401 * might be used by an embedding application, and on Windows
402 * version before 2000 we might end up eating those messages
403 * if they were not meant for us.
405 #define WM_USER_MIN (WM_USER+30)
406 #define WM_USER_MESSAGE (WM_USER_MIN)
407 #define WM_USER_KILL (WM_USER_MIN+1)
408 #define WM_USER_MAX (WM_USER_MIN+1)
410 struct thread_intern {
411 /* XXX can probably use one buffer instead of several */
412 char Wstrerror_buffer[512];
413 struct servent Wservent;
414 char Wgetlogin_buffer[128];
416 char Wcrypt_buffer[30];
417 # ifdef USE_RTL_THREAD_API
418 void * retv; /* slot for thread return value */
420 BOOL Wuse_showwindow;
424 #define HAVE_INTERP_INTERN
427 DWORD pids[MAXIMUM_WAIT_OBJECTS];
428 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
434 DWORD pids[MAXIMUM_WAIT_OBJECTS];
435 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
436 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
437 char sigterm[MAXIMUM_WAIT_OBJECTS];
442 typedef Signal_t (*Sighandler_t) (int);
443 #define Sighandler_t Sighandler_t
446 struct interp_intern {
447 char * perlshell_tokens;
448 char ** perlshell_vec;
449 long perlshell_items;
451 child_tab * children;
454 pseudo_child_tab * pseudo_children;
456 void * internal_host;
457 struct thread_intern thr_intern;
461 Sighandler_t sigtable[SIG_SIZE];
464 DllExport int win32_async_check(pTHX);
466 #define WIN32_POLL_INTERVAL 32768
467 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
469 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
470 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
471 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
472 #define w32_fdpid (PL_sys_intern.fdpid)
473 #define w32_children (PL_sys_intern.children)
474 #define w32_num_children (w32_children->num)
475 #define w32_child_pids (w32_children->pids)
476 #define w32_child_handles (w32_children->handles)
477 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
478 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
479 #define w32_num_pseudo_children (w32_pseudo_children->num)
480 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
481 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
482 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
483 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
484 #define w32_internal_host (PL_sys_intern.internal_host)
485 #define w32_timerid (PL_sys_intern.timerid)
486 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
487 #define w32_sighandler (PL_sys_intern.sigtable)
488 #define w32_poll_count (PL_sys_intern.poll_count)
489 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
490 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
491 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
492 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
493 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
494 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
495 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
496 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
499 void win32_wait_for_children(pTHX);
500 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
503 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
504 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
505 #undef PERLIO_NOT_STDIO
507 #define PERLIO_NOT_STDIO 0
512 * This provides a layer of functions and macros to ensure extensions will
513 * get to use the same RTL functions as the core.
515 #include "win32iop.h"
517 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
519 DllExport void *win32_signal_context(void);
520 #define PERL_GET_SIG_CONTEXT win32_signal_context()
523 #define Win_GetModuleHandle XCEGetModuleHandleA
524 #define Win_GetProcAddress XCEGetProcAddressA
525 #define Win_GetModuleFileName XCEGetModuleFileNameA
526 #define Win_CreateSemaphore CreateSemaphoreW
528 #define Win_GetModuleHandle GetModuleHandle
529 #define Win_GetProcAddress GetProcAddress
530 #define Win_GetModuleFileName GetModuleFileName
531 #define Win_CreateSemaphore CreateSemaphore
534 #endif /* _INC_WIN32_PERL5 */