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 #define WIN32_LEAN_AND_MEAN
62 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
63 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
64 * to declare GetEnvironmentStringsA.
66 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
70 #undef GetEnvironmentStringsA
71 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
72 #define GetEnvironmentStrings GetEnvironmentStringsA
78 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
79 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
80 #endif /*WIN32_LEAN_AND_MEAN */
82 #ifndef TLS_OUT_OF_INDEXES
83 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
110 char sysname[SYS_NMLN];
111 char nodename[SYS_NMLN];
112 char release[SYS_NMLN];
113 char version[SYS_NMLN];
114 char machine[SYS_NMLN];
117 #ifndef START_EXTERN_C
120 # define START_EXTERN_C extern "C" {
121 # define END_EXTERN_C }
122 # define EXTERN_C extern "C"
124 # define START_EXTERN_C
125 # define END_EXTERN_C
131 #define DOSISH 1 /* no escaping our roots */
132 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
134 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
135 * real filehandles. XXX Should always be defined (the other version is untested) */
136 #define USE_SOCKETS_AS_HANDLES
138 /* read() and write() aren't transparent for socket handles */
139 #define PERL_SOCK_SYSREAD_IS_RECV
140 #define PERL_SOCK_SYSWRITE_IS_SEND
142 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
144 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
145 It now uses some black magic to work seamlessly with the DLL CRT and
146 works with MSVC++ 4.0+ or GCC/Mingw32
148 Only use this fix for VC++ 6.x or earlier (and for GCC, which we assume
149 uses MSVCRT.DLL). Later versions use MSVCR70.dll, MSVCR71.dll, etc, which
150 do not require the fix. */
151 #if (defined(_M_IX86) && _MSC_VER >= 1000 && _MSC_VER <= 1200) || defined(__MINGW32__)
152 #define USE_FIXED_OSFHANDLE
155 /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
156 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
158 #if !(defined(_M_IX86) && _MSC_VER >= 1200)
159 #define PERL_WIN32_SOCK_DLOAD
161 #define ENV_IS_CASELESS
163 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
165 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
166 #define VER_PLATFORM_WIN32_WINDOWS 1
169 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
170 #define FILE_SHARE_DELETE 0x00000004
173 /* access() mode bits */
186 #define PERL_GET_CONTEXT_DEFINED
188 /* Compiler-specific stuff. */
190 #if defined(_MSC_VER) || defined(__MINGW32__)
191 /* VC uses non-standard way to determine the size and alignment if bit-fields */
192 /* MinGW will compiler with -mms-bitfields, so should use the same types */
193 # define PERL_BITFIELD8 unsigned char
194 # define PERL_BITFIELD16 unsigned short
195 # define PERL_BITFIELD32 unsigned int
198 #ifdef __BORLANDC__ /* Borland C++ */
200 #if (__BORLANDC__ <= 0x520)
201 #define _access access
205 #define _getpid getpid
206 #define wcsicmp _wcsicmp
207 #include <sys/types.h>
210 #define DllMain DllEntryPoint
213 #pragma warn -8004 /* "'foo' is assigned a value that is never used" */
214 #pragma warn -8008 /* "condition is always true/false" */
215 #pragma warn -8012 /* "comparing signed and unsigned values" */
216 #pragma warn -8027 /* "functions containing %s are not expanded inline" */
217 #pragma warn -8057 /* "parameter 'foo' is never used" */
218 #pragma warn -8060 /* "possibly incorrect assignment" */
219 #pragma warn -8066 /* "unreachable code" */
220 #pragma warn -8071 /* "conversion may lose significant digits" */
221 #pragma warn -8080 /* "'foo' is declared but never used" */
223 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
224 #define PERL_MEMBER_PTR_SIZE 12
230 #ifdef _MSC_VER /* Microsoft Visual C++ */
235 typedef unsigned short mode_t;
238 #pragma warning(disable: 4102) /* "unreferenced label" */
240 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
241 #define PERL_MEMBER_PTR_SIZE 16
244 #define snprintf _snprintf
245 #define vsnprintf _vsnprintf
248 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
249 #define NAN_COMPARE_BROKEN 1
252 #endif /* _MSC_VER */
254 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
259 #define _environ environ
261 #define flushall _flushall
262 #define fcloseall _fcloseall
263 #define isnan _isnan /* ...same libraries as MSVC */
266 # define _O_NOINHERIT 0x0080
267 # ifndef _NO_OLDNAMES
268 # define O_NOINHERIT _O_NOINHERIT
272 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
273 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
275 # ifndef _INTPTR_T_DEFINED
276 # define _INTPTR_T_DEFINED
278 # ifndef _UINTPTR_T_DEFINED
279 # define _UINTPTR_T_DEFINED
283 #endif /* __MINGW32__ */
285 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
287 # define CP_UTF8 65001
290 /* compatibility stuff for other compilers goes here */
292 #ifndef _INTPTR_T_DEFINED
293 typedef int intptr_t;
294 # define _INTPTR_T_DEFINED
297 #ifndef _UINTPTR_T_DEFINED
298 typedef unsigned int uintptr_t;
299 # define _UINTPTR_T_DEFINED
304 /* For UNIX compatibility. */
306 extern uid_t getuid(void);
307 extern gid_t getgid(void);
308 extern uid_t geteuid(void);
309 extern gid_t getegid(void);
310 extern int setuid(uid_t uid);
311 extern int setgid(gid_t gid);
312 extern int kill(int pid, int sig);
313 extern int killpg(int pid, int sig);
314 #ifndef USE_PERL_SBRK
315 extern void *sbrk(ptrdiff_t need);
316 # define HAS_SBRK_PROTO
318 extern char * getlogin(void);
319 extern int chown(const char *p, uid_t o, gid_t g);
320 extern int mkstemp(const char *path);
323 #define Stat win32_stat
325 #undef init_os_extras
326 #define init_os_extras Perl_init_os_extras
328 DllExport void Perl_win32_init(int *argcp, char ***argvp);
329 DllExport void Perl_win32_term(void);
330 DllExport void Perl_init_os_extras(void);
331 DllExport void win32_str_os_error(void *sv, DWORD err);
332 DllExport int RunPerl(int argc, char **argv, char **env);
339 * the following correspond to the fields of the same name
340 * in the STARTUPINFO structure. Embedders can use these to
341 * control the spawning process' look.
342 * Example - to hide the window of the spawned process:
343 * dwFlags = STARTF_USESHOWWINDOW;
344 * wShowWindow = SW_HIDE;
353 DWORD dwFillAttribute;
357 DllExport void win32_get_child_IO(child_IO_table* ptr);
358 DllExport HWND win32_create_message_window(void);
360 #ifndef USE_SOCKETS_AS_HANDLES
361 extern FILE * my_fdopen(int, char *);
363 extern int my_fclose(FILE *);
364 extern int my_fstat(int fd, Stat_t *sbufptr);
365 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
366 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
367 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
368 extern int IsWin95(void);
369 extern int IsWinNT(void);
371 #ifdef PERL_IMPLICIT_SYS
372 extern void win32_delete_internal_host(void *h);
375 extern char * staticlinkmodules[];
379 typedef char * caddr_t; /* In malloc.c (core address). */
382 * handle socket stuff, assuming socket is always available
384 #include <sys/socket.h>
388 #define EMBEDMYMALLOC /**/
389 /* #define USE_PERL_SBRK /**/
390 /* #define PERL_SBRK_VIA_MALLOC /**/
393 #ifdef PERL_TEXTMODE_SCRIPTS
394 # define PERL_SCRIPT_MODE "r"
396 # define PERL_SCRIPT_MODE "rb"
400 * Now Win32 specific per-thread data stuff
403 /* Leave the first couple ids after WM_USER unused because they
404 * might be used by an embedding application, and on Windows
405 * version before 2000 we might end up eating those messages
406 * if they were not meant for us.
408 #define WM_USER_MIN (WM_USER+30)
409 #define WM_USER_MESSAGE (WM_USER_MIN)
410 #define WM_USER_KILL (WM_USER_MIN+1)
411 #define WM_USER_MAX (WM_USER_MIN+1)
413 struct thread_intern {
414 /* XXX can probably use one buffer instead of several */
415 char Wstrerror_buffer[512];
416 struct servent Wservent;
417 char Wgetlogin_buffer[128];
418 # ifdef USE_SOCKETS_AS_HANDLES
421 # ifdef HAVE_DES_FCRYPT
422 char Wcrypt_buffer[30];
424 # ifdef USE_RTL_THREAD_API
425 void * retv; /* slot for thread return value */
427 BOOL Wuse_showwindow;
431 #define HAVE_INTERP_INTERN
434 DWORD pids[MAXIMUM_WAIT_OBJECTS];
435 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
441 DWORD pids[MAXIMUM_WAIT_OBJECTS];
442 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
443 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
448 typedef Signal_t (*Sighandler_t) (int);
449 #define Sighandler_t Sighandler_t
452 struct interp_intern {
453 char * perlshell_tokens;
454 char ** perlshell_vec;
455 long perlshell_items;
457 child_tab * children;
460 pseudo_child_tab * pseudo_children;
462 void * internal_host;
463 struct thread_intern thr_intern;
467 Sighandler_t sigtable[SIG_SIZE];
470 DllExport int win32_async_check(pTHX);
472 #define WIN32_POLL_INTERVAL 32768
473 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
475 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
476 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
477 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
478 #define w32_fdpid (PL_sys_intern.fdpid)
479 #define w32_children (PL_sys_intern.children)
480 #define w32_num_children (w32_children->num)
481 #define w32_child_pids (w32_children->pids)
482 #define w32_child_handles (w32_children->handles)
483 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
484 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
485 #define w32_num_pseudo_children (w32_pseudo_children->num)
486 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
487 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
488 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
489 #define w32_internal_host (PL_sys_intern.internal_host)
490 #define w32_timerid (PL_sys_intern.timerid)
491 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
492 #define w32_sighandler (PL_sys_intern.sigtable)
493 #define w32_poll_count (PL_sys_intern.poll_count)
494 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
495 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
496 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
497 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
498 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
499 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
500 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
501 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
504 # define PERL_WAIT_FOR_CHILDREN \
506 if (w32_pseudo_children && w32_num_pseudo_children) { \
507 long children = w32_num_pseudo_children; \
508 WaitForMultipleObjects(children, \
509 w32_pseudo_child_handles, \
512 CloseHandle(w32_pseudo_child_handles[--children]); \
517 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
520 /* C doesn't like repeat struct definitions */
521 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
525 #define _CRTIMP __declspec(dllimport)
529 * Control structure for lowio file handles
532 intptr_t osfhnd;/* underlying OS file HANDLE */
533 char osfile; /* attributes of file (e.g., open in text mode?) */
534 char pipech; /* one char buffer for handles opened on pipes */
536 CRITICAL_SECTION lock;
541 * Array of arrays of control structures for lowio files.
543 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
546 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
547 * array of ioinfo structs.
552 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
554 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
557 * Access macros for getting at an ioinfo struct and its fields from a
560 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
561 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
562 #define _osfile(i) (_pioinfo(i)->osfile)
563 #define _pipech(i) (_pioinfo(i)->pipech)
565 /* since we are not doing a dup2(), this works fine */
566 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
570 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
571 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
572 #undef PERLIO_NOT_STDIO
574 #define PERLIO_NOT_STDIO 0
579 * This provides a layer of functions and macros to ensure extensions will
580 * get to use the same RTL functions as the core.
582 #include "win32iop.h"
584 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
586 #if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
587 #define ECONNABORTED WSAECONNABORTED
589 #if !defined(ECONNRESET) && defined(WSAECONNRESET)
590 #define ECONNRESET WSAECONNRESET
592 #if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
593 #define EAFNOSUPPORT WSAEAFNOSUPPORT
595 /* Why not needed for ECONNREFUSED? --abe */
597 DllExport void *win32_signal_context(void);
598 #define PERL_GET_SIG_CONTEXT win32_signal_context()
601 #define Win_GetModuleHandle XCEGetModuleHandleA
602 #define Win_GetProcAddress XCEGetProcAddressA
603 #define Win_GetModuleFileName XCEGetModuleFileNameA
604 #define Win_CreateSemaphore CreateSemaphoreW
606 #define Win_GetModuleHandle GetModuleHandle
607 #define Win_GetProcAddress GetProcAddress
608 #define Win_GetModuleFileName GetModuleFileName
609 #define Win_CreateSemaphore CreateSemaphore
612 #endif /* _INC_WIN32_PERL5 */