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() */
51 #define DllExport __declspec(dllexport)
53 #define DllExport __declspec(dllimport)
56 /* The Perl APIs can only be called directly inside the perl5xx.dll.
57 * All other code has to import them. By declaring them as "dllimport"
58 * we tell the compiler to generate an indirect call instruction and
59 * avoid redirection through a call thunk.
61 * The XS code in the re extension is special, in that it redefines
62 * core APIs locally, so don't mark them as "dllimport" because GCC
63 * cannot handle this situation.
65 #if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
67 # define PERL_CALLCONV extern "C" __declspec(dllimport)
69 # define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
72 # define PERL_CALLCONV __declspec(dllimport)
74 # define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
77 #else /* MSVC noreturn support inside the interp */
79 # define PERL_CALLCONV_NO_RET __declspec(noreturn)
83 #define WIN32_LEAN_AND_MEAN
87 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
88 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
89 * to declare GetEnvironmentStringsA.
91 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
95 #undef GetEnvironmentStringsA
96 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
97 #define GetEnvironmentStrings GetEnvironmentStringsA
103 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
104 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
105 #endif /*WIN32_LEAN_AND_MEAN */
107 #ifndef TLS_OUT_OF_INDEXES
108 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
135 char sysname[SYS_NMLN];
136 char nodename[SYS_NMLN];
137 char release[SYS_NMLN];
138 char version[SYS_NMLN];
139 char machine[SYS_NMLN];
142 #ifndef START_EXTERN_C
145 # define START_EXTERN_C extern "C" {
146 # define END_EXTERN_C }
147 # define EXTERN_C extern "C"
149 # define START_EXTERN_C
150 # define END_EXTERN_C
156 #define DOSISH 1 /* no escaping our roots */
157 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
159 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
160 * real filehandles. XXX Should always be defined (the other version is untested) */
161 #define USE_SOCKETS_AS_HANDLES
163 /* read() and write() aren't transparent for socket handles */
164 #define PERL_SOCK_SYSREAD_IS_RECV
165 #define PERL_SOCK_SYSWRITE_IS_SEND
167 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
169 #define ENV_IS_CASELESS
171 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
173 /* access() mode bits */
186 #define PERL_GET_CONTEXT_DEFINED
188 /* Compiler-specific stuff. */
190 /* VC uses non-standard way to determine the size and alignment if bit-fields */
191 /* MinGW will compile with -mms-bitfields, so should use the same types */
192 #define PERL_BITFIELD8 unsigned char
193 #define PERL_BITFIELD16 unsigned short
194 #define PERL_BITFIELD32 unsigned int
196 #ifdef _MSC_VER /* Microsoft Visual C++ */
201 typedef unsigned short mode_t;
204 #pragma warning(disable: 4102) /* "unreferenced label" */
207 #define snprintf _snprintf
208 #define vsnprintf _vsnprintf
211 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
212 #define NAN_COMPARE_BROKEN 1
215 #endif /* _MSC_VER */
217 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
222 #define _environ environ
224 #define flushall _flushall
225 #define fcloseall _fcloseall
227 #define isnan _isnan /* ...same libraries as MSVC */
231 # define _O_NOINHERIT 0x0080
232 # ifndef _NO_OLDNAMES
233 # define O_NOINHERIT _O_NOINHERIT
237 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
238 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
240 # ifndef _INTPTR_T_DEFINED
241 # define _INTPTR_T_DEFINED
243 # ifndef _UINTPTR_T_DEFINED
244 # define _UINTPTR_T_DEFINED
249 # define CP_UTF8 65001
252 #endif /* __MINGW32__ */
254 #ifndef _INTPTR_T_DEFINED
255 typedef int intptr_t;
256 # define _INTPTR_T_DEFINED
259 #ifndef _UINTPTR_T_DEFINED
260 typedef unsigned int uintptr_t;
261 # define _UINTPTR_T_DEFINED
266 /* For UNIX compatibility. */
268 extern uid_t getuid(void);
269 extern gid_t getgid(void);
270 extern uid_t geteuid(void);
271 extern gid_t getegid(void);
272 extern int setuid(uid_t uid);
273 extern int setgid(gid_t gid);
274 extern int kill(int pid, int sig);
275 extern int killpg(int pid, int sig);
276 #ifndef USE_PERL_SBRK
277 extern void *sbrk(ptrdiff_t need);
278 # define HAS_SBRK_PROTO
280 extern char * getlogin(void);
281 extern int chown(const char *p, uid_t o, gid_t g);
282 extern int mkstemp(const char *path);
285 #define Stat win32_stat
287 #undef init_os_extras
288 #define init_os_extras Perl_init_os_extras
290 DllExport void Perl_win32_init(int *argcp, char ***argvp);
291 DllExport void Perl_win32_term(void);
292 DllExport void Perl_init_os_extras(void);
293 DllExport void win32_str_os_error(void *sv, DWORD err);
294 DllExport int RunPerl(int argc, char **argv, char **env);
301 * the following correspond to the fields of the same name
302 * in the STARTUPINFO structure. Embedders can use these to
303 * control the spawning process' look.
304 * Example - to hide the window of the spawned process:
305 * dwFlags = STARTF_USESHOWWINDOW;
306 * wShowWindow = SW_HIDE;
315 DWORD dwFillAttribute;
319 DllExport void win32_get_child_IO(child_IO_table* ptr);
320 DllExport HWND win32_create_message_window(void);
322 #ifndef USE_SOCKETS_AS_HANDLES
323 extern FILE * my_fdopen(int, char *);
325 extern int my_fclose(FILE *);
326 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
327 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
328 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
330 #ifdef PERL_IMPLICIT_SYS
331 extern void win32_delete_internal_host(void *h);
334 extern char * staticlinkmodules[];
338 typedef char * caddr_t; /* In malloc.c (core address). */
341 * handle socket stuff, assuming socket is always available
343 #include <sys/socket.h>
347 #define EMBEDMYMALLOC /**/
348 /* #define USE_PERL_SBRK /**/
349 /* #define PERL_SBRK_VIA_MALLOC /**/
352 #ifdef PERL_TEXTMODE_SCRIPTS
353 # define PERL_SCRIPT_MODE "r"
355 # define PERL_SCRIPT_MODE "rb"
359 * Now Win32 specific per-thread data stuff
362 /* Leave the first couple ids after WM_USER unused because they
363 * might be used by an embedding application, and on Windows
364 * version before 2000 we might end up eating those messages
365 * if they were not meant for us.
367 #define WM_USER_MIN (WM_USER+30)
368 #define WM_USER_MESSAGE (WM_USER_MIN)
369 #define WM_USER_KILL (WM_USER_MIN+1)
370 #define WM_USER_MAX (WM_USER_MIN+1)
372 struct thread_intern {
373 /* XXX can probably use one buffer instead of several */
374 char Wstrerror_buffer[512];
375 struct servent Wservent;
376 char Wgetlogin_buffer[128];
377 # ifdef USE_SOCKETS_AS_HANDLES
380 char Wcrypt_buffer[30];
381 # ifdef USE_RTL_THREAD_API
382 void * retv; /* slot for thread return value */
384 BOOL Wuse_showwindow;
388 #define HAVE_INTERP_INTERN
391 DWORD pids[MAXIMUM_WAIT_OBJECTS];
392 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
398 DWORD pids[MAXIMUM_WAIT_OBJECTS];
399 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
400 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
401 char sigterm[MAXIMUM_WAIT_OBJECTS];
406 typedef Signal_t (*Sighandler_t) (int);
407 #define Sighandler_t Sighandler_t
410 struct interp_intern {
411 char * perlshell_tokens;
412 char ** perlshell_vec;
413 long perlshell_items;
415 child_tab * children;
418 pseudo_child_tab * pseudo_children;
420 void * internal_host;
421 struct thread_intern thr_intern;
425 Sighandler_t sigtable[SIG_SIZE];
428 DllExport int win32_async_check(pTHX);
430 #define WIN32_POLL_INTERVAL 32768
431 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
433 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
434 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
435 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
436 #define w32_fdpid (PL_sys_intern.fdpid)
437 #define w32_children (PL_sys_intern.children)
438 #define w32_num_children (w32_children->num)
439 #define w32_child_pids (w32_children->pids)
440 #define w32_child_handles (w32_children->handles)
441 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
442 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
443 #define w32_num_pseudo_children (w32_pseudo_children->num)
444 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
445 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
446 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
447 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
448 #define w32_internal_host (PL_sys_intern.internal_host)
449 #define w32_timerid (PL_sys_intern.timerid)
450 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
451 #define w32_sighandler (PL_sys_intern.sigtable)
452 #define w32_poll_count (PL_sys_intern.poll_count)
453 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
454 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
455 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
456 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
457 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
458 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
459 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
460 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
463 void win32_wait_for_children(pTHX);
464 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
467 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
468 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
469 #undef PERLIO_NOT_STDIO
471 #define PERLIO_NOT_STDIO 0
476 * This provides a layer of functions and macros to ensure extensions will
477 * get to use the same RTL functions as the core.
479 #include "win32iop.h"
481 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
483 DllExport void *win32_signal_context(void);
484 #define PERL_GET_SIG_CONTEXT win32_signal_context()
487 #define Win_GetModuleHandle XCEGetModuleHandleA
488 #define Win_GetProcAddress XCEGetProcAddressA
489 #define Win_GetModuleFileName XCEGetModuleFileNameA
490 #define Win_CreateSemaphore CreateSemaphoreW
492 #define Win_GetModuleHandle GetModuleHandle
493 #define Win_GetProcAddress GetProcAddress
494 #define Win_GetModuleFileName GetModuleFileName
495 #define Win_CreateSemaphore CreateSemaphore
498 #endif /* _INC_WIN32_PERL5 */