1 // Time-stamp: <01/08/01 20:59:54 keuchel@w2k>
5 * (c) 1995 Microsoft Corporation. All rights reserved.
6 * Developed by hip communications inc., http://info.hip.com/info/
8 * You may distribute under the terms of either the GNU General Public
9 * License or the Artistic License, as specified in the README file.
12 #ifndef _INC_WIN32_PERL5
13 #define _INC_WIN32_PERL5
16 # define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */
19 #if defined(PERL_OBJECT) || defined(PERL_IMPLICIT_SYS) || defined(PERL_CAPI)
20 # define DYNAMIC_ENV_FETCH
21 # define ENV_HV_NAME "___ENV_HV_NAME___"
22 # define HAS_GETENV_LEN
23 # define prime_env_iter()
24 # define WIN32IO_IS_STDIO /* don't pull in custom stdio layer */
25 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
26 # ifdef PERL_GLOBAL_STRUCT
27 # error PERL_GLOBAL_STRUCT cannot be defined with PERL_IMPLICIT_SYS
29 # define win32_get_privlib PerlEnv_lib_path
30 # define win32_get_sitelib PerlEnv_sitelib_path
31 # define win32_get_vendorlib PerlEnv_vendorlib_path
35 # ifndef __int64 /* some versions seem to #define it already */
36 # define __int64 long long
38 # define Win32_Winsock
41 /* Define DllExport akin to perl's EXT,
42 * If we are in the DLL or mimicing the DLL for Win95 work round
43 * then Export the symbol,
44 * otherwise import it.
47 /* now even GCC supports __declspec() */
49 #if defined(PERL_OBJECT)
52 #if defined(PERLDLL) || defined(WIN95FIX)
54 /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
56 #define DllExport __declspec(dllimport)
60 #define WIN32_LEAN_AND_MEAN
63 #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
64 #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
65 #endif /*WIN32_LEAN_AND_MEAN */
67 #ifndef TLS_OUT_OF_INDEXES
68 #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
96 char sysname[SYS_NMLN];
97 char nodename[SYS_NMLN];
98 char release[SYS_NMLN];
99 char version[SYS_NMLN];
100 char machine[SYS_NMLN];
103 #ifndef START_EXTERN_C
106 # define START_EXTERN_C extern "C" {
107 # define END_EXTERN_C }
108 # define EXTERN_C extern "C"
110 # define START_EXTERN_C
111 # define END_EXTERN_C
117 #define DOSISH 1 /* no escaping our roots */
118 #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
120 /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
121 * real filehandles. XXX Should always be defined (the other version is untested) */
123 //#define USE_SOCKETS_AS_HANDLES
125 /* read() and write() aren't transparent for socket handles */
126 #define PERL_SOCK_SYSREAD_IS_RECV
127 #define PERL_SOCK_SYSWRITE_IS_SEND
129 #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
131 /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
132 * to read the environment, bypassing the runtime's (usually broken)
133 * facilities for accessing the same. See note in util.c/my_setenv(). */
134 /*#define USE_WIN32_RTL_ENV */
136 /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
137 It now uses some black magic to work seamlessly with the DLL CRT and
138 works with MSVC++ 4.0+ or GCC/Mingw32
140 #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
141 #define USE_FIXED_OSFHANDLE
144 #define ENV_IS_CASELESS
146 #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
147 #define VER_PLATFORM_WIN32_WINDOWS 1
150 #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
151 #define FILE_SHARE_DELETE 0x00000004
154 /* access() mode bits */
162 #define PERL_GET_CONTEXT_DEFINED
164 /* Compiler-specific stuff. */
166 #ifdef __BORLANDC__ /* Borland C++ */
168 #define _access access
170 #define _getpid getpid
171 #define wcsicmp _wcsicmp
172 #include <sys/types.h>
175 #define DllMain DllEntryPoint
178 #pragma warn -ccc /* "condition is always true/false" */
179 #pragma warn -rch /* "unreachable code" */
180 #pragma warn -sig /* "conversion may lose significant digits" */
181 #pragma warn -pia /* "possibly incorrect assignment" */
182 #pragma warn -par /* "parameter 'foo' is never used" */
183 #pragma warn -aus /* "'foo' is assigned a value that is never used" */
184 #pragma warn -use /* "'foo' is declared but never used" */
185 #pragma warn -csu /* "comparing signed and unsigned values" */
186 #pragma warn -pro /* "call to function with no prototype" */
187 #pragma warn -stu /* "undefined structure 'foo'" */
189 /* Borland is picky about a bare member function name used as its ptr */
191 # define MEMBER_TO_FPTR(name) &(name)
194 /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
195 #define PERL_MEMBER_PTR_SIZE 12
199 #ifdef _MSC_VER /* Microsoft Visual C++ */
201 #ifndef _MODE_T_DEFINED_
202 typedef unsigned long mode_t;
203 #define _MODE_T_DEFINED_
206 #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
208 /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
209 #define PERL_MEMBER_PTR_SIZE 16
211 #endif /* _MSC_VER */
213 #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
218 #define _environ environ
220 #define flushall _flushall
221 #define fcloseall _fcloseall
224 # define MEMBER_TO_FPTR(name) &(name)
228 # define _O_NOINHERIT 0x0080
229 # ifndef _NO_OLDNAMES
230 # define O_NOINHERIT _O_NOINHERIT
234 #endif /* __MINGW32__ */
236 /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
238 # define CP_UTF8 65001
241 /* compatibility stuff for other compilers goes here */
244 #if !defined(PERL_OBJECT) && defined(PERL_CAPI) && defined(PERL_MEMBER_PTR_SIZE)
245 # define STRUCT_MGVTBL_DEFINITION \
248 int (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg); \
249 char handle_VC_problem1[PERL_MEMBER_PTR_SIZE]; \
252 int (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg); \
253 char handle_VC_problem2[PERL_MEMBER_PTR_SIZE]; \
256 U32 (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg); \
257 char handle_VC_problem3[PERL_MEMBER_PTR_SIZE]; \
260 int (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg); \
261 char handle_VC_problem4[PERL_MEMBER_PTR_SIZE]; \
264 int (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg); \
265 char handle_VC_problem5[PERL_MEMBER_PTR_SIZE]; \
269 # define BASEOP_DEFINITION \
272 OP* (CPERLscope(*op_ppaddr))(pTHX); \
273 char handle_VC_problem[PERL_MEMBER_PTR_SIZE-sizeof(OP*)]; \
280 #endif /* !PERL_OBJECT && PERL_CAPI && PERL_MEMBER_PTR_SIZE */
286 #define Stat win32_stat
288 #undef init_os_extras
289 #define init_os_extras Perl_init_os_extras
291 DllExport void Perl_win32_init(int *argcp, char ***argvp);
292 DllExport void Perl_init_os_extras();
293 DllExport void win32_str_os_error(void *sv, DWORD err);
294 DllExport int RunPerl(int argc, char **argv, char **env);
301 * the following correspond to the fields of the same name
302 * in the STARTUPINFO structure. Embedders can use these to
303 * control the spawning process' look.
304 * Example - to hide the window of the spawned process:
305 * dwFlags = STARTF_USESHOWWINDOW;
306 * wShowWindow = SW_HIDE;
315 DWORD dwFillAttribute;
319 DllExport void win32_get_child_IO(child_IO_table* ptr);
321 #ifndef USE_SOCKETS_AS_HANDLES
322 extern FILE * my_fdopen(int, char *);
325 extern int my_fclose(FILE *);
326 extern int do_aspawn(void *really, void **mark, void **sp);
327 extern int do_spawn(char *cmd);
328 extern int do_spawn_nowait(char *cmd);
329 extern char * win32_get_privlib(const char *pl);
330 extern char * win32_get_sitelib(const char *pl);
331 extern char * win32_get_vendorlib(const char *pl);
332 extern int IsWin95(void);
333 extern int IsWinNT(void);
334 extern void win32_argv2utf8(int argc, char** argv);
336 #ifdef PERL_IMPLICIT_SYS
337 extern void win32_delete_internal_host(void *h);
340 extern char * staticlinkmodules[];
345 * handle socket stuff, assuming socket is always available
348 #include <sys/socket.h>
352 #define EMBEDMYMALLOC /**/
353 /* #define USE_PERL_SBRK /**/
354 /* #define PERL_SBRK_VIA_MALLOC /**/
357 #if defined(PERLDLL) && !defined(PERL_CORE)
361 #ifdef PERL_TEXTMODE_SCRIPTS
362 # define PERL_SCRIPT_MODE "r"
364 # define PERL_SCRIPT_MODE "rb"
368 * Now Win32 specific per-thread data stuff
371 struct thread_intern {
372 /* XXX can probably use one buffer instead of several */
373 char Wstrerror_buffer[512];
374 struct servent Wservent;
375 char Wgetlogin_buffer[128];
376 # ifdef USE_SOCKETS_AS_HANDLES
379 # ifdef HAVE_DES_FCRYPT
380 char Wcrypt_buffer[30];
382 # ifdef USE_RTL_THREAD_API
383 void * retv; /* slot for thread return value */
388 # ifndef USE_DECLSPEC_THREAD
389 # define HAVE_THREAD_INTERN
390 # endif /* !USE_DECLSPEC_THREAD */
391 #endif /* USE_THREADS */
393 #define HAVE_INTERP_INTERN
396 DWORD pids[MAXIMUM_WAIT_OBJECTS];
397 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
400 struct interp_intern {
401 char * perlshell_tokens;
402 char ** perlshell_vec;
403 long perlshell_items;
405 child_tab * children;
408 child_tab * pseudo_children;
410 void * internal_host;
412 struct thread_intern thr_intern;
417 #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
418 #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
419 #define w32_perlshell_items (PL_sys_intern.perlshell_items)
420 #define w32_fdpid (PL_sys_intern.fdpid)
421 #define w32_children (PL_sys_intern.children)
422 #define w32_num_children (w32_children->num)
423 #define w32_child_pids (w32_children->pids)
424 #define w32_child_handles (w32_children->handles)
425 #define w32_pseudo_id (PL_sys_intern.pseudo_id)
426 #define w32_pseudo_children (PL_sys_intern.pseudo_children)
427 #define w32_num_pseudo_children (w32_pseudo_children->num)
428 #define w32_pseudo_child_pids (w32_pseudo_children->pids)
429 #define w32_pseudo_child_handles (w32_pseudo_children->handles)
430 #define w32_internal_host (PL_sys_intern.internal_host)
432 # define w32_strerror_buffer (thr->i.Wstrerror_buffer)
433 # define w32_getlogin_buffer (thr->i.Wgetlogin_buffer)
434 # define w32_crypt_buffer (thr->i.Wcrypt_buffer)
435 # define w32_servent (thr->i.Wservent)
436 # define w32_init_socktype (thr->i.Winit_socktype)
438 # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
439 # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
440 # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
441 # define w32_servent (PL_sys_intern.thr_intern.Wservent)
442 # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
443 #endif /* USE_THREADS */
445 /* UNICODE<>ANSI translation helpers */
446 /* Use CP_ACP when mode is ANSI */
447 /* Use CP_UTF8 when mode is UTF8 */
449 #define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
450 (lpw[0] = 0, MultiByteToWideChar((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
451 lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
452 #define A2WHELPER(lpa, lpw, nBytes) A2WHELPER_LEN(lpa, -1, lpw, nBytes)
454 #define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
455 (lpa[0] = '\0', WideCharToMultiByte((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
456 lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
457 #define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
459 #define USING_WIDE() (PL_widesyscalls && PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
462 # define PERL_WAIT_FOR_CHILDREN \
464 if (w32_pseudo_children && w32_num_pseudo_children) { \
465 long children = w32_num_pseudo_children; \
466 WaitForMultipleObjects(children, \
467 w32_pseudo_child_handles, \
470 CloseHandle(w32_pseudo_child_handles[--children]); \
476 * This provides a layer of functions and macros to ensure extensions will
477 * get to use the same RTL functions as the core.
479 #include "win32iop.h"
481 #endif /* _INC_WIN32_PERL5 */