Commit | Line | Data |
e1caacb4 |
1 | // Time-stamp: <01/08/01 20:59:54 keuchel@w2k> |
2 | |
3 | /* WIN32.H |
4 | * |
5 | * (c) 1995 Microsoft Corporation. All rights reserved. |
6 | * Developed by hip communications inc., http://info.hip.com/info/ |
7 | * |
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. |
10 | */ |
11 | |
12 | #ifndef _INC_WIN32_PERL5 |
13 | #define _INC_WIN32_PERL5 |
14 | |
15 | #ifndef _WIN32_WINNT |
16 | # define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */ |
17 | #endif |
18 | |
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 |
28 | # endif |
29 | # define win32_get_privlib PerlEnv_lib_path |
30 | # define win32_get_sitelib PerlEnv_sitelib_path |
31 | # define win32_get_vendorlib PerlEnv_vendorlib_path |
32 | #endif |
33 | |
34 | #ifdef __GNUC__ |
35 | # ifndef __int64 /* some versions seem to #define it already */ |
36 | # define __int64 long long |
37 | # endif |
38 | # define Win32_Winsock |
39 | #endif |
40 | |
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. |
45 | */ |
46 | |
47 | /* now even GCC supports __declspec() */ |
48 | |
49 | #if defined(PERL_OBJECT) |
50 | #define DllExport |
51 | #else |
52 | #if defined(PERLDLL) || defined(WIN95FIX) |
53 | #define DllExport |
54 | /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */ |
55 | #else |
56 | #define DllExport __declspec(dllimport) |
57 | #endif |
58 | #endif |
59 | |
60 | #define WIN32_LEAN_AND_MEAN |
61 | #include <windows.h> |
62 | |
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 */ |
66 | |
67 | #ifndef TLS_OUT_OF_INDEXES |
68 | #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF |
69 | #endif |
70 | |
71 | #include <dirent.h> |
72 | #ifndef UNDER_CE |
73 | #include <io.h> |
74 | #include <process.h> |
75 | #include <direct.h> |
76 | #include <fcntl.h> |
77 | #endif |
78 | #include <stdio.h> |
79 | #include <stdlib.h> |
80 | #ifndef EXT |
81 | #include "EXTERN.h" |
82 | #endif |
83 | |
84 | struct tms { |
85 | long tms_utime; |
86 | long tms_stime; |
87 | long tms_cutime; |
88 | long tms_cstime; |
89 | }; |
90 | |
91 | #ifndef SYS_NMLN |
92 | #define SYS_NMLN 257 |
93 | #endif |
94 | |
95 | struct utsname { |
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]; |
101 | }; |
102 | |
103 | #ifndef START_EXTERN_C |
104 | #undef EXTERN_C |
105 | #ifdef __cplusplus |
106 | # define START_EXTERN_C extern "C" { |
107 | # define END_EXTERN_C } |
108 | # define EXTERN_C extern "C" |
109 | #else |
110 | # define START_EXTERN_C |
111 | # define END_EXTERN_C |
112 | # define EXTERN_C |
113 | #endif |
114 | #endif |
115 | |
116 | #define STANDARD_C 1 |
117 | #define DOSISH 1 /* no escaping our roots */ |
118 | #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */ |
119 | |
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) */ |
122 | |
123 | //#define USE_SOCKETS_AS_HANDLES |
124 | |
125 | /* read() and write() aren't transparent for socket handles */ |
126 | #define PERL_SOCK_SYSREAD_IS_RECV |
127 | #define PERL_SOCK_SYSWRITE_IS_SEND |
128 | |
129 | #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */ |
130 | |
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 */ |
135 | |
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 |
139 | -- BKS 1-24-2000 */ |
140 | #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__) |
141 | #define USE_FIXED_OSFHANDLE |
142 | #endif |
143 | |
144 | #define ENV_IS_CASELESS |
145 | |
146 | #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */ |
147 | #define VER_PLATFORM_WIN32_WINDOWS 1 |
148 | #endif |
149 | |
150 | #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */ |
151 | #define FILE_SHARE_DELETE 0x00000004 |
152 | #endif |
153 | |
154 | /* access() mode bits */ |
155 | #ifndef R_OK |
156 | # define R_OK 4 |
157 | # define W_OK 2 |
158 | # define X_OK 1 |
159 | # define F_OK 0 |
160 | #endif |
161 | |
162 | #define PERL_GET_CONTEXT_DEFINED |
163 | |
164 | /* Compiler-specific stuff. */ |
165 | |
166 | #ifdef __BORLANDC__ /* Borland C++ */ |
167 | |
168 | #define _access access |
169 | #define _chdir chdir |
170 | #define _getpid getpid |
171 | #define wcsicmp _wcsicmp |
172 | #include <sys/types.h> |
173 | |
174 | #ifndef DllMain |
175 | #define DllMain DllEntryPoint |
176 | #endif |
177 | |
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'" */ |
188 | |
189 | /* Borland is picky about a bare member function name used as its ptr */ |
190 | #ifdef PERL_OBJECT |
191 | # define MEMBER_TO_FPTR(name) &(name) |
192 | #endif |
193 | |
194 | /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */ |
195 | #define PERL_MEMBER_PTR_SIZE 12 |
196 | |
197 | #endif |
198 | |
199 | #ifdef _MSC_VER /* Microsoft Visual C++ */ |
200 | |
201 | #ifndef _MODE_T_DEFINED_ |
202 | typedef unsigned long mode_t; |
203 | #define _MODE_T_DEFINED_ |
204 | #endif |
205 | |
206 | #pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761) |
207 | |
208 | /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */ |
209 | #define PERL_MEMBER_PTR_SIZE 16 |
210 | |
211 | #endif /* _MSC_VER */ |
212 | |
213 | #ifdef __MINGW32__ /* Minimal Gnu-Win32 */ |
214 | |
215 | typedef long uid_t; |
216 | typedef long gid_t; |
217 | #ifndef _environ |
218 | #define _environ environ |
219 | #endif |
220 | #define flushall _flushall |
221 | #define fcloseall _fcloseall |
222 | |
223 | #ifdef PERL_OBJECT |
224 | # define MEMBER_TO_FPTR(name) &(name) |
225 | #endif |
226 | |
227 | #ifndef _O_NOINHERIT |
228 | # define _O_NOINHERIT 0x0080 |
229 | # ifndef _NO_OLDNAMES |
230 | # define O_NOINHERIT _O_NOINHERIT |
231 | # endif |
232 | #endif |
233 | |
234 | #endif /* __MINGW32__ */ |
235 | |
236 | /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */ |
237 | #ifndef CP_UTF8 |
238 | # define CP_UTF8 65001 |
239 | #endif |
240 | |
241 | /* compatibility stuff for other compilers goes here */ |
242 | |
243 | |
244 | #if !defined(PERL_OBJECT) && defined(PERL_CAPI) && defined(PERL_MEMBER_PTR_SIZE) |
245 | # define STRUCT_MGVTBL_DEFINITION \ |
246 | struct mgvtbl { \ |
247 | union { \ |
248 | int (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg); \ |
249 | char handle_VC_problem1[PERL_MEMBER_PTR_SIZE]; \ |
250 | }; \ |
251 | union { \ |
252 | int (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg); \ |
253 | char handle_VC_problem2[PERL_MEMBER_PTR_SIZE]; \ |
254 | }; \ |
255 | union { \ |
256 | U32 (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg); \ |
257 | char handle_VC_problem3[PERL_MEMBER_PTR_SIZE]; \ |
258 | }; \ |
259 | union { \ |
260 | int (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg); \ |
261 | char handle_VC_problem4[PERL_MEMBER_PTR_SIZE]; \ |
262 | }; \ |
263 | union { \ |
264 | int (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg); \ |
265 | char handle_VC_problem5[PERL_MEMBER_PTR_SIZE]; \ |
266 | }; \ |
267 | } |
268 | |
269 | # define BASEOP_DEFINITION \ |
270 | OP* op_next; \ |
271 | OP* op_sibling; \ |
272 | OP* (CPERLscope(*op_ppaddr))(pTHX); \ |
273 | char handle_VC_problem[PERL_MEMBER_PTR_SIZE-sizeof(OP*)]; \ |
274 | PADOFFSET op_targ; \ |
275 | OPCODE op_type; \ |
276 | U16 op_seq; \ |
277 | U8 op_flags; \ |
278 | U8 op_private; |
279 | |
280 | #endif /* !PERL_OBJECT && PERL_CAPI && PERL_MEMBER_PTR_SIZE */ |
281 | |
282 | |
283 | START_EXTERN_C |
284 | |
285 | #undef Stat |
286 | #define Stat win32_stat |
287 | |
288 | #undef init_os_extras |
289 | #define init_os_extras Perl_init_os_extras |
290 | |
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); |
295 | |
296 | typedef struct { |
297 | HANDLE childStdIn; |
298 | HANDLE childStdOut; |
299 | HANDLE childStdErr; |
300 | /* |
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; |
307 | */ |
308 | DWORD dwFlags; |
309 | DWORD dwX; |
310 | DWORD dwY; |
311 | DWORD dwXSize; |
312 | DWORD dwYSize; |
313 | DWORD dwXCountChars; |
314 | DWORD dwYCountChars; |
315 | DWORD dwFillAttribute; |
316 | WORD wShowWindow; |
317 | } child_IO_table; |
318 | |
319 | DllExport void win32_get_child_IO(child_IO_table* ptr); |
320 | |
321 | #ifndef USE_SOCKETS_AS_HANDLES |
322 | extern FILE * my_fdopen(int, char *); |
323 | #endif |
324 | |
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); |
335 | |
336 | #ifdef PERL_IMPLICIT_SYS |
337 | extern void win32_delete_internal_host(void *h); |
338 | #endif |
339 | |
340 | extern char * staticlinkmodules[]; |
341 | |
342 | END_EXTERN_C |
343 | |
344 | /* |
345 | * handle socket stuff, assuming socket is always available |
346 | */ |
347 | |
348 | #include <sys/socket.h> |
349 | #include <netdb.h> |
350 | |
351 | #ifdef MYMALLOC |
352 | #define EMBEDMYMALLOC /**/ |
353 | /* #define USE_PERL_SBRK /**/ |
354 | /* #define PERL_SBRK_VIA_MALLOC /**/ |
355 | #endif |
356 | |
357 | #if defined(PERLDLL) && !defined(PERL_CORE) |
358 | #define PERL_CORE |
359 | #endif |
360 | |
361 | #ifdef PERL_TEXTMODE_SCRIPTS |
362 | # define PERL_SCRIPT_MODE "r" |
363 | #else |
364 | # define PERL_SCRIPT_MODE "rb" |
365 | #endif |
366 | |
367 | /* |
368 | * Now Win32 specific per-thread data stuff |
369 | */ |
370 | |
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 |
377 | int Winit_socktype; |
378 | # endif |
379 | # ifdef HAVE_DES_FCRYPT |
380 | char Wcrypt_buffer[30]; |
381 | # endif |
382 | # ifdef USE_RTL_THREAD_API |
383 | void * retv; /* slot for thread return value */ |
384 | # endif |
385 | }; |
386 | |
387 | #ifdef USE_THREADS |
388 | # ifndef USE_DECLSPEC_THREAD |
389 | # define HAVE_THREAD_INTERN |
390 | # endif /* !USE_DECLSPEC_THREAD */ |
391 | #endif /* USE_THREADS */ |
392 | |
393 | #define HAVE_INTERP_INTERN |
394 | typedef struct { |
395 | long num; |
396 | DWORD pids[MAXIMUM_WAIT_OBJECTS]; |
397 | HANDLE handles[MAXIMUM_WAIT_OBJECTS]; |
398 | } child_tab; |
399 | |
400 | struct interp_intern { |
401 | char * perlshell_tokens; |
402 | char ** perlshell_vec; |
403 | long perlshell_items; |
404 | struct av * fdpid; |
405 | child_tab * children; |
406 | #ifdef USE_ITHREADS |
407 | DWORD pseudo_id; |
408 | child_tab * pseudo_children; |
409 | #endif |
410 | void * internal_host; |
411 | #ifndef USE_THREADS |
412 | struct thread_intern thr_intern; |
413 | #endif |
414 | }; |
415 | |
416 | |
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) |
431 | #ifdef USE_THREADS |
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) |
437 | #else |
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 */ |
444 | |
445 | /* UNICODE<>ANSI translation helpers */ |
446 | /* Use CP_ACP when mode is ANSI */ |
447 | /* Use CP_UTF8 when mode is UTF8 */ |
448 | |
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) |
453 | |
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) |
458 | |
459 | #define USING_WIDE() (PL_widesyscalls && PerlEnv_os_id() == VER_PLATFORM_WIN32_NT) |
460 | |
461 | #ifdef USE_ITHREADS |
462 | # define PERL_WAIT_FOR_CHILDREN \ |
463 | STMT_START { \ |
464 | if (w32_pseudo_children && w32_num_pseudo_children) { \ |
465 | long children = w32_num_pseudo_children; \ |
466 | WaitForMultipleObjects(children, \ |
467 | w32_pseudo_child_handles, \ |
468 | TRUE, INFINITE); \ |
469 | while (children) \ |
470 | CloseHandle(w32_pseudo_child_handles[--children]); \ |
471 | } \ |
472 | } STMT_END |
473 | #endif |
474 | |
475 | /* |
476 | * This provides a layer of functions and macros to ensure extensions will |
477 | * get to use the same RTL functions as the core. |
478 | */ |
479 | #include "win32iop.h" |
480 | |
481 | #endif /* _INC_WIN32_PERL5 */ |
482 | |