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 /* Win32 only optimizations for faster building */
17 #ifdef PERL_IS_MINIPERL
18 /* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and
19 * makedef.pl create dependencies that will keep Winsock linked in even with
20 * this macro defined, even though sockets will be umimplemented from a script
23 # define WIN32_NO_SOCKETS
24 /* less I/O calls during each require */
25 # define PERL_DISABLE_PMC
28 #ifdef WIN32_NO_SOCKETS
30 # undef HAS_GETPROTOBYNAME
31 # undef HAS_GETPROTOBYNUMBER
32 # undef HAS_GETPROTOENT
33 # undef HAS_GETNETBYNAME
34 # undef HAS_GETNETBYADDR
36 # undef HAS_GETSERVBYNAME
37 # undef HAS_GETSERVBYPORT
38 # undef HAS_GETSERVENT
39 # undef HAS_GETHOSTBYNAME
40 # undef HAS_GETHOSTBYADDR
41 # undef HAS_GETHOSTENT
48 # define WIN32SCK_IS_STDSCK
51 #if defined(PERL_IMPLICIT_SYS)
52 # define DYNAMIC_ENV_FETCH
53 # define HAS_GETENV_LEN
54 # define prime_env_iter()
55 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
56 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
57 # ifdef PERL_GLOBAL_STRUCT
58 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
60 # define win32_get_privlib PerlEnv_lib_path
61 # define win32_get_sitelib PerlEnv_sitelib_path
62 # define win32_get_vendorlib PerlEnv_vendorlib_path
66 # ifndef __int64 /* some versions seem to #define it already */
67 # define __int64 long long
69 # define Win32_Winsock
71 /* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
72 #undef PERL_UNUSED_DECL
73 #define PERL_UNUSED_DECL
78 /* Define DllExport akin to perl's EXT,
79 * If we are in the DLL then Export the symbol,
80 * otherwise import it.
83 /* now even GCC supports __declspec() */
84 /* miniperl has no reason to export anything */
85 #if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
89 # define DllExport __declspec(dllexport)
91 # define DllExport __declspec(dllimport)
95 /* The Perl APIs can only be called directly inside the perl5xx.dll.
96 * All other code has to import them. By declaring them as "dllimport"
97 * we tell the compiler to generate an indirect call instruction and
98 * avoid redirection through a call thunk.
100 * The XS code in the re extension is special, in that it redefines
101 * core APIs locally, so don't mark them as "dllimport" because GCC
102 * cannot handle this situation.
104 #if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
106 # define PERL_CALLCONV extern "C" __declspec(dllimport)
108 # define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
111 # define PERL_CALLCONV __declspec(dllimport)
113 # define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
116 #else /* MSVC noreturn support inside the interp */
118 # define PERL_CALLCONV_NO_RET __declspec(noreturn)
123 # define PERL_STATIC_NO_RET __declspec(noreturn) static
124 # define PERL_STATIC_INLINE_NO_RET __declspec(noreturn) PERL_STATIC_INLINE
127 #define WIN32_LEAN_AND_MEAN
131 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
132 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
133 * to declare GetEnvironmentStringsA.
135 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
139 #undef GetEnvironmentStringsA
140 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
141 #define GetEnvironmentStrings GetEnvironmentStringsA
147 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
148 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
149 #endif /*WIN32_LEAN_AND_MEAN */
151 #ifndef TLS_OUT_OF_INDEXES
152 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
179 char sysname[SYS_NMLN];
180 char nodename[SYS_NMLN];
181 char release[SYS_NMLN];
182 char version[SYS_NMLN];
183 char machine[SYS_NMLN];
186 #ifndef START_EXTERN_C
189 # define START_EXTERN_C extern "C" {
190 # define END_EXTERN_C }
191 # define EXTERN_C extern "C"
193 # define START_EXTERN_C
194 # define END_EXTERN_C
200 #define DOSISH 1 /* no escaping our roots */
201 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
203 /* read() and write() aren't transparent for socket handles */
204 #ifndef WIN32_NO_SOCKETS
205 # define PERL_SOCK_SYSREAD_IS_RECV
206 # define PERL_SOCK_SYSWRITE_IS_SEND
209 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
211 #define ENV_IS_CASELESS
213 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
215 /* access() mode bits */
228 #define PERL_GET_CONTEXT_DEFINED
230 /* Compiler-specific stuff. */
232 /* VC uses non-standard way to determine the size and alignment if bit-fields */
233 /* MinGW will compile with -mms-bitfields, so should use the same types */
234 #define PERL_BITFIELD8 unsigned char
235 #define PERL_BITFIELD16 unsigned short
236 #define PERL_BITFIELD32 unsigned int
238 #ifdef _MSC_VER /* Microsoft Visual C++ */
243 typedef unsigned short mode_t;
246 #pragma warning(disable: 4102) /* "unreferenced label" */
249 #define isnan _isnan /* Defined already in VC++ 12.0 */
251 #ifdef UNDER_CE /* revisit what function this becomes celib vs corelibc, prv warning here*/
254 #define snprintf _snprintf
255 #define vsnprintf _vsnprintf
257 /* on VC2003, msvcrt.lib is missing these symbols */
258 #if _MSC_VER >= 1300 && _MSC_VER < 1400
259 # pragma intrinsic(_rotl64,_rotr64)
262 #endif /* _MSC_VER */
264 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
269 #define _environ environ
271 #define flushall _flushall
272 #define fcloseall _fcloseall
274 #define isnan _isnan /* ...same libraries as MSVC */
278 # define _O_NOINHERIT 0x0080
279 # ifndef _NO_OLDNAMES
280 # define O_NOINHERIT _O_NOINHERIT
284 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
285 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
287 # ifndef _INTPTR_T_DEFINED
288 # define _INTPTR_T_DEFINED
290 # ifndef _UINTPTR_T_DEFINED
291 # define _UINTPTR_T_DEFINED
296 # define CP_UTF8 65001
299 #endif /* __MINGW32__ */
301 #ifndef _INTPTR_T_DEFINED
302 typedef int intptr_t;
303 # define _INTPTR_T_DEFINED
306 #ifndef _UINTPTR_T_DEFINED
307 typedef unsigned int uintptr_t;
308 # define _UINTPTR_T_DEFINED
313 /* For UNIX compatibility. */
316 extern uid_t getuid(void);
317 extern gid_t getgid(void);
318 extern uid_t geteuid(void);
319 extern gid_t getegid(void);
320 extern int setuid(uid_t uid);
321 extern int setgid(gid_t gid);
322 extern int kill(int pid, int sig);
323 #ifndef USE_PERL_SBRK
324 extern void *sbrk(ptrdiff_t need);
325 # define HAS_SBRK_PROTO
327 extern char * getlogin(void);
328 extern int chown(const char *p, uid_t o, gid_t g);
329 extern int mkstemp(const char *path);
333 #define Stat win32_stat
335 #undef init_os_extras
336 #define init_os_extras Perl_init_os_extras
338 DllExport void Perl_win32_init(int *argcp, char ***argvp);
339 DllExport void Perl_win32_term(void);
340 DllExport void Perl_init_os_extras(void);
341 DllExport void win32_str_os_error(void *sv, DWORD err);
342 DllExport int RunPerl(int argc, char **argv, char **env);
349 * the following correspond to the fields of the same name
350 * in the STARTUPINFO structure. Embedders can use these to
351 * control the spawning process' look.
352 * Example - to hide the window of the spawned process:
353 * dwFlags = STARTF_USESHOWWINDOW;
354 * wShowWindow = SW_HIDE;
363 DWORD dwFillAttribute;
367 DllExport void win32_get_child_IO(child_IO_table* ptr);
368 DllExport HWND win32_create_message_window(void);
370 extern int my_fclose(FILE *);
371 extern char * win32_get_privlib(const char *pl, STRLEN *const len);
372 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
373 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
375 #ifdef PERL_IMPLICIT_SYS
376 extern void win32_delete_internal_host(void *h);
379 extern int win32_get_errno(int err);
381 extern const char * const staticlinkmodules[];
385 typedef char * caddr_t; /* In malloc.c (core address). */
388 * handle socket stuff, assuming socket is always available
390 #include <sys/socket.h>
394 #define EMBEDMYMALLOC /**/
395 /* #define USE_PERL_SBRK / **/
396 /* #define PERL_SBRK_VIA_MALLOC / **/
399 #ifdef PERL_TEXTMODE_SCRIPTS
400 # define PERL_SCRIPT_MODE "r"
402 # define PERL_SCRIPT_MODE "rb"
406 * Now Win32 specific per-thread data stuff
409 /* Leave the first couple ids after WM_USER unused because they
410 * might be used by an embedding application, and on Windows
411 * version before 2000 we might end up eating those messages
412 * if they were not meant for us.
414 #define WM_USER_MIN (WM_USER+30)
415 #define WM_USER_MESSAGE (WM_USER_MIN)
416 #define WM_USER_KILL (WM_USER_MIN+1)
417 #define WM_USER_MAX (WM_USER_MIN+1)
419 struct thread_intern {
420 /* XXX can probably use one buffer instead of several */
421 char Wstrerror_buffer[512];
422 struct servent Wservent;
423 char Wgetlogin_buffer[128];
425 char Wcrypt_buffer[30];
426 # ifdef USE_RTL_THREAD_API
427 void * retv; /* slot for thread return value */
429 BOOL Wuse_showwindow;
433 #define HAVE_INTERP_INTERN
436 DWORD pids[MAXIMUM_WAIT_OBJECTS];
437 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
443 DWORD pids[MAXIMUM_WAIT_OBJECTS];
444 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
445 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
446 char sigterm[MAXIMUM_WAIT_OBJECTS];
451 typedef Signal_t (*Sighandler_t) (int);
452 #define Sighandler_t Sighandler_t
455 struct interp_intern {
456 char * perlshell_tokens;
457 char ** perlshell_vec;
458 long perlshell_items;
460 child_tab * children;
463 pseudo_child_tab * pseudo_children;
465 void * internal_host;
466 struct thread_intern thr_intern;
470 Sighandler_t sigtable[SIG_SIZE];
473 DllExport int win32_async_check(pTHX);
475 #define WIN32_POLL_INTERVAL 32768
476 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
478 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
479 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
480 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
481 #define w32_fdpid (PL_sys_intern.fdpid)
482 #define w32_children (PL_sys_intern.children)
483 #define w32_num_children (w32_children->num)
484 #define w32_child_pids (w32_children->pids)
485 #define w32_child_handles (w32_children->handles)
486 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
487 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
488 #define w32_num_pseudo_children (w32_pseudo_children->num)
489 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
490 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
491 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
492 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
493 #define w32_internal_host (PL_sys_intern.internal_host)
494 #define w32_timerid (PL_sys_intern.timerid)
495 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
496 #define w32_sighandler (PL_sys_intern.sigtable)
497 #define w32_poll_count (PL_sys_intern.poll_count)
498 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
499 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
500 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
501 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
502 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
503 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
504 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
505 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
508 void win32_wait_for_children(pTHX);
509 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
513 /* C doesn't like repeat struct definitions */
514 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
518 #define _CRTIMP __declspec(dllimport)
522 /* VV 2005 has multiple ioinfo struct definitions through VC 2005's release life
523 * VC 2008-2012 have been stable but do not assume future VCs will have the
524 * same ioinfo struct, just because past struct stability. If research is done
525 * on the CRTs of future VS, the version check can be bumped up so the newer
526 * VC uses a fixed ioinfo size.
528 #if ! (_MSC_VER < 1400 || (_MSC_VER >= 1500 && _MSC_VER <= 1700) \
529 || defined(__MINGW32__))
530 /* size of ioinfo struct is determined at runtime */
531 # define WIN32_DYN_IOINFO_SIZE
534 #ifndef WIN32_DYN_IOINFO_SIZE
536 * Control structure for lowio file handles
539 intptr_t osfhnd;/* underlying OS file HANDLE */
540 char osfile; /* attributes of file (e.g., open in text mode?) */
541 char pipech; /* one char buffer for handles opened on pipes */
543 CRITICAL_SECTION lock;
544 /* this struct defintion breaks ABI compatibility with
545 * not using, cl.exe's native VS version specitfic CRT. */
546 # if _MSC_VER >= 1400 && _MSC_VER < 1500
547 # error "This ioinfo struct is incomplete for Visual C 2005"
549 /* VC 2005 CRT has atleast 3 different definitions of this struct based on the
550 * CRT DLL's build number. */
551 # if _MSC_VER >= 1500
552 # ifndef _SAFECRT_IMPL
553 /* Not used in the safecrt downlevel. We do not define them, so we cannot
554 * use them accidentally */
555 char textmode : 7;/* __IOINFO_TM_ANSI or __IOINFO_TM_UTF8 or __IOINFO_TM_UTF16LE */
556 char unicode : 1; /* Was the file opened as unicode? */
557 char pipech2[2]; /* 2 more peak ahead chars for UNICODE mode */
558 __int64 startpos; /* File position that matches buffer start */
559 BOOL utf8translations; /* Buffer contains translations other than CRLF*/
560 char dbcsBuffer; /* Buffer for the lead byte of dbcs when converting from dbcs to unicode */
561 BOOL dbcsBufferUsed; /* Bool for the lead byte buffer is used or not */
566 typedef intptr_t ioinfo;
570 * Array of arrays of control structures for lowio files.
572 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
575 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
576 * array of ioinfo structs.
581 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
583 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
586 * Access macros for getting at an ioinfo struct and its fields from a
589 #ifdef WIN32_DYN_IOINFO_SIZE
590 # define _pioinfo(i) ((intptr_t *) \
591 (((Size_t)__pioinfo[(i) >> IOINFO_L2E])/* * to head of array ioinfo [] */\
592 /* offset to the head of a particular ioinfo struct */ \
593 + (((i) & (IOINFO_ARRAY_ELTS - 1)) * w32_ioinfo_size)) \
595 /* first slice of ioinfo is always the OS handle */
596 # define _osfhnd(i) (*(_pioinfo(i)))
598 # define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
599 # define _osfhnd(i) (_pioinfo(i)->osfhnd)
602 /* since we are not doing a dup2(), this works fine */
603 # define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
604 #endif /* PERL_CORE */
606 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
607 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
608 #undef PERLIO_NOT_STDIO
610 #define PERLIO_NOT_STDIO 0
615 * This provides a layer of functions and macros to ensure extensions will
616 * get to use the same RTL functions as the core.
618 #include "win32iop.h"
620 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
622 DllExport void *win32_signal_context(void);
623 #define PERL_GET_SIG_CONTEXT win32_signal_context()
626 #define Win_GetModuleHandle XCEGetModuleHandleA
627 #define Win_GetProcAddress XCEGetProcAddressA
628 #define Win_GetModuleFileName XCEGetModuleFileNameA
629 #define Win_CreateSemaphore CreateSemaphoreW
631 #define Win_GetModuleHandle GetModuleHandle
632 #define Win_GetProcAddress GetProcAddress
633 #define Win_GetModuleFileName GetModuleFileName
634 #define Win_CreateSemaphore CreateSemaphore
637 #endif /* _INC_WIN32_PERL5 */