1 --- win32-o.h 2006-04-28 00:29:04.000000000 +0400
2 +++ win32.h 2006-04-28 19:34:28.000000000 +0400
4 -/* Time-stamp: <01/08/01 20:59:54 keuchel@w2k> */
8 * (c) 1995 Microsoft Corporation. All rights reserved.
9 * Developed by hip communications inc., http://info.hip.com/info/
11 * You may distribute under the terms of either the GNU General Public
12 * License or the Artistic License, as specified in the README file.
15 #ifndef _INC_WIN32_PERL5
16 #define _INC_WIN32_PERL5
19 # define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */
22 #if defined(PERL_IMPLICIT_SYS)
23 # define DYNAMIC_ENV_FETCH
24 -# define ENV_HV_NAME "___ENV_HV_NAME___"
25 # define HAS_GETENV_LEN
26 # define prime_env_iter()
27 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
28 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
29 # ifdef PERL_GLOBAL_STRUCT
30 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
32 # define win32_get_privlib PerlEnv_lib_path
33 # define win32_get_sitelib PerlEnv_sitelib_path
34 # define win32_get_vendorlib PerlEnv_vendorlib_path
38 # ifndef __int64 /* some versions seem to #define it already */
39 # define __int64 long long
41 # define Win32_Winsock
43 +/* Mingw32 gcc -xc++ objects to __attribute((unused)) at least */
44 +#undef PERL_UNUSED_DECL
45 +#define PERL_UNUSED_DECL
50 /* Define DllExport akin to perl's EXT,
51 * If we are in the DLL or mimicing the DLL for Win95 work round
52 * then Export the symbol,
53 * otherwise import it.
56 /* now even GCC supports __declspec() */
58 #if defined(PERLDLL) || defined(WIN95FIX)
60 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
62 #define DllExport __declspec(dllimport)
65 #define WIN32_LEAN_AND_MEAN
68 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
69 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
70 #endif /*WIN32_LEAN_AND_MEAN */
72 #ifndef TLS_OUT_OF_INDEXES
73 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
104 char sysname[SYS_NMLN];
105 char nodename[SYS_NMLN];
106 char release[SYS_NMLN];
107 char version[SYS_NMLN];
108 char machine[SYS_NMLN];
111 #ifndef START_EXTERN_C
114 # define START_EXTERN_C extern "C" {
115 # define END_EXTERN_C }
116 # define EXTERN_C extern "C"
118 # define START_EXTERN_C
119 # define END_EXTERN_C
125 #define DOSISH 1 /* no escaping our roots */
126 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
128 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
129 * real filehandles. XXX Should always be defined (the other version is untested) */
131 #define USE_SOCKETS_AS_HANDLES
133 /* read() and write() aren't transparent for socket handles */
134 #define PERL_SOCK_SYSREAD_IS_RECV
135 #define PERL_SOCK_SYSWRITE_IS_SEND
137 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
139 -/* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
140 - * to read the environment, bypassing the runtime's (usually broken)
141 - * facilities for accessing the same. See note in util.c/my_setenv(). */
142 -/*#define USE_WIN32_RTL_ENV */
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 #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
149 #define USE_FIXED_OSFHANDLE
152 +/* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
153 + DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
154 + -- BKS 5-29-2000 */
155 +#if !(defined(_M_IX86) && _MSC_VER >= 1200)
156 +#define PERL_WIN32_SOCK_DLOAD
158 #define ENV_IS_CASELESS
160 +#define PIPESOCK_MODE "b" /* pipes, sockets default to binmode */
162 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
163 #define VER_PLATFORM_WIN32_WINDOWS 1
166 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
167 #define FILE_SHARE_DELETE 0x00000004
170 /* access() mode bits */
183 #define PERL_GET_CONTEXT_DEFINED
185 /* Compiler-specific stuff. */
187 #ifdef __BORLANDC__ /* Borland C++ */
189 +#if (__BORLANDC__ <= 0x520)
190 #define _access access
194 #define _getpid getpid
195 #define wcsicmp _wcsicmp
196 #include <sys/types.h>
199 #define DllMain DllEntryPoint
202 #pragma warn -ccc /* "condition is always true/false" */
203 #pragma warn -rch /* "unreachable code" */
204 #pragma warn -sig /* "conversion may lose significant digits" */
205 #pragma warn -pia /* "possibly incorrect assignment" */
206 #pragma warn -par /* "parameter 'foo' is never used" */
207 #pragma warn -aus /* "'foo' is assigned a value that is never used" */
208 #pragma warn -use /* "'foo' is declared but never used" */
209 #pragma warn -csu /* "comparing signed and unsigned values" */
210 -#pragma warn -pro /* "call to function with no prototype" */
211 -#pragma warn -stu /* "undefined structure 'foo'" */
213 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
214 #define PERL_MEMBER_PTR_SIZE 12
216 +#define isnan _isnan
220 #ifdef _MSC_VER /* Microsoft Visual C++ */
222 -#ifndef _MODE_T_DEFINED_
223 -typedef unsigned long mode_t;
224 -#define _MODE_T_DEFINED_
227 -#pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
230 +typedef unsigned short mode_t;
231 +#pragma warning(disable: 4102) /* "unreferenced label" */
233 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
234 #define PERL_MEMBER_PTR_SIZE 16
236 +#define isnan _isnan
239 +/* VC6 has broken NaN semantics: NaN == NaN returns true instead of false */
240 +#define NAN_COMPARE_BROKEN 1
243 #endif /* _MSC_VER */
245 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
250 #define _environ environ
252 #define flushall _flushall
253 #define fcloseall _fcloseall
255 -#endif /* __MINGW32__ */
256 +#define isnan _isnan /* ...same libraries as MSVC */
259 # define _O_NOINHERIT 0x0080
260 # ifndef _NO_OLDNAMES
261 # define O_NOINHERIT _O_NOINHERIT
265 +/* <stdint.h>, pulled in by <io.h> as of mingw-runtime-3.3, typedef's
266 + * (u)intptr_t but doesn't set the _(U)INTPTR_T_DEFINED defines */
268 +# ifndef _INTPTR_T_DEFINED
269 +# define _INTPTR_T_DEFINED
271 +# ifndef _UINTPTR_T_DEFINED
272 +# define _UINTPTR_T_DEFINED
276 +#endif /* __MINGW32__ */
278 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
280 # define CP_UTF8 65001
283 /* compatibility stuff for other compilers goes here */
285 #ifndef _INTPTR_T_DEFINED
286 typedef int intptr_t;
287 # define _INTPTR_T_DEFINED
290 #ifndef _UINTPTR_T_DEFINED
291 typedef unsigned int uintptr_t;
292 # define _UINTPTR_T_DEFINED
297 +/* For UNIX compatibility. */
299 +extern uid_t getuid(void);
300 +extern gid_t getgid(void);
301 +extern uid_t geteuid(void);
302 +extern gid_t getegid(void);
303 +extern int setuid(uid_t uid);
304 +extern int setgid(gid_t gid);
305 +extern int kill(int pid, int sig);
306 +#ifndef USE_PERL_SBRK
307 +extern void *sbrk(ptrdiff_t need);
308 +# define HAS_SBRK_PROTO
310 +extern char * getlogin(void);
311 +extern int chown(const char *p, uid_t o, gid_t g);
312 +extern int mkstemp(const char *path);
315 #define Stat win32_stat
317 #undef init_os_extras
318 #define init_os_extras Perl_init_os_extras
320 DllExport void Perl_win32_init(int *argcp, char ***argvp);
321 DllExport void Perl_win32_term(void);
322 -DllExport void Perl_init_os_extras();
323 +DllExport void Perl_init_os_extras(void);
324 DllExport void win32_str_os_error(void *sv, DWORD err);
325 DllExport int RunPerl(int argc, char **argv, char **env);
332 * the following correspond to the fields of the same name
333 * in the STARTUPINFO structure. Embedders can use these to
334 * control the spawning process' look.
335 * Example - to hide the window of the spawned process:
336 * dwFlags = STARTF_USESHOWWINDOW;
337 * wShowWindow = SW_HIDE;
346 DWORD dwFillAttribute;
350 DllExport void win32_get_child_IO(child_IO_table* ptr);
351 +DllExport HWND win32_create_message_window();
353 #ifndef USE_SOCKETS_AS_HANDLES
354 extern FILE * my_fdopen(int, char *);
357 extern int my_fclose(FILE *);
358 -extern int do_aspawn(void *really, void **mark, void **sp);
359 -extern int do_spawn(char *cmd);
360 -extern int do_spawn_nowait(char *cmd);
361 +extern int my_fstat(int fd, Stat_t *sbufptr);
362 extern char * win32_get_privlib(const char *pl);
363 extern char * win32_get_sitelib(const char *pl);
364 extern char * win32_get_vendorlib(const char *pl);
365 extern int IsWin95(void);
366 extern int IsWinNT(void);
367 extern void win32_argv2utf8(int argc, char** argv);
369 #ifdef PERL_IMPLICIT_SYS
370 extern void win32_delete_internal_host(void *h);
373 extern char * staticlinkmodules[];
377 +typedef char * caddr_t; /* In malloc.c (core address). */
380 * handle socket stuff, assuming socket is always available
383 #include <sys/socket.h>
387 #define EMBEDMYMALLOC /**/
388 /* #define USE_PERL_SBRK /**/
389 /* #define PERL_SBRK_VIA_MALLOC /**/
392 #if defined(PERLDLL) && !defined(PERL_CORE)
396 #ifdef PERL_TEXTMODE_SCRIPTS
397 # define PERL_SCRIPT_MODE "r"
399 # define PERL_SCRIPT_MODE "rb"
402 -#ifndef Sighandler_t
403 -typedef Signal_t (*Sighandler_t) (int);
404 -#define Sighandler_t Sighandler_t
408 * Now Win32 specific per-thread data stuff
411 +/* Leave the first couple ids after WM_USER unused because they
412 + * might be used by an embedding application, and on Windows
413 + * version before 2000 we might end up eating those messages
414 + * if they were not meant for us.
416 +#define WM_USER_MIN (WM_USER+30)
417 +#define WM_USER_MESSAGE (WM_USER_MIN)
418 +#define WM_USER_KILL (WM_USER_MIN+1)
419 +#define WM_USER_MAX (WM_USER_MIN+1)
421 struct thread_intern {
422 /* XXX can probably use one buffer instead of several */
423 char Wstrerror_buffer[512];
424 struct servent Wservent;
425 char Wgetlogin_buffer[128];
426 -# ifdef USE_SOCKETS_AS_HANDLES
427 - int Winit_socktype;
429 # ifdef HAVE_DES_FCRYPT
430 char Wcrypt_buffer[30];
432 # ifdef USE_RTL_THREAD_API
433 void * retv; /* slot for thread return value */
435 BOOL Wuse_showwindow;
439 #define HAVE_INTERP_INTERN
442 DWORD pids[MAXIMUM_WAIT_OBJECTS];
443 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
449 + DWORD pids[MAXIMUM_WAIT_OBJECTS];
450 + HANDLE handles[MAXIMUM_WAIT_OBJECTS];
451 + HWND message_hwnds[MAXIMUM_WAIT_OBJECTS];
455 +#ifndef Sighandler_t
456 +typedef Signal_t (*Sighandler_t) (int);
457 +#define Sighandler_t Sighandler_t
460 struct interp_intern {
461 char * perlshell_tokens;
462 char ** perlshell_vec;
463 long perlshell_items;
465 child_tab * children;
468 - child_tab * pseudo_children;
469 + pseudo_child_tab * pseudo_children;
471 void * internal_host;
472 struct thread_intern thr_intern;
476 Sighandler_t sigtable[SIG_SIZE];
479 DllExport int win32_async_check(pTHX);
481 #define WIN32_POLL_INTERVAL 32768
482 #define PERL_ASYNC_CHECK() if (w32_do_async || PL_sig_pending) win32_async_check(aTHX)
484 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
485 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
486 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
487 #define w32_fdpid (PL_sys_intern.fdpid)
488 #define w32_children (PL_sys_intern.children)
489 #define w32_num_children (w32_children->num)
490 #define w32_child_pids (w32_children->pids)
491 #define w32_child_handles (w32_children->handles)
492 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
493 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
494 #define w32_num_pseudo_children (w32_pseudo_children->num)
495 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
496 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
497 +#define w32_pseudo_child_message_hwnds (w32_pseudo_children->message_hwnds)
498 #define w32_internal_host (PL_sys_intern.internal_host)
499 #define w32_timerid (PL_sys_intern.timerid)
500 +#define w32_message_hwnd (PL_sys_intern.message_hwnd)
501 #define w32_sighandler (PL_sys_intern.sigtable)
502 #define w32_poll_count (PL_sys_intern.poll_count)
503 #define w32_do_async (w32_poll_count++ > WIN32_POLL_INTERVAL)
504 #define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
505 #define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
506 #define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
507 #define w32_servent (PL_sys_intern.thr_intern.Wservent)
508 -#define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
509 #define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow)
510 -#define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
511 +#define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow)
514 # define PERL_WAIT_FOR_CHILDREN \
516 if (w32_pseudo_children && w32_num_pseudo_children) { \
517 long children = w32_num_pseudo_children; \
518 WaitForMultipleObjects(children, \
519 w32_pseudo_child_handles, \
522 CloseHandle(w32_pseudo_child_handles[--children]); \
527 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
530 /* C doesn't like repeat struct definitions */
531 +#if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION>=3)
535 #define _CRTIMP __declspec(dllimport)
539 * Control structure for lowio file handles
542 intptr_t osfhnd;/* underlying OS file HANDLE */
543 char osfile; /* attributes of file (e.g., open in text mode?) */
544 char pipech; /* one char buffer for handles opened on pipes */
546 CRITICAL_SECTION lock;
551 * Array of arrays of control structures for lowio files.
553 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
556 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
557 * array of ioinfo structs.
562 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
564 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
567 * Access macros for getting at an ioinfo struct and its fields from a
570 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
571 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
572 #define _osfile(i) (_pioinfo(i)->osfile)
573 #define _pipech(i) (_pioinfo(i)->pipech)
575 /* since we are not doing a dup2(), this works fine */
576 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (intptr_t)osfh)
580 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
581 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
582 #undef PERLIO_NOT_STDIO
584 #define PERLIO_NOT_STDIO 0
589 * This provides a layer of functions and macros to ensure extensions will
590 * get to use the same RTL functions as the core.
592 #include "win32iop.h"
594 +#define EXEC_ARGV_CAST(x) ((const char *const *) x)
596 +#if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
597 +#define ECONNABORTED WSAECONNABORTED
599 +#if !defined(ECONNRESET) && defined(WSAECONNRESET)
600 +#define ECONNRESET WSAECONNRESET
602 +#if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
603 +#define EAFNOSUPPORT WSAEAFNOSUPPORT
605 +/* Why not needed for ECONNREFUSED? --abe */
607 +DllExport void *win32_signal_context(void);
608 +#define PERL_GET_SIG_CONTEXT win32_signal_context()
611 #define Win_GetModuleHandle XCEGetModuleHandleA
612 #define Win_GetProcAddress XCEGetProcAddressA
613 #define Win_GetModuleFileName XCEGetModuleFileNameA
614 #define Win_CreateSemaphore CreateSemaphoreW
616 #define Win_GetModuleHandle GetModuleHandle
617 #define Win_GetProcAddress GetProcAddress
618 #define Win_GetModuleFileName GetModuleFileName
619 #define Win_CreateSemaphore CreateSemaphore
622 #endif /* _INC_WIN32_PERL5 */