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
92 char sysname[SYS_NMLN];
93 char nodename[SYS_NMLN];
94 char release[SYS_NMLN];
95 char version[SYS_NMLN];
96 char machine[SYS_NMLN];
99 #ifndef START_EXTERN_C
102 # define START_EXTERN_C extern "C" {
103 # define END_EXTERN_C }
104 # define EXTERN_C extern "C"
106 # define START_EXTERN_C
107 # define END_EXTERN_C
113 #define DOSISH 1 /* no escaping our roots */
114 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
116 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
117 * real filehandles. XXX Should always be defined (the other version is untested) */
118 #define USE_SOCKETS_AS_HANDLES
120 /* read() and write() aren't transparent for socket handles */
121 #define PERL_SOCK_SYSREAD_IS_RECV
122 #define PERL_SOCK_SYSWRITE_IS_SEND
124 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
126 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
127 It now uses some black magic to work seamlessly with the DLL CRT and
128 works with MSVC++ 4.0+ or GCC/Mingw32
130 #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
131 #define USE_FIXED_OSFHANDLE
134 /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
135 DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
137 #if !(defined(_M_IX86) && _MSC_VER >= 1200)
138 #define PERL_WIN32_SOCK_DLOAD
140 #define ENV_IS_CASELESS
142 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
143 #define VER_PLATFORM_WIN32_WINDOWS 1
146 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
147 #define FILE_SHARE_DELETE 0x00000004
150 /* access() mode bits */
163 #define PERL_GET_CONTEXT_DEFINED
165 /* Compiler-specific stuff. */
167 #ifdef __BORLANDC__ /* Borland C++ */
169 #if (__BORLANDC__ <= 0x520)
170 #define _access access
174 #define _getpid getpid
175 #define wcsicmp _wcsicmp
176 #include <sys/types.h>
179 #define DllMain DllEntryPoint
182 #pragma warn -ccc /* "condition is always true/false" */
183 #pragma warn -rch /* "unreachable code" */
184 #pragma warn -sig /* "conversion may lose significant digits" */
185 #pragma warn -pia /* "possibly incorrect assignment" */
186 #pragma warn -par /* "parameter 'foo' is never used" */
187 #pragma warn -aus /* "'foo' is assigned a value that is never used" */
188 #pragma warn -use /* "'foo' is declared but never used" */
189 #pragma warn -csu /* "comparing signed and unsigned values" */
191 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
192 #define PERL_MEMBER_PTR_SIZE 12
198 #ifdef _MSC_VER /* Microsoft Visual C++ */
202 typedef unsigned short mode_t;
203 #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
205 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
206 #define PERL_MEMBER_PTR_SIZE 16
210 #endif /* _MSC_VER */
212 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
217 #define _environ environ
219 #define flushall _flushall
220 #define fcloseall _fcloseall
221 #define isnan _isnan /* ...same libraries as MSVC */
224 # define _O_NOINHERIT 0x0080
225 # ifndef _NO_OLDNAMES
226 # define O_NOINHERIT _O_NOINHERIT
230 #endif /* __MINGW32__ */
232 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
234 # define CP_UTF8 65001
237 /* compatibility stuff for other compilers goes here */
241 /* For UNIX compatibility. */
243 extern uid_t getuid(void);
244 extern gid_t getgid(void);
245 extern uid_t geteuid(void);
246 extern gid_t getegid(void);
247 extern int setuid(uid_t uid);
248 extern int setgid(gid_t gid);
249 extern int kill(int pid, int sig);
250 extern void *sbrk(int need);
251 extern char * getlogin(void);
252 extern int chown(const char *p, uid_t o, gid_t g);
253 extern int mkstemp(const char *path);
256 #define Stat win32_stat
258 #undef init_os_extras
259 #define init_os_extras Perl_init_os_extras
261 DllExport void Perl_win32_init(int *argcp, char ***argvp);
262 DllExport void Perl_init_os_extras(void);
263 DllExport void win32_str_os_error(void *sv, DWORD err);
264 DllExport int RunPerl(int argc, char **argv, char **env);
271 * the following correspond to the fields of the same name
272 * in the STARTUPINFO structure. Embedders can use these to
273 * control the spawning process' look.
274 * Example - to hide the window of the spawned process:
275 * dwFlags = STARTF_USESHOWWINDOW;
276 * wShowWindow = SW_HIDE;
285 DWORD dwFillAttribute;
289 DllExport void win32_get_child_IO(child_IO_table* ptr);
291 #ifndef USE_SOCKETS_AS_HANDLES
292 extern FILE * my_fdopen(int, char *);
294 extern int my_fclose(FILE *);
295 extern int my_fstat(int fd, struct stat *sbufptr);
296 extern int do_aspawn(void *really, void **mark, void **sp);
297 extern int do_spawn(char *cmd);
298 extern int do_spawn_nowait(char *cmd);
299 extern char * win32_get_privlib(const char *pl);
300 extern char * win32_get_sitelib(const char *pl);
301 extern char * win32_get_vendorlib(const char *pl);
302 extern int IsWin95(void);
303 extern int IsWinNT(void);
304 extern void win32_argv2utf8(int argc, char** argv);
306 #ifdef PERL_IMPLICIT_SYS
307 extern void win32_delete_internal_host(void *h);
310 extern char * staticlinkmodules[];
314 typedef char * caddr_t; /* In malloc.c (core address). */
317 * handle socket stuff, assuming socket is always available
319 #include <sys/socket.h>
323 #define EMBEDMYMALLOC /**/
324 /* #define USE_PERL_SBRK /**/
325 /* #define PERL_SBRK_VIA_MALLOC /**/
328 #if defined(PERLDLL) && !defined(PERL_CORE)
332 #ifdef PERL_TEXTMODE_SCRIPTS
333 # define PERL_SCRIPT_MODE "r"
335 # define PERL_SCRIPT_MODE "rb"
339 * Now Win32 specific per-thread data stuff
342 struct thread_intern {
343 /* XXX can probably use one buffer instead of several */
344 char Wstrerror_buffer[512];
345 struct servent Wservent;
346 char Wgetlogin_buffer[128];
347 # ifdef USE_SOCKETS_AS_HANDLES
350 # ifdef HAVE_DES_FCRYPT
351 char Wcrypt_buffer[30];
353 # ifdef USE_RTL_THREAD_API
354 void * retv; /* slot for thread return value */
358 #ifdef USE_5005THREADS
359 # ifndef USE_DECLSPEC_THREAD
360 # define HAVE_THREAD_INTERN
361 # endif /* !USE_DECLSPEC_THREAD */
362 #endif /* USE_5005THREADS */
364 #define HAVE_INTERP_INTERN
367 DWORD pids[MAXIMUM_WAIT_OBJECTS];
368 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
371 struct interp_intern {
372 char * perlshell_tokens;
373 char ** perlshell_vec;
374 long perlshell_items;
376 child_tab * children;
379 child_tab * pseudo_children;
381 void * internal_host;
382 #ifndef USE_5005THREADS
383 struct thread_intern thr_intern;
388 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
389 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
390 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
391 #define w32_fdpid (PL_sys_intern.fdpid)
392 #define w32_children (PL_sys_intern.children)
393 #define w32_num_children (w32_children->num)
394 #define w32_child_pids (w32_children->pids)
395 #define w32_child_handles (w32_children->handles)
396 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
397 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
398 #define w32_num_pseudo_children (w32_pseudo_children->num)
399 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
400 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
401 #define w32_internal_host (PL_sys_intern.internal_host)
402 #ifdef USE_5005THREADS
403 # define w32_strerror_buffer (thr->i.Wstrerror_buffer)
404 # define w32_getlogin_buffer (thr->i.Wgetlogin_buffer)
405 # define w32_crypt_buffer (thr->i.Wcrypt_buffer)
406 # define w32_servent (thr->i.Wservent)
407 # define w32_init_socktype (thr->i.Winit_socktype)
409 # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
410 # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
411 # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
412 # define w32_servent (PL_sys_intern.thr_intern.Wservent)
413 # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
414 #endif /* USE_5005THREADS */
416 /* UNICODE<>ANSI translation helpers */
417 /* Use CP_ACP when mode is ANSI */
418 /* Use CP_UTF8 when mode is UTF8 */
420 #define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
421 (lpw[0] = 0, MultiByteToWideChar((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
422 lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
423 #define A2WHELPER(lpa, lpw, nBytes) A2WHELPER_LEN(lpa, -1, lpw, nBytes)
425 #define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
426 (lpa[0] = '\0', WideCharToMultiByte((IN_BYTES) ? CP_ACP : CP_UTF8, 0, \
427 lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
428 #define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
430 #define USING_WIDE() (PL_widesyscalls && PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
433 # define PERL_WAIT_FOR_CHILDREN \
435 if (w32_pseudo_children && w32_num_pseudo_children) { \
436 long children = w32_num_pseudo_children; \
437 WaitForMultipleObjects(children, \
438 w32_pseudo_child_handles, \
441 CloseHandle(w32_pseudo_child_handles[--children]); \
446 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
449 /* C doesn't like repeat struct definitions */
451 #define _CRTIMP __declspec(dllimport)
455 * Control structure for lowio file handles
458 long osfhnd; /* underlying OS file HANDLE */
459 char osfile; /* attributes of file (e.g., open in text mode?) */
460 char pipech; /* one char buffer for handles opened on pipes */
462 CRITICAL_SECTION lock;
467 * Array of arrays of control structures for lowio files.
469 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
472 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
473 * array of ioinfo structs.
478 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
480 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
483 * Access macros for getting at an ioinfo struct and its fields from a
486 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
487 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
488 #define _osfile(i) (_pioinfo(i)->osfile)
489 #define _pipech(i) (_pioinfo(i)->pipech)
491 /* since we are not doing a dup2(), this works fine */
492 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (long)osfh)
496 /* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
497 #if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
498 #undef PERLIO_NOT_STDIO
500 #define PERLIO_NOT_STDIO 0
505 * This provides a layer of functions and macros to ensure extensions will
506 * get to use the same RTL functions as the core.
508 #include "win32iop.h"
510 #define EXEC_ARGV_CAST(x) ((const char *const *) x)
512 #endif /* _INC_WIN32_PERL5 */