Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

552 lines
15 KiB

  1. /* WIN32.H
  2. *
  3. * (c) 1995 Microsoft Corporation. All rights reserved.
  4. * Developed by hip communications inc., http://info.hip.com/info/
  5. *
  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.
  8. */
  9. #ifndef _INC_WIN32_PERL5
  10. #define _INC_WIN32_PERL5
  11. #include "BuildInfo.h"
  12. #ifndef _WIN32_WINNT
  13. # define _WIN32_WINNT 0x0400 /* needed for TryEnterCriticalSection() etc. */
  14. #endif
  15. #if defined(PERL_OBJECT) || defined(PERL_IMPLICIT_SYS) || defined(PERL_CAPI)
  16. # define DYNAMIC_ENV_FETCH
  17. # define ENV_HV_NAME "___ENV_HV_NAME___"
  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
  24. # endif
  25. # define win32_get_privlib PerlEnv_lib_path
  26. # define win32_get_sitelib PerlEnv_sitelib_path
  27. # define win32_get_vendorlib PerlEnv_vendorlib_path
  28. #endif
  29. #ifdef __GNUC__
  30. # ifndef __int64 /* some versions seem to #define it already */
  31. # define __int64 long long
  32. # endif
  33. # define Win32_Winsock
  34. #endif
  35. /* Define DllExport akin to perl's EXT,
  36. * If we are in the DLL or mimicing the DLL for Win95 work round
  37. * then Export the symbol,
  38. * otherwise import it.
  39. */
  40. /* now even GCC supports __declspec() */
  41. #if defined(PERL_OBJECT)
  42. #define DllExport
  43. #else
  44. #if defined(PERLDLL) || defined(WIN95FIX)
  45. #define DllExport
  46. /*#define DllExport __declspec(dllexport)*/ /* noises with VC5+sp3 */
  47. #else
  48. #define DllExport __declspec(dllimport)
  49. #endif
  50. #endif
  51. #define WIN32_LEAN_AND_MEAN
  52. #include <windows.h>
  53. #ifdef WIN32_LEAN_AND_MEAN /* C file is NOT a Perl5 original. */
  54. #define CONTEXT PERL_CONTEXT /* Avoid conflict of CONTEXT defs. */
  55. #endif /*WIN32_LEAN_AND_MEAN */
  56. #ifndef TLS_OUT_OF_INDEXES
  57. #define TLS_OUT_OF_INDEXES (DWORD)0xFFFFFFFF
  58. #endif
  59. #include <dirent.h>
  60. #include <io.h>
  61. #include <process.h>
  62. #include <stdio.h>
  63. #include <direct.h>
  64. #include <stdlib.h>
  65. #include <fcntl.h>
  66. #ifndef EXT
  67. #include "EXTERN.h"
  68. #endif
  69. struct tms {
  70. long tms_utime;
  71. long tms_stime;
  72. long tms_cutime;
  73. long tms_cstime;
  74. };
  75. #ifndef SYS_NMLN
  76. #define SYS_NMLN 257
  77. #endif
  78. struct utsname {
  79. char sysname[SYS_NMLN];
  80. char nodename[SYS_NMLN];
  81. char release[SYS_NMLN];
  82. char version[SYS_NMLN];
  83. char machine[SYS_NMLN];
  84. };
  85. #ifndef START_EXTERN_C
  86. #undef EXTERN_C
  87. #ifdef __cplusplus
  88. # define START_EXTERN_C extern "C" {
  89. # define END_EXTERN_C }
  90. # define EXTERN_C extern "C"
  91. #else
  92. # define START_EXTERN_C
  93. # define END_EXTERN_C
  94. # define EXTERN_C
  95. #endif
  96. #endif
  97. #define STANDARD_C 1
  98. #define DOSISH 1 /* no escaping our roots */
  99. #define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
  100. /* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
  101. * real filehandles. XXX Should always be defined (the other version is untested) */
  102. #define USE_SOCKETS_AS_HANDLES
  103. /* read() and write() aren't transparent for socket handles */
  104. #define PERL_SOCK_SYSREAD_IS_RECV
  105. #define PERL_SOCK_SYSWRITE_IS_SEND
  106. #define PERL_NO_FORCE_LINK /* no need for PL_force_link_funcs */
  107. /* Define USE_FIXED_OSFHANDLE to fix MSVCRT's _open_osfhandle() on W95.
  108. It now uses some black magic to work seamlessly with the DLL CRT and
  109. works with MSVC++ 4.0+ or GCC/Mingw32
  110. -- BKS 1-24-2000 */
  111. #if (defined(_M_IX86) && _MSC_VER >= 1000) || defined(__MINGW32__)
  112. #define USE_FIXED_OSFHANDLE
  113. #endif
  114. /* Define PERL_WIN32_SOCK_DLOAD to have Perl dynamically load the winsock
  115. DLL when needed. Don't use if your compiler supports delayloading (ie, VC++ 6.0)
  116. -- BKS 5-29-2000 */
  117. #if !(defined(_M_IX86) && _MSC_VER >= 1200)
  118. #define PERL_WIN32_SOCK_DLOAD
  119. #endif
  120. #define ENV_IS_CASELESS
  121. #ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers don't have this */
  122. #define VER_PLATFORM_WIN32_WINDOWS 1
  123. #endif
  124. #ifndef FILE_SHARE_DELETE /* VC-4.0 headers don't have this */
  125. #define FILE_SHARE_DELETE 0x00000004
  126. #endif
  127. /* access() mode bits */
  128. #ifndef R_OK
  129. # define R_OK 4
  130. # define W_OK 2
  131. # define X_OK 1
  132. # define F_OK 0
  133. #endif
  134. /* for waitpid() */
  135. #ifndef WNOHANG
  136. # define WNOHANG 1
  137. #endif
  138. #define PERL_GET_CONTEXT_DEFINED
  139. /* Compiler-specific stuff. */
  140. #ifdef __BORLANDC__ /* Borland C++ */
  141. #if (__BORLANDC__ <= 0x520)
  142. #define _access access
  143. #define _chdir chdir
  144. #endif
  145. #define _getpid getpid
  146. #define wcsicmp _wcsicmp
  147. #include <sys/types.h>
  148. #ifndef DllMain
  149. #define DllMain DllEntryPoint
  150. #endif
  151. #pragma warn -ccc /* "condition is always true/false" */
  152. #pragma warn -rch /* "unreachable code" */
  153. #pragma warn -sig /* "conversion may lose significant digits" */
  154. #pragma warn -pia /* "possibly incorrect assignment" */
  155. #pragma warn -par /* "parameter 'foo' is never used" */
  156. #pragma warn -aus /* "'foo' is assigned a value that is never used" */
  157. #pragma warn -use /* "'foo' is declared but never used" */
  158. #pragma warn -csu /* "comparing signed and unsigned values" */
  159. /* Borland is picky about a bare member function name used as its ptr */
  160. #ifdef PERL_OBJECT
  161. # define MEMBER_TO_FPTR(name) &(name)
  162. #endif
  163. /* Borland C thinks that a pointer to a member variable is 12 bytes in size. */
  164. #define PERL_MEMBER_PTR_SIZE 12
  165. #define isnan _isnan
  166. #endif
  167. #ifdef _MSC_VER /* Microsoft Visual C++ */
  168. typedef long uid_t;
  169. typedef long gid_t;
  170. typedef unsigned short mode_t;
  171. #pragma warning(disable: 4102) /* "unreferenced label" */
  172. /* Visual C thinks that a pointer to a member variable is 16 bytes in size. */
  173. #define PERL_MEMBER_PTR_SIZE 16
  174. #define isnan _isnan
  175. #endif /* _MSC_VER */
  176. #ifdef __MINGW32__ /* Minimal Gnu-Win32 */
  177. typedef long uid_t;
  178. typedef long gid_t;
  179. #ifndef _environ
  180. #define _environ environ
  181. #endif
  182. #define flushall _flushall
  183. #define fcloseall _fcloseall
  184. #define isnan _isnan /* ...same libraries as MSVC */
  185. #ifdef PERL_OBJECT
  186. # define MEMBER_TO_FPTR(name) &(name)
  187. #endif
  188. #ifndef _O_NOINHERIT
  189. # define _O_NOINHERIT 0x0080
  190. # ifndef _NO_OLDNAMES
  191. # define O_NOINHERIT _O_NOINHERIT
  192. # endif
  193. #endif
  194. #endif /* __MINGW32__ */
  195. /* both GCC/Mingw32 and MSVC++ 4.0 are missing this, so we put it here */
  196. #ifndef CP_UTF8
  197. # define CP_UTF8 65001
  198. #endif
  199. /* compatibility stuff for other compilers goes here */
  200. #if !defined(PERL_OBJECT) && defined(PERL_CAPI) && defined(PERL_MEMBER_PTR_SIZE)
  201. # define STRUCT_MGVTBL_DEFINITION \
  202. struct mgvtbl { \
  203. union { \
  204. int (CPERLscope(*svt_get))(pTHX_ SV *sv, MAGIC* mg); \
  205. char handle_VC_problem1[PERL_MEMBER_PTR_SIZE]; \
  206. }; \
  207. union { \
  208. int (CPERLscope(*svt_set))(pTHX_ SV *sv, MAGIC* mg); \
  209. char handle_VC_problem2[PERL_MEMBER_PTR_SIZE]; \
  210. }; \
  211. union { \
  212. U32 (CPERLscope(*svt_len))(pTHX_ SV *sv, MAGIC* mg); \
  213. char handle_VC_problem3[PERL_MEMBER_PTR_SIZE]; \
  214. }; \
  215. union { \
  216. int (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg); \
  217. char handle_VC_problem4[PERL_MEMBER_PTR_SIZE]; \
  218. }; \
  219. union { \
  220. int (CPERLscope(*svt_free))(pTHX_ SV *sv, MAGIC* mg); \
  221. char handle_VC_problem5[PERL_MEMBER_PTR_SIZE]; \
  222. }; \
  223. }
  224. # define BASEOP_DEFINITION \
  225. OP* op_next; \
  226. OP* op_sibling; \
  227. OP* (CPERLscope(*op_ppaddr))(pTHX); \
  228. char handle_VC_problem[PERL_MEMBER_PTR_SIZE-sizeof(OP*)]; \
  229. PADOFFSET op_targ; \
  230. OPCODE op_type; \
  231. U16 op_seq; \
  232. U8 op_flags; \
  233. U8 op_private;
  234. #endif /* !PERL_OBJECT && PERL_CAPI && PERL_MEMBER_PTR_SIZE */
  235. START_EXTERN_C
  236. /* For UNIX compatibility. */
  237. extern uid_t getuid(void);
  238. extern gid_t getgid(void);
  239. extern uid_t geteuid(void);
  240. extern gid_t getegid(void);
  241. extern int setuid(uid_t uid);
  242. extern int setgid(gid_t gid);
  243. extern int kill(int pid, int sig);
  244. extern void *sbrk(int need);
  245. extern char * getlogin(void);
  246. extern int chown(const char *p, uid_t o, gid_t g);
  247. #undef Stat
  248. #define Stat win32_stat
  249. #undef init_os_extras
  250. #define init_os_extras Perl_init_os_extras
  251. DllExport void Perl_win32_init(int *argcp, char ***argvp);
  252. DllExport void Perl_init_os_extras(void);
  253. DllExport void win32_str_os_error(void *sv, DWORD err);
  254. DllExport int RunPerl(int argc, char **argv, char **env);
  255. typedef struct {
  256. HANDLE childStdIn;
  257. HANDLE childStdOut;
  258. HANDLE childStdErr;
  259. /*
  260. * the following correspond to the fields of the same name
  261. * in the STARTUPINFO structure. Embedders can use these to
  262. * control the spawning process' look.
  263. * Example - to hide the window of the spawned process:
  264. * dwFlags = STARTF_USESHOWWINDOW;
  265. * wShowWindow = SW_HIDE;
  266. */
  267. DWORD dwFlags;
  268. DWORD dwX;
  269. DWORD dwY;
  270. DWORD dwXSize;
  271. DWORD dwYSize;
  272. DWORD dwXCountChars;
  273. DWORD dwYCountChars;
  274. DWORD dwFillAttribute;
  275. WORD wShowWindow;
  276. } child_IO_table;
  277. DllExport void win32_get_child_IO(child_IO_table* ptr);
  278. #ifndef USE_SOCKETS_AS_HANDLES
  279. extern FILE * my_fdopen(int, char *);
  280. #endif
  281. extern int my_fclose(FILE *);
  282. extern int my_fstat(int fd, struct stat *sbufptr);
  283. extern char * win32_get_privlib(const char *pl);
  284. extern char * win32_get_sitelib(const char *pl);
  285. extern char * win32_get_vendorlib(const char *pl);
  286. extern int IsWin95(void);
  287. extern int IsWinNT(void);
  288. extern void win32_argv2utf8(int argc, char** argv);
  289. #ifdef PERL_IMPLICIT_SYS
  290. extern void win32_delete_internal_host(void *h);
  291. #endif
  292. extern char * staticlinkmodules[];
  293. END_EXTERN_C
  294. typedef char * caddr_t; /* In malloc.c (core address). */
  295. /*
  296. * handle socket stuff, assuming socket is always available
  297. */
  298. #include <sys/socket.h>
  299. #include <netdb.h>
  300. #ifdef MYMALLOC
  301. #define EMBEDMYMALLOC /**/
  302. /* #define USE_PERL_SBRK /**/
  303. /* #define PERL_SBRK_VIA_MALLOC /**/
  304. #endif
  305. #if defined(PERLDLL) && !defined(PERL_CORE)
  306. #define PERL_CORE
  307. #endif
  308. #ifdef PERL_TEXTMODE_SCRIPTS
  309. # define PERL_SCRIPT_MODE "r"
  310. #else
  311. # define PERL_SCRIPT_MODE "rb"
  312. #endif
  313. /*
  314. * Now Win32 specific per-thread data stuff
  315. */
  316. struct thread_intern {
  317. /* XXX can probably use one buffer instead of several */
  318. char Wstrerror_buffer[512];
  319. struct servent Wservent;
  320. char Wgetlogin_buffer[128];
  321. # ifdef USE_SOCKETS_AS_HANDLES
  322. int Winit_socktype;
  323. # endif
  324. # ifdef HAVE_DES_FCRYPT
  325. char Wcrypt_buffer[30];
  326. # endif
  327. # ifdef USE_RTL_THREAD_API
  328. void * retv; /* slot for thread return value */
  329. # endif
  330. };
  331. #ifdef USE_THREADS
  332. # ifndef USE_DECLSPEC_THREAD
  333. # define HAVE_THREAD_INTERN
  334. # endif /* !USE_DECLSPEC_THREAD */
  335. #endif /* USE_THREADS */
  336. #define HAVE_INTERP_INTERN
  337. typedef struct {
  338. long num;
  339. DWORD pids[MAXIMUM_WAIT_OBJECTS];
  340. HANDLE handles[MAXIMUM_WAIT_OBJECTS];
  341. } child_tab;
  342. struct interp_intern {
  343. char * perlshell_tokens;
  344. char ** perlshell_vec;
  345. long perlshell_items;
  346. struct av * fdpid;
  347. child_tab * children;
  348. #if defined(USE_ITHREADS) || defined(PERL_OBJECT)
  349. DWORD pseudo_id;
  350. child_tab * pseudo_children;
  351. #endif
  352. void * internal_host;
  353. #ifndef USE_THREADS
  354. struct thread_intern thr_intern;
  355. #endif
  356. };
  357. #define w32_perlshell_tokens (PL_sys_intern.perlshell_tokens)
  358. #define w32_perlshell_vec (PL_sys_intern.perlshell_vec)
  359. #define w32_perlshell_items (PL_sys_intern.perlshell_items)
  360. #define w32_fdpid (PL_sys_intern.fdpid)
  361. #define w32_children (PL_sys_intern.children)
  362. #define w32_num_children (w32_children->num)
  363. #define w32_child_pids (w32_children->pids)
  364. #define w32_child_handles (w32_children->handles)
  365. #define w32_pseudo_id (PL_sys_intern.pseudo_id)
  366. #define w32_pseudo_children (PL_sys_intern.pseudo_children)
  367. #define w32_num_pseudo_children (w32_pseudo_children->num)
  368. #define w32_pseudo_child_pids (w32_pseudo_children->pids)
  369. #define w32_pseudo_child_handles (w32_pseudo_children->handles)
  370. #define w32_internal_host (PL_sys_intern.internal_host)
  371. #ifdef USE_THREADS
  372. # define w32_strerror_buffer (thr->i.Wstrerror_buffer)
  373. # define w32_getlogin_buffer (thr->i.Wgetlogin_buffer)
  374. # define w32_crypt_buffer (thr->i.Wcrypt_buffer)
  375. # define w32_servent (thr->i.Wservent)
  376. # define w32_init_socktype (thr->i.Winit_socktype)
  377. #else
  378. # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer)
  379. # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer)
  380. # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer)
  381. # define w32_servent (PL_sys_intern.thr_intern.Wservent)
  382. # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype)
  383. #endif /* USE_THREADS */
  384. /* UNICODE<>ANSI translation helpers */
  385. /* Use CP_ACP when mode is ANSI */
  386. /* Use CP_UTF8 when mode is UTF8 */
  387. #define A2WHELPER_LEN(lpa, alen, lpw, nBytes)\
  388. (lpw[0] = 0, MultiByteToWideChar((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
  389. lpa, alen, lpw, (nBytes/sizeof(WCHAR))))
  390. #define A2WHELPER(lpa, lpw, nBytes) A2WHELPER_LEN(lpa, -1, lpw, nBytes)
  391. #define W2AHELPER_LEN(lpw, wlen, lpa, nChars)\
  392. (lpa[0] = '\0', WideCharToMultiByte((IN_BYTE) ? CP_ACP : CP_UTF8, 0, \
  393. lpw, wlen, (LPSTR)lpa, nChars,NULL,NULL))
  394. #define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
  395. #define USING_WIDE() (PL_widesyscalls && PerlEnv_os_id() == VER_PLATFORM_WIN32_NT)
  396. #ifdef USE_ITHREADS
  397. # define PERL_WAIT_FOR_CHILDREN \
  398. STMT_START { \
  399. if (w32_pseudo_children && w32_num_pseudo_children) { \
  400. long children = w32_num_pseudo_children; \
  401. WaitForMultipleObjects(children, \
  402. w32_pseudo_child_handles, \
  403. TRUE, INFINITE); \
  404. while (children) \
  405. CloseHandle(w32_pseudo_child_handles[--children]); \
  406. } \
  407. } STMT_END
  408. #endif
  409. #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
  410. #ifdef PERL_CORE
  411. /* C doesn't like repeat struct definitions */
  412. #ifndef _CRTIMP
  413. #define _CRTIMP __declspec(dllimport)
  414. #endif
  415. /*
  416. * Control structure for lowio file handles
  417. */
  418. typedef struct {
  419. long osfhnd; /* underlying OS file HANDLE */
  420. char osfile; /* attributes of file (e.g., open in text mode?) */
  421. char pipech; /* one char buffer for handles opened on pipes */
  422. int lockinitflag;
  423. CRITICAL_SECTION lock;
  424. } ioinfo;
  425. /*
  426. * Array of arrays of control structures for lowio files.
  427. */
  428. EXTERN_C _CRTIMP ioinfo* __pioinfo[];
  429. /*
  430. * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
  431. * array of ioinfo structs.
  432. */
  433. #define IOINFO_L2E 5
  434. /*
  435. * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
  436. */
  437. #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
  438. /*
  439. * Access macros for getting at an ioinfo struct and its fields from a
  440. * file handle
  441. */
  442. #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
  443. #define _osfhnd(i) (_pioinfo(i)->osfhnd)
  444. #define _osfile(i) (_pioinfo(i)->osfile)
  445. #define _pipech(i) (_pioinfo(i)->pipech)
  446. /* since we are not doing a dup2(), this works fine */
  447. #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = (long)osfh)
  448. #endif
  449. #endif
  450. /*
  451. * This provides a layer of functions and macros to ensure extensions will
  452. * get to use the same RTL functions as the core.
  453. */
  454. #include "win32iop.h"
  455. #define EXEC_ARGV_CAST(x) ((const char *const *) x)
  456. #endif /* _INC_WIN32_PERL5 */