3 * (c) 1995 Microsoft Corporation. All rights reserved.
4 * Developed by hip communications inc., http://info.hip.com/info/
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
61 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
62 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
63 #endif /*WIN32_LEAN_AND_MEAN */
65 #ifndef TLS_OUT_OF_INDEXES
66 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
93 char sysname[SYS_NMLN];
94 char nodename[SYS_NMLN];
95 char release[SYS_NMLN];
96 char version[SYS_NMLN];
97 char machine[SYS_NMLN];
100 #ifndef START_EXTERN_C
103 # define START_EXTERN_C extern "C" {
104 # define END_EXTERN_C }
105 # define EXTERN_C extern "C"
107 # define START_EXTERN_C
108 # define END_EXTERN_C
114 #define DOSISH 1 /* no escaping our roots */
115 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
117 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
118 * real filehandles. XXX Should always be defined (the other version is untested) */
119 #define USE_SOCKETS_AS_HANDLES
121 /* read() and write() aren't transparent for socket handles */
122 #define PERL_SOCK_SYSREAD_IS_RECV
123 #define PERL_SOCK_SYSWRITE_IS_SEND
125 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
127 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
128 It now uses some black magic to work seamlessly with the DLL CRT and
129 works with MSVC++ 4.0+ or GCC/Mingw32
131 #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
132 #define USE_FIXED_OSFHANDLE
135 /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
136 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
138 #if !(defined(_M_IX86) && _MSC_VER >= 1200)
139 #define PERL_WIN32_SOCK_DLOAD
141 #define ENV_IS_CASELESS
143 #define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
145 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
146 #define VER_PLATFORM_WIN32_WINDOWS 1
149 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
150 #define FILE_SHARE_DELETE 0x00000004
153 /* access() mode bits */
166 #define PERL_GET_CONTEXT_DEFINED
168 /* Compiler-specific stuff. */
170 #ifdef __BORLANDC__ /* Borland C++ */
172 #if (__BORLANDC__ <= 0x520)
173 #define _access access
177 #define _getpid getpid
178 #define wcsicmp _wcsicmp
179 #include <sys/types.h>
182 #define DllMain DllEntryPoint
185 #pragma warn -ccc /* "condition is always true/false" */
186 #pragma warn -rch /* "unreachable code" */
187 #pragma warn -sig /* "conversion may lose significant digits" */
188 #pragma warn -pia /* "possibly incorrect assignment" */
189 #pragma warn -par /* "parameter 'foo' is never used" */
190 #pragma warn -aus /* "'foo' is assigned a value that is never used" */
191 #pragma warn -use /* "'foo' is declared but never used" */
192 #pragma warn -csu /* "comparing signed and unsigned values" */
194 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
195 #define PERL_MEMBER_PTR_SIZE 12
201 #ifdef _MSC_VER /* Microsoft Visual C++ */
205 typedef unsigned short mode_t;
206 #pragma warning(disable: 4102) /* "unreferenced label" */
208 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
209 #define PERL_MEMBER_PTR_SIZE 16
212 #define snprintf _snprintf
213 #define vsnprintf _vsnprintf
216 /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
217 #define NAN_COMPARE_BROKEN 1
220 #endif /* _MSC_VER */
222 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
227 #define _environ environ
229 #define flushall _flushall
230 #define fcloseall _fcloseall
231 #define isnan _isnan /* ...same libraries as MSVC */
234 # define _O_NOINHERIT 0x0080
235 # ifndef _NO_OLDNAMES
236 # define O_NOINHERIT _O_NOINHERIT
240 /* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
241 * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
243 # ifndef _INTPTR_T_DEFINED
244 # define _INTPTR_T_DEFINED
246 # ifndef _UINTPTR_T_DEFINED
247 # define _UINTPTR_T_DEFINED
251 #endif /* __MINGW32__ */
253 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
255 # define CP_UTF8 65001
258 /* compatibility stuff for other compilers goes here */
260 #ifndef _INTPTR_T_DEFINED
261 typedef int intptr_t;
262 # define _INTPTR_T_DEFINED
265 #ifndef _UINTPTR_T_DEFINED
266 typedef unsigned int uintptr_t;
267 # define _UINTPTR_T_DEFINED
272 /* For UNIX compatibility. */
274 extern uid_t getuid(void);
275 extern gid_t getgid(void);
276 extern uid_t geteuid(void);
277 extern gid_t getegid(void);
278 extern int setuid(uid_t uid);
279 extern int setgid(gid_t gid);
280 extern int kill(int pid, int sig);
281 #ifndef USE_PERL_SBRK
282 extern void *sbrk(ptrdiff_t need);
283 # define HAS_SBRK_PROTO
285 extern char * getlogin(void);
286 extern int chown(const char *p, uid_t o, gid_t g);
287 extern int mkstemp(const char *path);
290 #define Stat win32_stat
292 #undef init_os_extras
293 #define init_os_extras Perl_init_os_extras
295 DllExport void Perl_win32_init(int *argcp, char ***argvp);
296 DllExport void Perl_win32_term(void);
297 DllExport void Perl_init_os_extras(void);
298 DllExport void win32_str_os_error(void *sv, DWORD err);
299 DllExport int RunPerl(int argc, char **argv, char **env);
306 * the following correspond to the fields of the same name
307 * in the STARTUPINFO structure. Embedders can use these to
308 * control the spawning process' look.
309 * Example - to hide the window of the spawned process:
310 * dwFlags = STARTF_USESHOWWINDOW;
311 * wShowWindow = SW_HIDE;
320 DWORD dwFillAttribute;
324 DllExport void win32_get_child_IO(child_IO_table* ptr);
325 DllExport HWND win32_create_message_window();
327 #ifndef USE_SOCKETS_AS_HANDLES
328 extern FILE * my_fdopen(int, char *);
330 extern int my_fclose(FILE *);
331 extern int my_fstat(int fd, Stat_t *sbufptr);
332 extern char * win32_get_privlib(const char *pl);
333 extern char * win32_get_sitelib(const char *pl);
334 extern char * win32_get_vendorlib(const char *pl);
335 extern int IsWin95(void);
336 extern int IsWinNT(void);
337 extern void win32_argv2utf8(int argc, char** argv);
339 #ifdef PERL_IMPLICIT_SYS
340 extern void win32_delete_internal_host(void *h);
343 extern char * staticlinkmodules[];
347 typedef char * caddr_t; /* In malloc.c (core address). */
350 * handle socket stuff, assuming socket is always available
352 #include <sys/socket.h>
356 #define EMBEDMYMALLOC /**/
357 /* #define USE_PERL_SBRK /**/
358 /* #define PERL_SBRK_VIA_MALLOC /**/
361 #if defined(PERLDLL) && !defined(PERL_CORE)
365 #ifdef PERL_TEXTMODE_SCRIPTS
366 # define PERL_SCRIPT_MODE "r"
368 # define PERL_SCRIPT_MODE "rb"
372 * Now Win32 specific per-thread data stuff
375 /* Leave the first couple ids after WM_USER unused because they
376 * might be used by an embedding application, and on Windows
377 * version before 2000 we might end up eating those messages
378 * if they were not meant for us.
380 #define WM_USER_MIN (WM_USER+30)
381 #define WM_USER_MESSAGE (WM_USER_MIN)
382 #define WM_USER_KILL (WM_USER_MIN+1)
383 #define WM_USER_MAX (WM_USER_MIN+1)
385 struct thread_intern {
386 /* XXX can probably use one buffer instead of several */
387 char Wstrerror_buffer[512];
388 struct servent Wservent;
389 char Wgetlogin_buffer[128];
390 # ifdef HAVE_DES_FCRYPT
391 char Wcrypt_buffer[30];
393 # ifdef USE_RTL_THREAD_API
394 void * retv; /* slot for thread return value */
396 BOOL Wuse_showwindow;
400 #define HAVE_INTERP_INTERN
403 DWORD pids[MAXIMUM_WAIT_OBJECTS];
404 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
410 DWORD pids[MAXIMUM_WAIT_OBJECTS];
411 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
412 HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
417 typedef Signal_t (*Sighandler_t) (int);
418 #define Sighandler_t Sighandler_t
421 struct interp_intern {
422 char * perlshell_tokens;
423 char ** perlshell_vec;
424 long perlshell_items;
426 child_tab * children;
429 pseudo_child_tab * pseudo_children;
431 void * internal_host;
432 struct thread_intern thr_intern;
436 Sighandler_t sigtable[SIG_SIZE];
439 DllExport int win32_async_check(pTHX);
441 #define WIN32_POLL_INTERVAL 32768
442 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
444 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
445 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
446 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
447 #define w32_fdpid (PL_sys_intern.fdpid)
448 #define w32_children (PL_sys_intern.children)
449 #define w32_num_children (w32_children->num)
450 #define w32_child_pids (w32_children->pids)
451 #define w32_child_handles (w32_children->handles)
452 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
453 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
454 #define w32_num_pseudo_children (w32_pseudo_children->num)
455 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
456 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
457 #define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
458 #define w32_internal_host (PL_sys_intern.internal_host)
459 #define w32_timerid (PL_sys_intern.timerid)
460 #define w32_message_hwnd (PL_sys_intern.message_hwnd)
461 #define w32_sighandler (PL_sys_intern.sigtable)
462 #define w32_poll_count (PL_sys_intern.poll_count)
463 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
464 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
465 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
466 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
467 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
468 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
469 #define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
472 # define PERL_WAIT_FOR_CHILDREN \
474 if (w32_pseudo_children && w32_num_pseudo_children) { \
475 long children = w32_num_pseudo_children; \
476 WaitForMultipleObjects(children, \
477 w32_pseudo_child_handles, \
480 CloseHandle(w32_pseudo_child_handles[--children]); \
485 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
488 /* C doesn't like repeat struct definitions */
489 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
493 #define _CRTIMP __declspec(dllimport)
497 * Control structure for lowio file handles
500 intptr_t osfhnd;/* underlying OS file HANDLE */
501 char osfile; /* attributes of file (e.g., open in text mode?) */
502 char pipech; /* one char buffer for handles opened on pipes */
504 CRITICAL_SECTION lock;
509 * Array of arrays of control structures for lowio files.
511 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
514 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
515 * array of ioinfo structs.
520 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
522 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
525 * Access macros for getting at an ioinfo struct and its fields from a
528 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
529 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
530 #define _osfile(i) (_pioinfo(i)->osfile)
531 #define _pipech(i) (_pioinfo(i)->pipech)
533 /* since we are not doing a dup2(), this works fine */
534 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
538 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
539 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
540 #undef PERLIO_NOT_STDIO
542 #define PERLIO_NOT_STDIO 0
547 * This provides a layer of functions and macros to ensure extensions will
548 * get to use the same RTL functions as the core.
550 #include "win32iop.h"
552 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
554 #if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
555 #define ECONNABORTED WSAECONNABORTED
557 #if !defined(ECONNRESET) && defined(WSAECONNRESET)
558 #define ECONNRESET WSAECONNRESET
560 #if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
561 #define EAFNOSUPPORT WSAEAFNOSUPPORT
563 /* Why not needed for ECONNREFUSED? --abe */
565 DllExport void *win32_signal_context(void);
566 #define PERL_GET_SIG_CONTEXT win32_signal_context()
569 #define Win_GetModuleHandle XCEGetModuleHandleA
570 #define Win_GetProcAddress XCEGetProcAddressA
571 #define Win_GetModuleFileName XCEGetModuleFileNameA
572 #define Win_CreateSemaphore CreateSemaphoreW
574 #define Win_GetModuleHandle GetModuleHandle
575 #define Win_GetProcAddress GetProcAddress
576 #define Win_GetModuleFileName GetModuleFileName
577 #define Win_CreateSemaphore CreateSemaphore
580 #endif /* _INC_WIN32_PERL5 */