1 /* WINCE.C - stuff for Windows CE
3 * Time-stamp: <26/10/01 15:25:20 keuchel@keuchelnt>
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 #define WIN32_LEAN_AND_MEAN
10 #define WIN32IO_IS_STDIO
14 #define PERLIO_NOT_STDIO 0
16 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
27 #define PERL_NO_GET_CONTEXT
37 #include "celib_defs.h"
40 #include "cewin32_defs.h"
41 #include "cecrt_defs.h"
44 #include "stdio-palmsize.h"
49 #define EXECF_SPAWN_NOWAIT 3
51 #if defined(PERL_IMPLICIT_SYS)
52 # undef win32_get_privlib
53 # define win32_get_privlib g_win32_get_privlib
54 # undef win32_get_sitelib
55 # define win32_get_sitelib g_win32_get_sitelib
56 # undef win32_get_vendorlib
57 # define win32_get_vendorlib g_win32_get_vendorlib
59 # define do_spawn g_do_spawn
61 # define getlogin g_getlogin
64 static long filetime_to_clock(PFILETIME ft);
65 static BOOL filetime_from_time(PFILETIME ft, time_t t);
66 static char * get_emd_part(SV **leading, char *trailing, ...);
67 static char * win32_get_xlib(const char *pl, const char *xlib,
71 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
72 char w32_module_name[MAX_PATH+1];
75 static DWORD w32_platform = (DWORD)-1;
80 return (win32_os_id() == VER_PLATFORM_WIN32_WINDOWS);
86 return (win32_os_id() == VER_PLATFORM_WIN32_NT);
92 return (win32_os_id() == VER_PLATFORM_WIN32_CE);
96 set_w32_module_name(void)
99 XCEGetModuleFileNameA((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE)
100 ? XCEGetModuleHandleA(NULL)
101 : w32_perldll_handle),
102 w32_module_name, sizeof(w32_module_name));
104 /* normalize to forward slashes */
105 ptr = w32_module_name;
113 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
115 get_regstr_from(HKEY hkey, const char *valuename, SV **svp)
117 /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
120 const char *subkey = "Software\\Perl";
124 retval = XCERegOpenKeyExA(hkey, subkey, 0, KEY_READ, &handle);
125 if (retval == ERROR_SUCCESS) {
127 retval = XCERegQueryValueExA(handle, valuename, 0, &type, NULL, &datalen);
128 if (retval == ERROR_SUCCESS && type == REG_SZ) {
131 *svp = sv_2mortal(newSVpvn("",0));
132 SvGROW(*svp, datalen);
133 retval = XCERegQueryValueExA(handle, valuename, 0, NULL,
134 (PBYTE)SvPVX(*svp), &datalen);
135 if (retval == ERROR_SUCCESS) {
137 SvCUR_set(*svp,datalen-1);
145 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
147 get_regstr(const char *valuename, SV **svp)
149 char *str = get_regstr_from(HKEY_CURRENT_USER, valuename, svp);
151 str = get_regstr_from(HKEY_LOCAL_MACHINE, valuename, svp);
155 /* *prev_pathp (if non-NULL) is expected to be POK (valid allocated SvPVX(sv)) */
157 get_emd_part(SV **prev_pathp, char *trailing_path, ...)
161 char mod_name[MAX_PATH+1];
165 int oldsize, newsize;
168 va_start(ap, trailing_path);
169 strip = va_arg(ap, char *);
171 sprintf(base, "%d.%d", (int)PERL_REVISION, (int)PERL_VERSION);
172 baselen = strlen(base);
174 if (!*w32_module_name) {
175 set_w32_module_name();
177 strcpy(mod_name, w32_module_name);
178 ptr = strrchr(mod_name, '/');
179 while (ptr && strip) {
180 /* look for directories to skip back */
183 ptr = strrchr(mod_name, '/');
184 /* avoid stripping component if there is no slash,
185 * or it doesn't match ... */
186 if (!ptr || stricmp(ptr+1, strip) != 0) {
187 /* ... but not if component matches m|5\.$patchlevel.*| */
188 if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
189 && strncmp(strip, base, baselen) == 0
190 && strncmp(ptr+1, base, baselen) == 0))
196 strip = va_arg(ap, char *);
204 strcpy(++ptr, trailing_path);
206 /* only add directory if it exists */
207 if (XCEGetFileAttributesA(mod_name) != (DWORD) -1) {
208 /* directory exists */
211 *prev_pathp = sv_2mortal(newSVpvn("",0));
212 sv_catpvn(*prev_pathp, ";", 1);
213 sv_catpv(*prev_pathp, mod_name);
214 return SvPVX(*prev_pathp);
221 win32_get_privlib(const char *pl)
224 char *stdlib = "lib";
225 char buffer[MAX_PATH+1];
228 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
229 sprintf(buffer, "%s-%s", stdlib, pl);
230 if (!get_regstr(buffer, &sv))
231 (void)get_regstr(stdlib, &sv);
233 /* $stdlib .= ";$EMD/../../lib" */
234 return get_emd_part(&sv, stdlib, ARCHNAME, "bin", Nullch);
238 win32_get_xlib(const char *pl, const char *xlib, const char *libname)
242 char pathstr[MAX_PATH+1];
248 /* $HKCU{"$xlib-$]"} || $HKLM{"$xlib-$]"} . ---; */
249 sprintf(regstr, "%s-%s", xlib, pl);
250 (void)get_regstr(regstr, &sv1);
253 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/$]/lib"; */
254 sprintf(pathstr, "%s/%s/lib", libname, pl);
255 (void)get_emd_part(&sv1, pathstr, ARCHNAME, "bin", pl, Nullch);
257 /* $HKCU{$xlib} || $HKLM{$xlib} . ---; */
258 (void)get_regstr(xlib, &sv2);
261 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/lib"; */
262 sprintf(pathstr, "%s/lib", libname);
263 (void)get_emd_part(&sv2, pathstr, ARCHNAME, "bin", pl, Nullch);
272 sv_catpvn(sv1, ";", 1);
279 win32_get_sitelib(const char *pl)
281 return win32_get_xlib(pl, "sitelib", "site");
284 #ifndef PERL_VENDORLIB_NAME
285 # define PERL_VENDORLIB_NAME "vendor"
289 win32_get_vendorlib(const char *pl)
291 return win32_get_xlib(pl, "vendorlib", PERL_VENDORLIB_NAME);
294 #if !defined(PERL_IMPLICIT_SYS)
295 /* since the current process environment is being updated in util.c
296 * the library functions will get the correct environment
299 Perl_my_popen(pTHX_ char *cmd, char *mode)
301 printf("popen(%s)\n", cmd);
303 Perl_croak(aTHX_ PL_no_func, "popen");
308 Perl_my_pclose(pTHX_ PerlIO *fp)
310 Perl_croak(aTHX_ PL_no_func, "pclose");
315 DllExport unsigned long
318 static OSVERSIONINFOA osver;
320 if (osver.dwPlatformId != w32_platform) {
321 memset(&osver, 0, sizeof(OSVERSIONINFOA));
322 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
323 XCEGetVersionExA(&osver);
324 w32_platform = osver.dwPlatformId;
326 return (unsigned long)w32_platform;
336 Perl_do_exec(pTHX_ char *cmd)
338 Perl_croak_nocontext("exec() unimplemented on this platform");
343 win32_pipe(int *pfd, unsigned int size, int mode)
346 Perl_croak(aTHX_ PL_no_func, "pipe");
351 win32_times(struct tms *timebuf)
354 Perl_croak(aTHX_ PL_no_func, "times");
360 win32_signal(int sig, Sighandler_t subcode)
363 Perl_croak_nocontext("signal() TBD on this platform");
381 win32_opendir(char *filename)
383 return opendir(filename);
386 DllExport struct direct *
387 win32_readdir(DIR *dirp)
389 return readdir(dirp);
393 win32_telldir(DIR *dirp)
396 Perl_croak(aTHX_ PL_no_func, "telldir");
401 win32_seekdir(DIR *dirp, long loc)
404 Perl_croak(aTHX_ PL_no_func, "seekdir");
408 win32_rewinddir(DIR *dirp)
411 Perl_croak(aTHX_ PL_no_func, "rewinddir");
415 win32_closedir(DIR *dirp)
422 win32_kill(int pid, int sig)
425 Perl_croak(aTHX_ PL_no_func, "kill");
429 DllExport unsigned int
430 win32_sleep(unsigned int t)
436 win32_stat(const char *path, struct stat *sbuf)
438 return xcestat(path, sbuf);
442 win32_longpath(char *path)
447 #ifndef USE_WIN32_RTL_ENV
450 win32_getenv(const char *name)
452 return xcegetenv(name);
456 win32_putenv(const char *name)
458 return xceputenv(name);
464 filetime_to_clock(PFILETIME ft)
466 __int64 qw = ft->dwHighDateTime;
468 qw |= ft->dwLowDateTime;
469 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
473 /* fix utime() so it works on directories in NT */
475 filetime_from_time(PFILETIME pFileTime, time_t Time)
477 struct tm *pTM = localtime(&Time);
478 SYSTEMTIME SystemTime;
484 SystemTime.wYear = pTM->tm_year + 1900;
485 SystemTime.wMonth = pTM->tm_mon + 1;
486 SystemTime.wDay = pTM->tm_mday;
487 SystemTime.wHour = pTM->tm_hour;
488 SystemTime.wMinute = pTM->tm_min;
489 SystemTime.wSecond = pTM->tm_sec;
490 SystemTime.wMilliseconds = 0;
492 return SystemTimeToFileTime(&SystemTime, &LocalTime) &&
493 LocalFileTimeToFileTime(&LocalTime, pFileTime);
497 win32_unlink(const char *filename)
499 return xceunlink(filename);
503 win32_utime(const char *filename, struct utimbuf *times)
505 return xceutime(filename, (struct _utimbuf *) times);
509 win32_gettimeofday(struct timeval *tp, void *not_used)
511 return xcegettimeofday(tp,not_used);
515 win32_uname(struct utsname *name)
518 STRLEN nodemax = sizeof(name->nodename)-1;
519 OSVERSIONINFOA osver;
521 memset(&osver, 0, sizeof(OSVERSIONINFOA));
522 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
523 if (XCEGetVersionExA(&osver)) {
525 switch (osver.dwPlatformId) {
526 case VER_PLATFORM_WIN32_CE:
527 strcpy(name->sysname, "Windows CE");
529 case VER_PLATFORM_WIN32_WINDOWS:
530 strcpy(name->sysname, "Windows");
532 case VER_PLATFORM_WIN32_NT:
533 strcpy(name->sysname, "Windows NT");
535 case VER_PLATFORM_WIN32s:
536 strcpy(name->sysname, "Win32s");
539 strcpy(name->sysname, "Win32 Unknown");
544 sprintf(name->release, "%d.%d",
545 osver.dwMajorVersion, osver.dwMinorVersion);
548 sprintf(name->version, "Build %d",
549 osver.dwPlatformId == VER_PLATFORM_WIN32_NT
550 ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
551 if (osver.szCSDVersion[0]) {
552 char *buf = name->version + strlen(name->version);
553 sprintf(buf, " (%s)", osver.szCSDVersion);
557 *name->sysname = '\0';
558 *name->version = '\0';
559 *name->release = '\0';
563 hep = win32_gethostbyname("localhost");
565 STRLEN len = strlen(hep->h_name);
566 if (len <= nodemax) {
567 strcpy(name->nodename, hep->h_name);
570 strncpy(name->nodename, hep->h_name, nodemax);
571 name->nodename[nodemax] = '\0';
576 if (!XCEGetComputerNameA(name->nodename, &sz))
577 *name->nodename = '\0';
580 /* machine (architecture) */
584 GetSystemInfo(&info);
586 switch (info.wProcessorArchitecture) {
587 case PROCESSOR_ARCHITECTURE_INTEL:
589 case PROCESSOR_ARCHITECTURE_MIPS:
590 arch = "mips"; break;
591 case PROCESSOR_ARCHITECTURE_ALPHA:
592 arch = "alpha"; break;
593 case PROCESSOR_ARCHITECTURE_PPC:
595 case PROCESSOR_ARCHITECTURE_ARM:
597 case PROCESSOR_HITACHI_SH3:
599 case PROCESSOR_SHx_SH3:
603 arch = "unknown"; break;
605 strcpy(name->machine, arch);
611 sig_terminate(pTHX_ int sig)
613 Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[sig], sig);
614 /* exit() seems to be safe, my_exit() or die() is a problem in ^C
621 win32_async_check(pTHX)
625 /* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMessage() messages
626 * and ignores window messages - should co-exist better with windows apps e.g. Tk
628 while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) {
630 switch(msg.message) {
633 /* Perhaps some other messages could map to signals ? ... */
636 /* Treat WM_QUIT like SIGHUP? */
642 /* We use WM_USER to fake kill() with other signals */
646 if (do_raise(aTHX_ sig)) {
647 sig_terminate(aTHX_ sig);
653 /* alarm() is a one-shot but SetTimer() repeats so kill it */
655 KillTimer(NULL,w32_timerid);
658 /* Now fake a call to signal handler */
659 if (do_raise(aTHX_ 14)) {
660 sig_terminate(aTHX_ 14);
665 /* Otherwise do normal Win32 thing - in case it is useful */
667 TranslateMessage(&msg);
668 DispatchMessage(&msg);
675 /* Above or other stuff may have set a signal flag */
676 if (PL_sig_pending) {
682 /* This function will not return until the timeout has elapsed, or until
683 * one of the handles is ready. */
685 win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD resultp)
687 /* We may need several goes at this - so compute when we stop */
689 if (timeout != INFINITE) {
690 ticks = GetTickCount();
694 DWORD result = MsgWaitForMultipleObjects(count,handles,FALSE,timeout-ticks, QS_ALLEVENTS);
697 if (result == WAIT_TIMEOUT) {
698 /* Ran out of time - explicit return of zero to avoid -ve if we
699 have scheduling issues
703 if (timeout != INFINITE) {
704 ticks = GetTickCount();
706 if (result == WAIT_OBJECT_0 + count) {
707 /* Message has arrived - check it */
708 (void)win32_async_check(aTHX);
711 /* Not timeout or message - one of handles is ready */
715 /* compute time left to wait */
716 ticks = timeout - ticks;
717 /* If we are past the end say zero */
718 return (ticks > 0) ? ticks : 0;
721 /* Timing related stuff */
724 do_raise(pTHX_ int sig)
726 if (sig < SIG_SIZE) {
727 Sighandler_t handler = w32_sighandler[sig];
728 if (handler == SIG_IGN) {
731 else if (handler != SIG_DFL) {
736 /* Choose correct default behaviour */
752 /* Tell caller to exit thread/process as approriate */
756 static UINT timerid = 0;
758 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
761 KillTimer(NULL,timerid);
766 DllExport unsigned int
767 win32_alarm(unsigned int sec)
770 * the 'obvious' implentation is SetTimer() with a callback
771 * which does whatever receiving SIGALRM would do
772 * we cannot use SIGALRM even via raise() as it is not
773 * one of the supported codes in <signal.h>
775 * Snag is unless something is looking at the message queue
776 * nothing happens :-(
781 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
783 Perl_croak_nocontext("Cannot set timer");
789 KillTimer(NULL,timerid);
796 #ifdef HAVE_DES_FCRYPT
797 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
801 win32_crypt(const char *txt, const char *salt)
804 #ifdef HAVE_DES_FCRYPT
806 return des_fcrypt(txt, salt, w32_crypt_buffer);
808 Perl_croak(aTHX_ "The crypt() function is unimplemented due to excessive paranoia.");
813 /* C doesn't like repeat struct definitions */
815 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
818 #define _CRTIMP __declspec(dllimport)
822 * Control structure for lowio file handles
825 long osfhnd; /* underlying OS file HANDLE */
826 char osfile; /* attributes of file (e.g., open in text mode?) */
827 char pipech; /* one char buffer for handles opened on pipes */
829 CRITICAL_SECTION lock;
834 * Array of arrays of control structures for lowio files.
836 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
839 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
840 * array of ioinfo structs.
845 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
847 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
850 * Access macros for getting at an ioinfo struct and its fields from a
853 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
854 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
855 #define _osfile(i) (_pioinfo(i)->osfile)
856 #define _pipech(i) (_pioinfo(i)->pipech)
861 * redirected io subsystem for all XS modules
871 /* the rest are the remapped stdio routines */
879 return "no-getlogin";
895 win32_ferror(FILE *fp)
908 * Since the errors returned by the socket error function
909 * WSAGetLastError() are not known by the library routine strerror
910 * we have to roll our own.
914 win32_strerror(int e)
916 return xcestrerror(e);
920 win32_str_os_error(void *sv, DWORD dwErr)
924 sv_setpvn((SV*)sv, "Error", 5);
929 win32_fprintf(FILE *fp, const char *format, ...)
932 va_start(marker, format); /* Initialize variable arguments. */
934 return (vfprintf(fp, format, marker));
938 win32_printf(const char *format, ...)
941 va_start(marker, format); /* Initialize variable arguments. */
943 return (vprintf(format, marker));
947 win32_vfprintf(FILE *fp, const char *format, va_list args)
949 return (vfprintf(fp, format, args));
953 win32_vprintf(const char *format, va_list args)
955 return (vprintf(format, args));
959 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
961 return fread(buf, size, count, fp);
965 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
967 return fwrite(buf, size, count, fp);
971 win32_fopen(const char *filename, const char *mode)
973 return xcefopen(filename, mode);
977 win32_fdopen(int handle, const char *mode)
979 return palm_fdopen(handle, mode);
983 win32_freopen(const char *path, const char *mode, FILE *stream)
985 return xcefreopen(path, mode, stream);
989 win32_fclose(FILE *pf)
991 return xcefclose(pf);
995 win32_fputs(const char *s,FILE *pf)
1001 win32_fputc(int c,FILE *pf)
1007 win32_ungetc(int c,FILE *pf)
1009 return ungetc(c,pf);
1013 win32_getc(FILE *pf)
1019 win32_fileno(FILE *pf)
1021 return palm_fileno(pf);
1025 win32_clearerr(FILE *pf)
1032 win32_fflush(FILE *pf)
1038 win32_ftell(FILE *pf)
1044 win32_fseek(FILE *pf,long offset,int origin)
1046 return fseek(pf, offset, origin);
1049 /* fpos_t seems to be int64 on hpc pro! Really stupid. */
1050 /* But maybe someday there will be such large disks in a hpc... */
1052 win32_fgetpos(FILE *pf, fpos_t *p)
1054 return fgetpos(pf, p);
1058 win32_fsetpos(FILE *pf, const fpos_t *p)
1060 return fsetpos(pf, p);
1064 win32_rewind(FILE *pf)
1066 fseek(pf, 0, SEEK_SET);
1074 char prefix[MAX_PATH+1];
1075 char filename[MAX_PATH+1];
1076 DWORD len = GetTempPath(MAX_PATH, prefix);
1077 if (len && len < MAX_PATH) {
1078 if (GetTempFileName(prefix, "plx", 0, filename)) {
1079 HANDLE fh = CreateFile(filename,
1080 DELETE | GENERIC_READ | GENERIC_WRITE,
1084 FILE_ATTRIBUTE_NORMAL
1085 | FILE_FLAG_DELETE_ON_CLOSE,
1087 if (fh != INVALID_HANDLE_VALUE) {
1088 int fd = win32_open_osfhandle((intptr_t)fh, 0);
1090 #if defined(__BORLANDC__)
1091 setmode(fd,O_BINARY);
1093 DEBUG_p(PerlIO_printf(Perl_debug_log,
1094 "Created tmpfile=%s\n",filename));
1106 int fd = win32_tmpfd();
1108 return win32_fdopen(fd, "w+b");
1121 win32_fstat(int fd, struct stat *sbufptr)
1123 return xcefstat(fd, sbufptr);
1127 win32_link(const char *oldname, const char *newname)
1130 Perl_croak(aTHX_ PL_no_func, "link");
1136 win32_rename(const char *oname, const char *newname)
1138 return xcerename(oname, newname);
1142 win32_setmode(int fd, int mode)
1144 /* currently 'celib' seem to have this function in src, but not
1145 * exported. When it will be, we'll uncomment following line.
1147 /* return xcesetmode(fd, mode); */
1152 win32_chsize(int fd, Off_t size)
1154 return chsize(fd, size);
1158 win32_lseek(int fd, long offset, int origin)
1160 return xcelseek(fd, offset, origin);
1166 return xcelseek(fd, 0, SEEK_CUR);
1170 win32_open(const char *path, int flag, ...)
1176 pmode = va_arg(ap, int);
1179 return xceopen(path, flag, pmode);
1185 return xceclose(fd);
1192 Perl_croak(aTHX_ PL_no_func, "eof");
1199 return xcedup(fd); /* from celib/ceio.c; requires some more work on it */
1203 win32_dup2(int fd1,int fd2)
1205 return xcedup2(fd1,fd2);
1209 win32_read(int fd, void *buf, unsigned int cnt)
1211 return xceread(fd, buf, cnt);
1215 win32_write(int fd, const void *buf, unsigned int cnt)
1217 return xcewrite(fd, (void *) buf, cnt);
1221 win32_mkdir(const char *dir, int mode)
1223 return xcemkdir(dir);
1227 win32_rmdir(const char *dir)
1229 return xcermdir(dir);
1233 win32_chdir(const char *dir)
1235 return xcechdir(dir);
1239 win32_access(const char *path, int mode)
1241 return xceaccess(path, mode);
1245 win32_chmod(const char *path, int mode)
1247 return xcechmod(path, mode);
1251 win32_perror(const char *str)
1257 win32_setbuf(FILE *pf, char *buf)
1260 Perl_croak(aTHX_ PL_no_func, "setbuf");
1264 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1266 return setvbuf(pf, buf, type, size);
1270 win32_flushall(void)
1276 win32_fcloseall(void)
1282 win32_fgets(char *s, int n, FILE *pf)
1284 return fgets(s, n, pf);
1294 win32_fgetc(FILE *pf)
1300 win32_putc(int c, FILE *pf)
1306 win32_puts(const char *s)
1318 win32_putchar(int c)
1325 #ifndef USE_PERL_SBRK
1327 static char *committed = NULL;
1328 static char *base = NULL;
1329 static char *reserved = NULL;
1330 static char *brk = NULL;
1331 static DWORD pagesize = 0;
1332 static DWORD allocsize = 0;
1340 GetSystemInfo(&info);
1341 /* Pretend page size is larger so we don't perpetually
1342 * call the OS to commit just one page ...
1344 pagesize = info.dwPageSize << 3;
1345 allocsize = info.dwAllocationGranularity;
1347 /* This scheme fails eventually if request for contiguous
1348 * block is denied so reserve big blocks - this is only
1349 * address space not memory ...
1351 if (brk+need >= reserved)
1353 DWORD size = 64*1024*1024;
1355 if (committed && reserved && committed < reserved)
1357 /* Commit last of previous chunk cannot span allocations */
1358 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
1360 committed = reserved;
1362 /* Reserve some (more) space
1363 * Note this is a little sneaky, 1st call passes NULL as reserved
1364 * so lets system choose where we start, subsequent calls pass
1365 * the old end address so ask for a contiguous block
1367 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
1370 reserved = addr+size;
1385 if (brk > committed)
1387 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
1388 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
1403 win32_malloc(size_t size)
1405 return malloc(size);
1409 win32_calloc(size_t numitems, size_t size)
1411 return calloc(numitems,size);
1415 win32_realloc(void *block, size_t size)
1417 return realloc(block,size);
1421 win32_free(void *block)
1426 /* returns pointer to the next unquoted space or the end of the string */
1428 find_next_space(const char *s)
1430 bool in_quotes = FALSE;
1432 /* ignore doubled backslashes, or backslash+quote */
1433 if (*s == '\\' && (s[1] == '\\' || s[1] == '"')) {
1436 /* keep track of when we're within quotes */
1437 else if (*s == '"') {
1439 in_quotes = !in_quotes;
1441 /* break it up only at spaces that aren't in quotes */
1442 else if (!in_quotes && isSPACE(*s))
1451 create_command_line(char *cname, STRLEN clen, const char * const *args)
1458 bool bat_file = FALSE;
1459 bool cmd_shell = FALSE;
1460 bool dumb_shell = FALSE;
1461 bool extra_quotes = FALSE;
1462 bool quote_next = FALSE;
1465 cname = (char*)args[0];
1467 /* The NT cmd.exe shell has the following peculiarity that needs to be
1468 * worked around. It strips a leading and trailing dquote when any
1469 * of the following is true:
1470 * 1. the /S switch was used
1471 * 2. there are more than two dquotes
1472 * 3. there is a special character from this set: &<>()@^|
1473 * 4. no whitespace characters within the two dquotes
1474 * 5. string between two dquotes isn't an executable file
1475 * To work around this, we always add a leading and trailing dquote
1476 * to the string, if the first argument is either "cmd.exe" or "cmd",
1477 * and there were at least two or more arguments passed to cmd.exe
1478 * (not including switches).
1479 * XXX the above rules (from "cmd /?") don't seem to be applied
1480 * always, making for the convolutions below :-(
1484 clen = strlen(cname);
1487 && (stricmp(&cname[clen-4], ".bat") == 0
1488 || (IsWinNT() && stricmp(&cname[clen-4], ".cmd") == 0)))
1494 char *exe = strrchr(cname, '/');
1495 char *exe2 = strrchr(cname, '\\');
1502 if (stricmp(exe, "cmd.exe") == 0 || stricmp(exe, "cmd") == 0) {
1506 else if (stricmp(exe, "command.com") == 0
1507 || stricmp(exe, "command") == 0)
1514 DEBUG_p(PerlIO_printf(Perl_debug_log, "Args "));
1515 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1516 STRLEN curlen = strlen(arg);
1517 if (!(arg[0] == '"' && arg[curlen-1] == '"'))
1518 len += 2; /* assume quoting needed (worst case) */
1520 DEBUG_p(PerlIO_printf(Perl_debug_log, "[%s]",arg));
1522 DEBUG_p(PerlIO_printf(Perl_debug_log, "\n"));
1525 New(1310, cmd, len, char);
1530 extra_quotes = TRUE;
1533 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1535 STRLEN curlen = strlen(arg);
1537 /* we want to protect empty arguments and ones with spaces with
1538 * dquotes, but only if they aren't already there */
1543 else if (quote_next) {
1544 /* see if it really is multiple arguments pretending to
1545 * be one and force a set of quotes around it */
1546 if (*find_next_space(arg))
1549 else if (!(arg[0] == '"' && curlen > 1 && arg[curlen-1] == '"')) {
1551 while (i < curlen) {
1552 if (isSPACE(arg[i])) {
1555 else if (arg[i] == '"') {
1579 && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
1580 && stricmp(arg+curlen-2, "/c") == 0)
1582 /* is there a next argument? */
1583 if (args[index+1]) {
1584 /* are there two or more next arguments? */
1585 if (args[index+2]) {
1587 extra_quotes = TRUE;
1590 /* single argument, force quoting if it has spaces */
1606 qualified_path(const char *cmd)
1610 char *fullcmd, *curfullcmd;
1616 fullcmd = (char*)cmd;
1618 if (*fullcmd == '/' || *fullcmd == '\\')
1625 pathstr = PerlEnv_getenv("PATH");
1626 New(0, fullcmd, MAX_PATH+1, char);
1627 curfullcmd = fullcmd;
1632 /* start by appending the name to the current prefix */
1633 strcpy(curfullcmd, cmd);
1634 curfullcmd += cmdlen;
1636 /* if it doesn't end with '.', or has no extension, try adding
1637 * a trailing .exe first */
1638 if (cmd[cmdlen-1] != '.'
1639 && (cmdlen < 4 || cmd[cmdlen-4] != '.'))
1641 strcpy(curfullcmd, ".exe");
1642 res = GetFileAttributes(fullcmd);
1643 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1648 /* that failed, try the bare name */
1649 res = GetFileAttributes(fullcmd);
1650 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1653 /* quit if no other path exists, or if cmd already has path */
1654 if (!pathstr || !*pathstr || has_slash)
1657 /* skip leading semis */
1658 while (*pathstr == ';')
1661 /* build a new prefix from scratch */
1662 curfullcmd = fullcmd;
1663 while (*pathstr && *pathstr != ';') {
1664 if (*pathstr == '"') { /* foo;"baz;etc";bar */
1665 pathstr++; /* skip initial '"' */
1666 while (*pathstr && *pathstr != '"') {
1667 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1668 *curfullcmd++ = *pathstr;
1672 pathstr++; /* skip trailing '"' */
1675 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1676 *curfullcmd++ = *pathstr;
1681 pathstr++; /* skip trailing semi */
1682 if (curfullcmd > fullcmd /* append a dir separator */
1683 && curfullcmd[-1] != '/' && curfullcmd[-1] != '\\')
1685 *curfullcmd++ = '\\';
1693 /* XXX this needs to be made more compatible with the spawnvp()
1694 * provided by the various RTLs. In particular, searching for
1695 * *.{com,bat,cmd} files (as done by the RTLs) is unimplemented.
1696 * This doesn't significantly affect perl itself, because we
1697 * always invoke things using PERL5SHELL if a direct attempt to
1698 * spawn the executable fails.
1700 * XXX splitting and rejoining the commandline between do_aspawn()
1701 * and win32_spawnvp() could also be avoided.
1707 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1709 #ifdef USE_RTL_SPAWNVP
1710 return spawnvp(mode, cmdname, (char * const *)argv);
1717 STARTUPINFO StartupInfo;
1718 PROCESS_INFORMATION ProcessInformation;
1721 char *fullcmd = Nullch;
1722 char *cname = (char *)cmdname;
1726 clen = strlen(cname);
1727 /* if command name contains dquotes, must remove them */
1728 if (strchr(cname, '"')) {
1730 New(0,cname,clen+1,char);
1743 cmd = create_command_line(cname, clen, argv);
1745 env = PerlEnv_get_childenv();
1746 dir = PerlEnv_get_childdir();
1749 case P_NOWAIT: /* asynch + remember result */
1750 if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
1755 /* Create a new process group so we can use GenerateConsoleCtrlEvent()
1758 /* not supported on CE create |= CREATE_NEW_PROCESS_GROUP; */
1761 case P_WAIT: /* synchronous execution */
1763 default: /* invalid mode */
1768 memset(&StartupInfo,0,sizeof(StartupInfo));
1769 StartupInfo.cb = sizeof(StartupInfo);
1770 memset(&tbl,0,sizeof(tbl));
1771 PerlEnv_get_child_IO(&tbl);
1772 StartupInfo.dwFlags = tbl.dwFlags;
1773 StartupInfo.dwX = tbl.dwX;
1774 StartupInfo.dwY = tbl.dwY;
1775 StartupInfo.dwXSize = tbl.dwXSize;
1776 StartupInfo.dwYSize = tbl.dwYSize;
1777 StartupInfo.dwXCountChars = tbl.dwXCountChars;
1778 StartupInfo.dwYCountChars = tbl.dwYCountChars;
1779 StartupInfo.dwFillAttribute = tbl.dwFillAttribute;
1780 StartupInfo.wShowWindow = tbl.wShowWindow;
1781 StartupInfo.hStdInput = tbl.childStdIn;
1782 StartupInfo.hStdOutput = tbl.childStdOut;
1783 StartupInfo.hStdError = tbl.childStdErr;
1784 if (StartupInfo.hStdInput == INVALID_HANDLE_VALUE &&
1785 StartupInfo.hStdOutput == INVALID_HANDLE_VALUE &&
1786 StartupInfo.hStdError == INVALID_HANDLE_VALUE)
1788 create |= CREATE_NEW_CONSOLE;
1791 StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
1793 if (w32_use_showwindow) {
1794 StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
1795 StartupInfo.wShowWindow = w32_showwindow;
1798 DEBUG_p(PerlIO_printf(Perl_debug_log, "Spawning [%s] with [%s]\n",
1801 if (!CreateProcess(cname, /* search PATH to find executable */
1802 cmd, /* executable, and its arguments */
1803 NULL, /* process attributes */
1804 NULL, /* thread attributes */
1805 TRUE, /* inherit handles */
1806 create, /* creation flags */
1807 (LPVOID)env, /* inherit environment */
1808 dir, /* inherit cwd */
1810 &ProcessInformation))
1812 /* initial NULL argument to CreateProcess() does a PATH
1813 * search, but it always first looks in the directory
1814 * where the current process was started, which behavior
1815 * is undesirable for backward compatibility. So we
1816 * jump through our own hoops by picking out the path
1817 * we really want it to use. */
1819 fullcmd = qualified_path(cname);
1821 if (cname != cmdname)
1824 DEBUG_p(PerlIO_printf(Perl_debug_log,
1825 "Retrying [%s] with same args\n",
1835 if (mode == P_NOWAIT) {
1836 /* asynchronous spawn -- store handle, return PID */
1837 ret = (int)ProcessInformation.dwProcessId;
1838 if (IsWin95() && ret < 0)
1841 w32_child_handles[w32_num_children] = ProcessInformation.hProcess;
1842 w32_child_pids[w32_num_children] = (DWORD)ret;
1847 win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
1848 /* FIXME: if msgwait returned due to message perhaps forward the
1849 "signal" to the process
1851 GetExitCodeProcess(ProcessInformation.hProcess, &status);
1853 CloseHandle(ProcessInformation.hProcess);
1856 CloseHandle(ProcessInformation.hThread);
1859 PerlEnv_free_childenv(env);
1860 PerlEnv_free_childdir(dir);
1862 if (cname != cmdname)
1869 win32_execv(const char *cmdname, const char *const *argv)
1872 Perl_croak(aTHX_ PL_no_func, "execv");
1877 win32_execvp(const char *cmdname, const char *const *argv)
1880 Perl_croak(aTHX_ PL_no_func, "execvp");
1885 win32_dynaload(const char* filename)
1890 hModule = XCELoadLibraryA(filename);
1895 /* this is needed by Cwd.pm... */
1902 SV *sv = sv_newmortal();
1904 xcegetcwd(buf, sizeof(buf));
1906 sv_setpv(sv, xcestrdup(buf));
1910 #ifndef INCOMPLETE_TAINTS
1911 SvTAINTED_on(ST(0));
1922 Perl_croak(aTHX_ "usage: Win32::SetCwd($cwd)");
1924 if (!xcechdir(SvPV_nolen(ST(0))))
1931 XS(w32_GetTickCount)
1934 DWORD msec = GetTickCount();
1942 XS(w32_GetOSVersion)
1945 OSVERSIONINFOA osver;
1947 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
1948 if (!XCEGetVersionExA(&osver)) {
1951 XPUSHs(newSVpvn(osver.szCSDVersion, strlen(osver.szCSDVersion)));
1952 XPUSHs(newSViv(osver.dwMajorVersion));
1953 XPUSHs(newSViv(osver.dwMinorVersion));
1954 XPUSHs(newSViv(osver.dwBuildNumber));
1956 XPUSHs(newSViv(osver.dwPlatformId));
1965 XSRETURN_IV(IsWinNT());
1973 XSRETURN_IV(IsWin95());
1981 XSRETURN_IV(IsWinCE());
1991 if(SystemParametersInfoW(SPI_GETOEMINFO, sizeof(wbuf), wbuf, FALSE))
1992 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, sizeof(buf), 0, 0);
1994 sprintf(buf, "SystemParametersInfo failed: %d", GetLastError());
2005 Perl_croak(aTHX_ "usage: Win32::Sleep($milliseconds)");
2016 Perl_croak(aTHX_ "usage: Win32::CopyFile($from, $to, $overwrite)");
2019 char szSourceFile[MAX_PATH+1];
2020 strcpy(szSourceFile, PerlDir_mapA(SvPV_nolen(ST(0))));
2021 bResult = XCECopyFileA(szSourceFile, SvPV_nolen(ST(1)),
2038 unsigned int flags = MB_OK;
2040 txt = SvPV_nolen(ST(0));
2042 if (items < 1 || items > 2)
2043 Perl_croak(aTHX_ "usage: Win32::MessageBox($txt, [$flags])");
2046 flags = SvIV(ST(1));
2048 res = XCEMessageBoxA(NULL, txt, "Perl", flags);
2054 XS(w32_GetPowerStatus)
2058 SYSTEM_POWER_STATUS_EX sps;
2060 if(GetSystemPowerStatusEx(&sps, TRUE) == FALSE)
2065 XPUSHs(newSViv(sps.ACLineStatus));
2066 XPUSHs(newSViv(sps.BatteryFlag));
2067 XPUSHs(newSViv(sps.BatteryLifePercent));
2068 XPUSHs(newSViv(sps.BatteryLifeTime));
2069 XPUSHs(newSViv(sps.BatteryFullLifeTime));
2070 XPUSHs(newSViv(sps.BackupBatteryFlag));
2071 XPUSHs(newSViv(sps.BackupBatteryLifePercent));
2072 XPUSHs(newSViv(sps.BackupBatteryLifeTime));
2073 XPUSHs(newSViv(sps.BackupBatteryFullLifeTime));
2085 SHELLEXECUTEINFO si;
2087 wchar_t wfile[MAX_PATH];
2091 Perl_croak(aTHX_ "usage: Win32::ShellEx($file, $verb)");
2093 file = SvPV_nolen(ST(0));
2094 verb = SvPV_nolen(ST(1));
2096 memset(&si, 0, sizeof(si));
2097 si.cbSize = sizeof(si);
2098 si.fMask = SEE_MASK_FLAG_NO_UI;
2100 MultiByteToWideChar(CP_ACP, 0, verb, -1,
2101 wverb, sizeof(wverb)/2);
2102 si.lpVerb = (TCHAR *)wverb;
2104 MultiByteToWideChar(CP_ACP, 0, file, -1,
2105 wfile, sizeof(wfile)/2);
2106 si.lpFile = (TCHAR *)wfile;
2108 if(ShellExecuteEx(&si) == FALSE)
2117 Perl_init_os_extras(void)
2120 char *file = __FILE__;
2123 w32_perlshell_tokens = Nullch;
2124 w32_perlshell_items = -1;
2125 w32_fdpid = newAV(); /* XX needs to be in Perl_win32_init()? */
2126 New(1313, w32_children, 1, child_tab);
2127 w32_num_children = 0;
2129 newXS("Win32::GetCwd", w32_GetCwd, file);
2130 newXS("Win32::SetCwd", w32_SetCwd, file);
2131 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2132 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2134 newXS("Win32::ShellEx", w32_ShellEx, file);
2136 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2137 newXS("Win32::IsWin95", w32_IsWin95, file);
2138 newXS("Win32::IsWinCE", w32_IsWinCE, file);
2139 newXS("Win32::CopyFile", w32_CopyFile, file);
2140 newXS("Win32::Sleep", w32_Sleep, file);
2141 newXS("Win32::MessageBox", w32_MessageBox, file);
2142 newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
2143 newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
2152 fgets(buf, sizeof(buf), stdin);
2156 Perl_win32_init(int *argcp, char ***argvp)
2161 if((p = xcegetenv("PERLDEBUG")) && (p[0] == 'y' || p[0] == 'Y'))
2169 Perl_win32_term(void)
2176 Perl_win32_term(void)
2183 win32_get_child_IO(child_IO_table* ptbl)
2185 ptbl->childStdIn = GetStdHandle(STD_INPUT_HANDLE);
2186 ptbl->childStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
2187 ptbl->childStdErr = GetStdHandle(STD_ERROR_HANDLE);
2190 win32_flock(int fd, int oper)
2193 Perl_croak(aTHX_ PL_no_func, "flock");
2198 win32_waitpid(int pid, int *status, int flags)
2201 Perl_croak(aTHX_ PL_no_func, "waitpid");
2206 win32_wait(int *status)
2209 Perl_croak(aTHX_ PL_no_func, "wait");
2216 return xcesystem(cmd);
2220 Perl_do_spawn(pTHX_ char *cmd)
2222 return do_spawn(aTHX_ cmd);
2226 Perl_do_aspawn(pTHX_ SV *really, SV **mark, SV **sp)
2228 Perl_croak(aTHX_ PL_no_func, "aspawn");
2233 wce_reopen_stdout(char *fname)
2235 if(xcefreopen(fname, "w", stdout) == NULL)
2246 printf("Hit RETURN");
2248 fgets(buf, sizeof(buf), stdin);
2252 /* //////////////////////////////////////////////////////////////////// */
2257 getcwd(char *buf, size_t size)
2259 return xcegetcwd(buf, size);
2269 win32_open_osfhandle(intptr_t osfhandle, int flags)
2272 char fileflags=0; /* _osfile flags */
2274 Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
2279 win32_get_osfhandle(int fd)
2282 char fileflags=0; /* _osfile flags */
2284 Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
2289 * a popen() clone that respects PERL5SHELL
2291 * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
2295 win32_popen(const char *command, const char *mode)
2297 Perl_croak_nocontext("win32_popen() TBD on this platform");
2301 win32_popenlist(const char *mode, IV narg, SV **args)
2304 Perl_croak(aTHX_ "List form of pipe open not implemented");
2313 win32_pclose(PerlIO *pf)
2315 #ifdef USE_RTL_POPEN
2319 int childpid, status;
2323 sv = *av_fetch(w32_fdpid, PerlIO_fileno(pf), TRUE);
2326 childpid = SvIVX(sv);
2343 if (win32_waitpid(childpid, &status, 0) == -1)
2348 #endif /* USE_RTL_POPEN */
2352 win32_fdupopen(FILE *pf)
2357 int fileno = win32_dup(win32_fileno(pf));
2359 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in .../wince/wince.c(win32_fdupopen)", "Perl(developer)", 0);
2360 Perl_croak_nocontext("win32_fdupopen() TBD on this platform");
2363 /* open the file in the same mode */
2364 if((pf)->_flag & _IOREAD) {
2368 else if((pf)->_flag & _IOWRT) {
2372 else if((pf)->_flag & _IORW) {
2378 /* it appears that the binmode is attached to the
2379 * file descriptor so binmode files will be handled
2382 pfdup = win32_fdopen(fileno, mode);
2384 /* move the file pointer to the same position */
2385 if (!fgetpos(pf, &pos)) {
2386 fsetpos(pfdup, &pos);
2392 #ifdef HAVE_INTERP_INTERN
2396 win32_csighandler(int sig)
2399 dTHXa(PERL_GET_SIG_CONTEXT);
2400 Perl_warn(aTHX_ "Got signal %d",sig);
2406 Perl_sys_intern_init(pTHX)
2409 w32_perlshell_tokens = Nullch;
2410 w32_perlshell_vec = (char**)NULL;
2411 w32_perlshell_items = 0;
2412 w32_fdpid = newAV();
2413 New(1313, w32_children, 1, child_tab);
2414 w32_num_children = 0;
2415 # ifdef USE_ITHREADS
2417 New(1313, w32_pseudo_children, 1, child_tab);
2418 w32_num_pseudo_children = 0;
2420 w32_init_socktype = 0;
2426 Perl_sys_intern_clear(pTHX)
2428 Safefree(w32_perlshell_tokens);
2429 Safefree(w32_perlshell_vec);
2430 /* NOTE: w32_fdpid is freed by sv_clean_all() */
2431 Safefree(w32_children);
2433 KillTimer(NULL,w32_timerid);
2436 # ifdef USE_ITHREADS
2437 Safefree(w32_pseudo_children);
2441 # ifdef USE_ITHREADS
2444 Perl_sys_intern_dup(pTHX_ struct interp_intern *src, struct interp_intern *dst)
2446 dst->perlshell_tokens = Nullch;
2447 dst->perlshell_vec = (char**)NULL;
2448 dst->perlshell_items = 0;
2449 dst->fdpid = newAV();
2450 Newz(1313, dst->children, 1, child_tab);
2452 Newz(1313, dst->pseudo_children, 1, child_tab);
2453 dst->thr_intern.Winit_socktype = 0;
2455 dst->poll_count = 0;
2456 Copy(src->sigtable,dst->sigtable,SIG_SIZE,Sighandler_t);
2458 # endif /* USE_ITHREADS */
2459 #endif /* HAVE_INTERP_INTERN */
2462 win32_free_argvw(pTHX_ void *ptr)
2464 char** argv = (char**)ptr;
2472 win32_argv2utf8(int argc, char** argv)
2474 /* do nothing, since we're not aware of command line arguments
2481 Perl_sys_intern_clear(pTHX)
2483 Safefree(w32_perlshell_tokens);
2484 Safefree(w32_perlshell_vec);
2485 /* NOTE: w32_fdpid is freed by sv_clean_all() */
2486 Safefree(w32_children);
2487 # ifdef USE_ITHREADS
2488 Safefree(w32_pseudo_children);
2493 // added to remove undefied symbol error in CodeWarrior compilation
2495 Perl_Ireentrant_buffer_ptr(aTHX)