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
27 /* unnecessery for miniperl to lookup anything from an "installed" perl */
28 # define WIN32_NO_REGISTRY
30 /* allow minitest to work */
31 # define PERL_TEXTMODE_SCRIPTS
34 #ifdef WIN32_NO_SOCKETS
36 # undef HAS_GETPROTOBYNAME
37 # undef HAS_GETPROTOBYNUMBER
38 # undef HAS_GETPROTOENT
39 # undef HAS_GETNETBYNAME
40 # undef HAS_GETNETBYADDR
42 # undef HAS_GETSERVBYNAME
43 # undef HAS_GETSERVBYPORT
44 # undef HAS_GETSERVENT
45 # undef HAS_GETHOSTBYNAME
46 # undef HAS_GETHOSTBYADDR
47 # undef HAS_GETHOSTENT
54 # define WIN32SCK_IS_STDSCK
57 #if defined(PERL_IMPLICIT_SYS)
58 # define DYNAMIC_ENV_FETCH
59 # define HAS_GETENV_LEN
60 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
61 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
65 # ifndef __int64 /* some versions seem to #define it already */
66 # define __int64 long long
68 # define Win32_Winsock
72 /* Define DllExport akin to perl's EXT,
73 * If we are in the DLL then Export the symbol,
74 * otherwise import it.
77 /* now even GCC supports __declspec() */
78 /* miniperl has no reason to export anything */
79 #if defined(PERL_IS_MINIPERL)
83 # define DllExport __declspec(dllexport)
85 # define DllExport __declspec(dllimport)
89 /* The Perl APIs can only be called directly inside the perl5xx.dll.
90 * All other code has to import them. By declaring them as "dllimport"
91 * we tell the compiler to generate an indirect call instruction and
92 * avoid redirection through a call thunk.
94 * The XS code in the re extension is special, in that it redefines
95 * core APIs locally, so don't mark them as "dllimport" because GCC
96 * cannot handle this situation.
98 * Certain old GCCs will not allow the function pointer of dllimport marked
99 * function to be "const". This was fixed later on. Since this is a
100 * deoptimization, target "gcc version 3.4.5 (mingw-vista special r3)" only,
101 * The GCC bug was fixed in GCC patch "varasm.c (initializer_constant_valid_p):
102 * Don't deny DECL_DLLIMPORT_P on functions", which probably was first released
103 * in GCC 4.3.0, this #if can be expanded upto but not including 4.3.0 if more
104 * deployed GCC are found that wont build with the follow error, initializer
105 * element is a PerlIO func exported from perl5xx.dll.
107 * encoding.xs:610: error: initializer element is not constant
108 * encoding.xs:610: error: (near initialization for `PerlIO_encode.Open')
111 #if (defined(__GNUC__) && defined(__MINGW32__) && \
112 !defined(__MINGW64_VERSION_MAJOR) && !defined(__clang__) && \
113 ((__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ <= 5))))
114 /* use default fallbacks from perl.h for this particular GCC */
116 # if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
118 # define PERL_CALLCONV extern "C" __declspec(dllimport)
120 # define PERL_CALLCONV_NO_RET extern "C" __declspec(dllimport) __declspec(noreturn)
123 # define PERL_CALLCONV __declspec(dllimport)
125 # define PERL_CALLCONV_NO_RET __declspec(dllimport) __declspec(noreturn)
128 # else /* MSVC noreturn support inside the interp */
130 # define PERL_CALLCONV_NO_RET __declspec(noreturn)
136 # define PERL_STATIC_NO_RET __declspec(noreturn) static
137 # define PERL_STATIC_INLINE_NO_RET __declspec(noreturn) PERL_STATIC_INLINE
138 # define PERL_STATIC_FORCE_INLINE __forceinline static
139 # define PERL_STATIC_FORCE_INLINE_NO_RET __declspec(noreturn) __forceinline static
142 #define WIN32_LEAN_AND_MEAN
146 * Bug in winbase.h in mingw-w64 4.4.0-1 at least... they
147 * do #define GetEnvironmentStringsA GetEnvironmentStrings and fail
148 * to declare GetEnvironmentStringsA.
150 #if defined(__MINGW64__) && defined(GetEnvironmentStringsA) && !defined(UNICODE)
154 #undef GetEnvironmentStringsA
155 WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
156 #define GetEnvironmentStrings GetEnvironmentStringsA
162 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
163 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
164 #endif /*WIN32_LEAN_AND_MEAN */
166 #ifndef TLS_OUT_OF_INDEXES
167 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
194 char sysname[SYS_NMLN];
195 char nodename[SYS_NMLN];
196 char release[SYS_NMLN];
197 char version[SYS_NMLN];
198 char machine[SYS_NMLN];
201 #ifndef START_EXTERN_C
204 # define START_EXTERN_C extern "C" {
205 # define END_EXTERN_C }
206 # define EXTERN_C extern "C"
208 # define START_EXTERN_C
209 # define END_EXTERN_C
214 #define DOSISH 1 /* no escaping our roots */
215 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
217 /* read() and write() aren't transparent for socket handles */
218 #ifndef WIN32_NO_SOCKETS
219 # define PERL_SOCK_SYSREAD_IS_RECV
220 # define PERL_SOCK_SYSWRITE_IS_SEND
223 #ifdef WIN32_NO_REGISTRY
224 /* the last _ in WIN32_NO_REGISTRY_M_ is like the _ in aTHX_ */
225 # define WIN32_NO_REGISTRY_M_(x)
227 # define WIN32_NO_REGISTRY_M_(x) x,
230 #define ENV_IS_CASELESS
232 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
234 /* access() mode bits */
247 #define PERL_GET_CONTEXT_DEFINED
249 /* Compiler-specific stuff. */
251 /* VC uses non-standard way to determine the size and alignment if bit-fields */
252 /* MinGW will compile with -mms-bitfields, so should use the same types */
253 #define PERL_BITFIELD8 U8
254 #define PERL_BITFIELD16 U16
255 #define PERL_BITFIELD32 U32
257 #ifdef _MSC_VER /* Microsoft Visual C++ */
261 typedef unsigned short mode_t;
263 #define snprintf _snprintf
264 #define vsnprintf _vsnprintf
266 MSVC_DIAG_IGNORE(4756 4056)
268 double S_Infinity() {
269 /* this is a real C literal which can get further constant folded
270 unlike using HUGE_VAL/_HUGE which are data symbol imports from the CRT
271 and therefore can not by folded by VC, an example of constant
272 folding INF is creating -INF */
273 return (DBL_MAX+DBL_MAX);
277 #define NV_INF S_Infinity()
279 /* selectany allows duplicate and unused data symbols to be removed by
280 VC linker, if this were static, each translation unit will have its own,
281 usually unused __PL_nan_u, if this were plain extern it will cause link
282 to fail due to multiple definitions, since we dont know if we are being
283 compiled as static or DLL XS, selectany simply always works, the cost of
284 importing __PL_nan_u across DLL boundaries in size in the importing DLL
285 will be more than the 8 bytes it will take up being in each XS DLL if
286 that DLL actually uses __PL_nan_u */
287 extern const __declspec(selectany) union { unsigned __int64 __q; double __d; }
288 __PL_nan_u = { 0x7FF8000000000000UI64 };
289 #define NV_NAN ((NV)__PL_nan_u.__d)
291 /* The CRT was rewritten in VS2015. */
294 /* No longer declared in stdio.h */
295 EXTERN_C char *gets(char* buffer);
297 #define tzname _tzname
299 /* From corecrt_internal_stdio.h: */
315 CRITICAL_SECTION _lock;
316 } __crt_stdio_stream_data;
318 #define PERLIO_FILE_flag_RD 0x0001 /* _IOREAD */
319 #define PERLIO_FILE_flag_WR 0x0002 /* _IOWRITE */
320 #define PERLIO_FILE_flag_RW 0x0004 /* _IOUPDATE */
321 #define PERLIO_FILE_ptr(f) (((__crt_stdio_stream_data*)(f))->_ptr)
322 #define PERLIO_FILE_base(f) (((__crt_stdio_stream_data*)(f))->_base)
323 #define PERLIO_FILE_cnt(f) (((__crt_stdio_stream_data*)(f))->_cnt)
324 #define PERLIO_FILE_flag(f) ((int)(((__crt_stdio_stream_data*)(f))->_flags))
325 #define PERLIO_FILE_file(f) (*(int*)(&((__crt_stdio_stream_data*)(f))->_file))
329 #endif /* _MSC_VER */
331 #if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900)
333 /* Note: PERLIO_FILE_ptr/base/cnt are not actually used for GCC or <VS2015
334 * since FILE_ptr/base/cnt do the same thing anyway but it doesn't hurt to
335 * define them all here for completeness. */
336 #define PERLIO_FILE_flag_RD _IOREAD /* 0x001 */
337 #define PERLIO_FILE_flag_WR _IOWRT /* 0x002 */
338 #define PERLIO_FILE_flag_RW _IORW /* 0x080 */
339 #define PERLIO_FILE_ptr(f) ((f)->_ptr)
340 #define PERLIO_FILE_base(f) ((f)->_base)
341 #define PERLIO_FILE_cnt(f) ((f)->_cnt)
342 #define PERLIO_FILE_flag(f) ((f)->_flag)
343 #define PERLIO_FILE_file(f) ((f)->_file)
347 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
352 #define _environ environ
354 #define flushall _flushall
355 #define fcloseall _fcloseall
357 #define isnan _isnan /* ...same libraries as MSVC */
361 # define _O_NOINHERIT 0x0080
362 # ifndef _NO_OLDNAMES
363 # define O_NOINHERIT _O_NOINHERIT
367 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
368 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
370 # ifndef _INTPTR_T_DEFINED
371 # define _INTPTR_T_DEFINED
373 # ifndef _UINTPTR_T_DEFINED
374 # define _UINTPTR_T_DEFINED
379 # define CP_UTF8 65001
382 #endif /* __MINGW32__ */
384 #ifndef _INTPTR_T_DEFINED
385 typedef int intptr_t;
386 # define _INTPTR_T_DEFINED
389 #ifndef _UINTPTR_T_DEFINED
390 typedef unsigned int uintptr_t;
391 # define _UINTPTR_T_DEFINED
396 /* For UNIX compatibility. */
399 extern uid_t getuid(void);
400 extern gid_t getgid(void);
401 extern uid_t geteuid(void);
402 extern gid_t getegid(void);
403 extern int setuid(uid_t uid);
404 extern int setgid(gid_t gid);
405 extern int kill(int pid, int sig);
406 #ifndef USE_PERL_SBRK
407 extern void *sbrk(ptrdiff_t need);
408 # define HAS_SBRK_PROTO
410 extern char * getlogin(void);
411 extern int chown(const char *p, uid_t o, gid_t g);
412 #if((!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4) && \
413 (!defined(__MINGW32_MAJOR_VERSION) || __MINGW32_MAJOR_VERSION < 3 || \
414 (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION < 21)))
415 extern int mkstemp(const char *path);
420 #define Stat win32_stat
422 #undef init_os_extras
423 #define init_os_extras Perl_init_os_extras
425 DllExport void Perl_win32_init(int *argcp, char ***argvp);
426 DllExport void Perl_win32_term(void);
427 DllExport void Perl_init_os_extras(void);
428 DllExport void win32_str_os_error(void *sv, DWORD err);
429 DllExport int RunPerl(int argc, char **argv, char **env);
436 * the following correspond to the fields of the same name
437 * in the STARTUPINFO structure. Embedders can use these to
438 * control the spawning process' look.
439 * Example - to hide the window of the spawned process:
440 * dwFlags = STARTF_USESHOWWINDOW;
441 * wShowWindow = SW_HIDE;
450 DWORD dwFillAttribute;
454 DllExport void win32_get_child_IO(child_IO_table* ptr);
455 DllExport HWND win32_create_message_window(void);
456 DllExport int win32_async_check(pTHX);
458 extern int my_fclose(FILE *);
459 extern char * win32_get_privlib(WIN32_NO_REGISTRY_M_(const char *pl) STRLEN *const len);
460 extern char * win32_get_sitelib(const char *pl, STRLEN *const len);
461 extern char * win32_get_vendorlib(const char *pl, STRLEN *const len);
463 #ifdef PERL_IMPLICIT_SYS
464 extern void win32_delete_internal_host(void *h);
467 extern int win32_get_errno(int err);
469 extern const char * const staticlinkmodules[];
473 typedef char * caddr_t; /* In malloc.c (core address). */
476 * handle socket stuff, assuming socket is always available
478 #include <sys/socket.h>
482 #define EMBEDMYMALLOC /**/
483 /* #define USE_PERL_SBRK / **/
484 /* #define PERL_SBRK_VIA_MALLOC / **/
487 #ifdef PERL_TEXTMODE_SCRIPTS
488 # define PERL_SCRIPT_MODE "r"
490 # define PERL_SCRIPT_MODE "rb"
494 * Now Win32 specific per-thread data stuff
497 /* Leave the first couple ids after WM_USER unused because they
498 * might be used by an embedding application, and on Windows
499 * version before 2000 we might end up eating those messages
500 * if they were not meant for us.
502 #define WM_USER_MIN (WM_USER+30)
503 #define WM_USER_MESSAGE (WM_USER_MIN)
504 #define WM_USER_KILL (WM_USER_MIN+1)
505 #define WM_USER_MAX (WM_USER_MIN+1)
507 struct thread_intern {
508 /* XXX can probably use one buffer instead of several */
509 char Wstrerror_buffer[512];
510 struct servent Wservent;
511 char Wgetlogin_buffer[128];
513 char Wcrypt_buffer[30];
514 # ifdef USE_RTL_THREAD_API
515 void * retv; /* slot for thread return value */
517 BOOL Wuse_showwindow;
521 #define HAVE_INTERP_INTERN
524 DWORD pids[MAXIMUM_WAIT_OBJECTS];
525 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
531 DWORD pids[MAXIMUM_WAIT_OBJECTS];
532 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
533 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
534 char sigterm[MAXIMUM_WAIT_OBJECTS];
539 typedef Signal_t (*Sighandler_t) (int);
540 #define Sighandler_t Sighandler_t
543 struct interp_intern {
544 char * perlshell_tokens;
545 char ** perlshell_vec;
546 long perlshell_items;
548 child_tab * children;
551 pseudo_child_tab * pseudo_children;
553 void * internal_host;
554 struct thread_intern thr_intern;
558 Sighandler_t sigtable[SIG_SIZE];
561 #define WIN32_POLL_INTERVAL 32768
562 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
564 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
565 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
566 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
567 #define w32_fdpid (PL_sys_intern.fdpid)
568 #define w32_children (PL_sys_intern.children)
569 #define w32_num_children (w32_children->num)
570 #define w32_child_pids (w32_children->pids)
571 #define w32_child_handles (w32_children->handles)
572 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
573 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
574 #define w32_num_pseudo_children (w32_pseudo_children->num)
575 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
576 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
577 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
578 #define w32_pseudo_child_sigterm (w32_pseudo_children->sigterm)
579 #define w32_internal_host (PL_sys_intern.internal_host)
580 #define w32_timerid (PL_sys_intern.timerid)
581 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
582 #define w32_sighandler (PL_sys_intern.sigtable)
583 #define w32_poll_count (PL_sys_intern.poll_count)
584 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
585 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
586 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
587 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
588 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
589 #define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
590 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
591 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
594 void win32_wait_for_children(pTHX);
595 # define PERL_WAIT_FOR_CHILDREN win32_wait_for_children(aTHX)
598 /* The following ioinfo struct manipulations had been removed but were
599 * reinstated to fix RT#120091/118059. However, they do not work with
600 * the rewritten CRT in VS2015 so they are removed once again for VS2015
601 * onwards, which will therefore suffer from the reintroduction of the
602 * close socket bug. */
603 #if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900)
607 /* C doesn't like repeat struct definitions */
608 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
612 # define _CRTIMP __declspec(dllimport)
616 /* size of ioinfo struct is determined at runtime */
617 # define WIN32_DYN_IOINFO_SIZE
620 #ifndef WIN32_DYN_IOINFO_SIZE
622 * Control structure for lowio file handles
625 intptr_t osfhnd;/* underlying OS file HANDLE */
626 char osfile; /* attributes of file (e.g., open in text mode?) */
627 char pipech; /* one char buffer for handles opened on pipes */
629 CRITICAL_SECTION lock;
632 typedef intptr_t ioinfo;
636 * Array of arrays of control structures for lowio files.
638 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
641 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
642 * array of ioinfo structs.
647 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
649 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
652 * Access macros for getting at an ioinfo struct and its fields from a
655 #ifdef WIN32_DYN_IOINFO_SIZE
656 # define _pioinfo(i) ((intptr_t *) \
657 (((Size_t)__pioinfo[(i) >> IOINFO_L2E])/* * to head of array ioinfo [] */\
658 /* offset to the head of a particular ioinfo struct */ \
659 + (((i) & (IOINFO_ARRAY_ELTS - 1)) * w32_ioinfo_size)) \
661 /* first slice of ioinfo is always the OS handle */
662 # define _osfhnd(i) (*(_pioinfo(i)))
664 # define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
665 # define _osfhnd(i) (_pioinfo(i)->osfhnd)
668 /* since we are not doing a dup2(), this works fine */
669 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
671 #endif /* PERL_CORE */
673 #endif /* !defined(_MSC_VER) || _MSC_VER<1900 */
675 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
676 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
677 #undef PERLIO_NOT_STDIO
679 #define PERLIO_NOT_STDIO 0
681 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
683 DllExport void *win32_signal_context(void);
684 #define PERL_GET_SIG_CONTEXT win32_signal_context()
686 #define Win_GetModuleHandle GetModuleHandle
687 #define Win_GetProcAddress GetProcAddress
688 #define Win_GetModuleFileName GetModuleFileName
689 #define Win_CreateSemaphore CreateSemaphore
691 #if defined(PERL_CORE) && !defined(O_ACCMODE)
692 # define O_ACCMODE (O_RDWR | O_WRONLY | O_RDONLY)
695 /* ucrt at least seems to allocate a whole bit per type,
696 just mask off one bit from the mask for our symlink
699 #define _S_IFLNK ((unsigned)(_S_IFMT ^ (_S_IFMT & -_S_IFMT)))
701 #define S_ISLNK(mode) (((mode) & _S_IFMT) == _S_IFLNK)
705 The default CRT struct stat uses unsigned short for st_dev and st_ino
706 which obviously isn't enough, so we define our own structure.
711 typedef unsigned __int64 Ino_t;
716 unsigned short st_mode;
727 #endif /* _INC_WIN32_PERL5 */