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 0x0400 /* needed for TryEnterCriticalSection() 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 or mimicing the DLL for Win95 work round
45 * then Export the symbol,
46 * otherwise import it.
49 /* now even GCC supports __declspec() */
51 #if defined(PERLDLL) || defined(WIN95FIX)
53 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
55 #define DllExport __declspec(dllimport)
58 /* The Perl APIs can only be called directly inside the perl5xx.dll.
59 * All other code has to import them. By declaring them as "dllimport"
60 * we tell the compiler to generate an indirect call instruction and
61 * avoid redirection through a call thunk.
63 * The XS code in the re extension is special, in that it redefines
64 * core APIs locally, so don't mark them as "dllimport" because GCC
65 * cannot handle this situation.
67 #if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
69 # define PERL_CALLCONV extern "C" __declspec(dllimport)
71 # define PERL_CALLCONV __declspec(dllimport)
75 #define WIN32_LEAN_AND_MEAN
79 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
80 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
81 * to declare GetEnvironmentStringsA.
83 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
87 #undef GetEnvironmentStringsA
88 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
89 #define GetEnvironmentStrings GetEnvironmentStringsA
95 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
96 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
97 #endif /*WIN32_LEAN_AND_MEAN */
99 #ifndef TLS_OUT_OF_INDEXES
100 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
127 char sysname[SYS_NMLN];
128 char nodename[SYS_NMLN];
129 char release[SYS_NMLN];
130 char version[SYS_NMLN];
131 char machine[SYS_NMLN];
134 #ifndef START_EXTERN_C
137 # define START_EXTERN_C extern "C" {
138 # define END_EXTERN_C }
139 # define EXTERN_C extern "C"
141 # define START_EXTERN_C
142 # define END_EXTERN_C
148 #define DOSISH 1 /* no escaping our roots */
149 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
151 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
152 * real filehandles. XXX Should always be defined (the other version is untested) */
153 #define USE_SOCKETS_AS_HANDLES
155 /* read() and write() aren't transparent for socket handles */
156 #define PERL_SOCK_SYSREAD_IS_RECV
157 #define PERL_SOCK_SYSWRITE_IS_SEND
159 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
161 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
162 It now uses some black magic to work seamlessly with the DLL CRT and
163 works with MSVC++ 4.0+ or GCC/Mingw32
165 Only use this fix for VC++ 6.x or earlier (and for GCC, which we assume
166 uses MSVCRT.DLL). Later versions use MSVCR70.dll, MSVCR71.dll, etc, which
167 do not require the fix. */
168 #if (defined(_M_IX86) && _MSC_VER >= 1000 && _MSC_VER <= 1200) || defined(__MINGW32__)
169 #define USE_FIXED_OSFHANDLE
172 /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
173 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
175 #if !(defined(_M_IX86) && _MSC_VER >= 1200)
176 #define PERL_WIN32_SOCK_DLOAD
178 #define ENV_IS_CASELESS
180 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
182 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
183 #define VER_PLATFORM_WIN32_WINDOWS 1
186 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
187 #define FILE_SHARE_DELETE 0x00000004
190 /* access() mode bits */
203 #define PERL_GET_CONTEXT_DEFINED
205 /* Compiler-specific stuff. */
207 #if defined(_MSC_VER) || defined(__MINGW32__)
208 /* VC uses non-standard way to determine the size and alignment if bit-fields */
209 /* MinGW will compiler with -mms-bitfields, so should use the same types */
210 # define PERL_BITFIELD8 unsigned char
211 # define PERL_BITFIELD16 unsigned short
212 # define PERL_BITFIELD32 unsigned int
215 #ifdef __BORLANDC__ /* Borland C++ */
217 #if (__BORLANDC__ <= 0x520)
218 #define _access access
222 #define _getpid getpid
223 #define wcsicmp _wcsicmp
224 #include <sys/types.h>
227 #define DllMain DllEntryPoint
230 #pragma warn -8004 /* "'foo' is assigned a value that is never used" */
231 #pragma warn -8008 /* "condition is always true/false" */
232 #pragma warn -8012 /* "comparing signed and unsigned values" */
233 #pragma warn -8027 /* "functions containing %s are not expanded inline" */
234 #pragma warn -8057 /* "parameter 'foo' is never used" */
235 #pragma warn -8060 /* "possibly incorrect assignment" */
236 #pragma warn -8066 /* "unreachable code" */
237 #pragma warn -8071 /* "conversion may lose significant digits" */
238 #pragma warn -8080 /* "'foo' is declared but never used" */
240 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
241 #define PERL_MEMBER_PTR_SIZE 12
247 #ifdef _MSC_VER /* Microsoft Visual C++ */
252 typedef unsigned short mode_t;
255 #pragma warning(disable: 4102) /* "unreferenced label" */
257 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
258 #define PERL_MEMBER_PTR_SIZE 16
261 #define snprintf _snprintf
262 #define vsnprintf _vsnprintf
265 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
266 #define NAN_COMPARE_BROKEN 1
269 #endif /* _MSC_VER */
271 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
276 #define _environ environ
278 #define flushall _flushall
279 #define fcloseall _fcloseall
281 #define isnan _isnan /* ...same libraries as MSVC */
285 # define _O_NOINHERIT 0x0080
286 # ifndef _NO_OLDNAMES
287 # define O_NOINHERIT _O_NOINHERIT
291 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
292 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
294 # ifndef _INTPTR_T_DEFINED
295 # define _INTPTR_T_DEFINED
297 # ifndef _UINTPTR_T_DEFINED
298 # define _UINTPTR_T_DEFINED
302 #endif /* __MINGW32__ */
304 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
306 # define CP_UTF8 65001
309 /* compatibility stuff for other compilers goes here */
311 #ifndef _INTPTR_T_DEFINED
312 typedef int intptr_t;
313 # define _INTPTR_T_DEFINED
316 #ifndef _UINTPTR_T_DEFINED
317 typedef unsigned int uintptr_t;
318 # define _UINTPTR_T_DEFINED
323 /* For UNIX compatibility. */
325 extern uid_t getuid(void);
326 extern gid_t getgid(void);
327 extern uid_t geteuid(void);
328 extern gid_t getegid(void);
329 extern int setuid(uid_t uid);
330 extern int setgid(gid_t gid);
331 extern int kill(int pid, int sig);
332 extern int killpg(int pid, int sig);
333 #ifndef USE_PERL_SBRK
334 extern void *sbrk(ptrdiff_t need);
335 # define HAS_SBRK_PROTO
337 extern char * getlogin(void);
338 extern int chown(const char *p, uid_t o, gid_t g);
339 extern int mkstemp(const char *path);
342 #define Stat win32_stat
344 #undef init_os_extras
345 #define init_os_extras Perl_init_os_extras
347 DllExport void Perl_win32_init(int *argcp, char ***argvp);
348 DllExport void Perl_win32_term(void);
349 DllExport void Perl_init_os_extras(void);
350 DllExport void win32_str_os_error(void *sv, DWORD err);
351 DllExport int RunPerl(int argc, char **argv, char **env);
358 * the following correspond to the fields of the same name
359 * in the STARTUPINFO structure. Embedders can use these to
360 * control the spawning process' look.
361 * Example - to hide the window of the spawned process:
362 * dwFlags = STARTF_USESHOWWINDOW;
363 * wShowWindow = SW_HIDE;
372 DWORD dwFillAttribute;
376 DllExport void win32_get_child_IO(child_IO_table* ptr);
377 DllExport HWND win32_create_message_window(void);
379 #ifndef USE_SOCKETS_AS_HANDLES
380 extern FILE * my_fdopen(int, char *);
382 extern int my_fclose(FILE *);
383 extern int my_fstat(int fd, Stat_t *sbufptr);
384 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
385 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
386 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
387 extern int IsWin95(void);
388 extern int IsWinNT(void);
390 #ifdef PERL_IMPLICIT_SYS
391 extern void win32_delete_internal_host(void *h);
394 extern char * staticlinkmodules[];
398 typedef char * caddr_t; /* In malloc.c (core address). */
401 * handle socket stuff, assuming socket is always available
403 #include <sys/socket.h>
407 #define EMBEDMYMALLOC /**/
408 /* #define USE_PERL_SBRK /**/
409 /* #define PERL_SBRK_VIA_MALLOC /**/
412 #ifdef PERL_TEXTMODE_SCRIPTS
413 # define PERL_SCRIPT_MODE "r"
415 # define PERL_SCRIPT_MODE "rb"
419 * Now Win32 specific per-thread data stuff
422 /* Leave the first couple ids after WM_USER unused because they
423 * might be used by an embedding application, and on Windows
424 * version before 2000 we might end up eating those messages
425 * if they were not meant for us.
427 #define WM_USER_MIN (WM_USER+30)
428 #define WM_USER_MESSAGE (WM_USER_MIN)
429 #define WM_USER_KILL (WM_USER_MIN+1)
430 #define WM_USER_MAX (WM_USER_MIN+1)
432 struct thread_intern {
433 /* XXX can probably use one buffer instead of several */
434 char Wstrerror_buffer[512];
435 struct servent Wservent;
436 char Wgetlogin_buffer[128];
437 # ifdef USE_SOCKETS_AS_HANDLES
440 # ifdef HAVE_DES_FCRYPT
441 char Wcrypt_buffer[30];
443 # ifdef USE_RTL_THREAD_API
444 void * retv; /* slot for thread return value */
446 BOOL Wuse_showwindow;
450 #define HAVE_INTERP_INTERN
453 DWORD pids[MAXIMUM_WAIT_OBJECTS];
454 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
460 DWORD pids[MAXIMUM_WAIT_OBJECTS];
461 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
462 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
467 typedef Signal_t (*Sighandler_t) (int);
468 #define Sighandler_t Sighandler_t
471 struct interp_intern {
472 char * perlshell_tokens;
473 char ** perlshell_vec;
474 long perlshell_items;
476 child_tab * children;
479 pseudo_child_tab * pseudo_children;
481 void * internal_host;
482 struct thread_intern thr_intern;
486 Sighandler_t sigtable[SIG_SIZE];
489 DllExport int win32_async_check(pTHX);
491 #define WIN32_POLL_INTERVAL 32768
492 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
494 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
495 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
496 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
497 #define w32_fdpid (PL_sys_intern.fdpid)
498 #define w32_children (PL_sys_intern.children)
499 #define w32_num_children (w32_children->num)
500 #define w32_child_pids (w32_children->pids)
501 #define w32_child_handles (w32_children->handles)
502 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
503 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
504 #define w32_num_pseudo_children (w32_pseudo_children->num)
505 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
506 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
507 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
508 #define w32_internal_host (PL_sys_intern.internal_host)
509 #define w32_timerid (PL_sys_intern.timerid)
510 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
511 #define w32_sighandler (PL_sys_intern.sigtable)
512 #define w32_poll_count (PL_sys_intern.poll_count)
513 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
514 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
515 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
516 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
517 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
518 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
519 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
520 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
523 # define PERL_WAIT_FOR_CHILDREN \
525 if (w32_pseudo_children && w32_num_pseudo_children) { \
526 long children = w32_num_pseudo_children; \
527 WaitForMultipleObjects(children, \
528 w32_pseudo_child_handles, \
531 CloseHandle(w32_pseudo_child_handles[--children]); \
536 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
539 /* C doesn't like repeat struct definitions */
540 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
544 #define _CRTIMP __declspec(dllimport)
548 * Control structure for lowio file handles
551 intptr_t osfhnd;/* underlying OS file HANDLE */
552 char osfile; /* attributes of file (e.g., open in text mode?) */
553 char pipech; /* one char buffer for handles opened on pipes */
555 CRITICAL_SECTION lock;
560 * Array of arrays of control structures for lowio files.
562 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
565 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
566 * array of ioinfo structs.
571 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
573 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
576 * Access macros for getting at an ioinfo struct and its fields from a
579 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
580 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
581 #define _osfile(i) (_pioinfo(i)->osfile)
582 #define _pipech(i) (_pioinfo(i)->pipech)
584 /* since we are not doing a dup2(), this works fine */
585 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
589 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
590 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
591 #undef PERLIO_NOT_STDIO
593 #define PERLIO_NOT_STDIO 0
598 * This provides a layer of functions and macros to ensure extensions will
599 * get to use the same RTL functions as the core.
601 #include "win32iop.h"
603 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
605 #if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
606 #define ECONNABORTED WSAECONNABORTED
608 #if !defined(ECONNRESET) && defined(WSAECONNRESET)
609 #define ECONNRESET WSAECONNRESET
611 #if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
612 #define EAFNOSUPPORT WSAEAFNOSUPPORT
614 /* Why not needed for ECONNREFUSED? --abe */
616 DllExport void *win32_signal_context(void);
617 #define PERL_GET_SIG_CONTEXT win32_signal_context()
620 #define Win_GetModuleHandle XCEGetModuleHandleA
621 #define Win_GetProcAddress XCEGetProcAddressA
622 #define Win_GetModuleFileName XCEGetModuleFileNameA
623 #define Win_CreateSemaphore CreateSemaphoreW
625 #define Win_GetModuleHandle GetModuleHandle
626 #define Win_GetProcAddress GetProcAddress
627 #define Win_GetModuleFileName GetModuleFileName
628 #define Win_CreateSemaphore CreateSemaphore
631 #endif /* _INC_WIN32_PERL5 */