2 * The Road goes ever on and on
3 * Down from the door where it began.
5 * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"]
6 * [Frodo on p.73 of _The Lord of the Rings_, I/iii: "Three Is Company"]
8 #define PERLIO_NOT_STDIO 0
14 #ifdef PERL_IMPLICIT_SYS
17 #endif /* PERL_IMPLICIT_SYS */
20 /* Register any extra external extensions */
21 char *staticlinkmodules[] = {
23 /* other similar records will be included from "perllibst.h" */
25 #include "perllibst.h"
29 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
30 /* other similar records will be included from "perllibst.h" */
32 #include "perllibst.h"
37 char *file = __FILE__;
39 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
40 /* other similar records will be included from "perllibst.h" */
42 #include "perllibst.h"
45 #ifdef PERL_IMPLICIT_SYS
47 /* WINCE: include replaced by:
48 extern "C" void win32_checkTLS(PerlInterpreter *host_perl);
53 win32_checkTLS(PerlInterpreter *host_perl)
56 if (host_perl != my_perl) {
59 printf(" ... bad in win32_checkTLS\n");
60 printf(" %08X ne %08X\n",host_perl,my_perl);
67 int GetLogicalDrives() {
68 return 0; /* no logical drives on CE */
70 int GetLogicalDriveStrings(int size, char addr[]) {
71 return 0; /* no logical drives on CE */
74 DWORD GetFullPathNameA(LPCSTR fn, DWORD blen, LPTSTR buf, LPSTR *pfile) {
78 DWORD GetFullPathNameW(CONST WCHAR *fn, DWORD blen, WCHAR * buf, WCHAR **pfile) {
82 DWORD SetCurrentDirectoryA(LPSTR pPath) {
86 DWORD SetCurrentDirectoryW(CONST WCHAR *pPath) {
89 int xcesetuid(uid_t id){return 0;}
90 int xceseteuid(uid_t id){ return 0;}
91 int xcegetuid() {return 0;}
92 int xcegeteuid(){ return 0;}
95 /* WINCE??: include "perlhost.h" */
98 perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
99 struct IPerlMemInfo* perlMemSharedInfo,
100 struct IPerlMemInfo* perlMemParseInfo,
101 struct IPerlEnvInfo* perlEnvInfo,
102 struct IPerlStdIOInfo* perlStdIOInfo,
103 struct IPerlLIOInfo* perlLIOInfo,
104 struct IPerlDirInfo* perlDirInfo,
105 struct IPerlSockInfo* perlSockInfo,
106 struct IPerlProcInfo* perlProcInfo)
109 Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
110 perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
112 if (perlMemSharedInfo) {
113 Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
114 perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
116 if (perlMemParseInfo) {
117 Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
118 perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
121 Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
122 perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
125 Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
126 perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
129 Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
130 perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
133 Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
134 perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
137 Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
138 perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
141 Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
142 perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
146 EXTERN_C PerlInterpreter*
147 perl_alloc_override(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
148 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
149 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
150 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
151 struct IPerlProc** ppProc)
153 PerlInterpreter *my_perl = NULL;
154 CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv,
155 ppStdIO, ppLIO, ppDir, ppSock, ppProc);
158 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
159 pHost->m_pHostperlMemShared,
160 pHost->m_pHostperlMemParse,
161 pHost->m_pHostperlEnv,
162 pHost->m_pHostperlStdIO,
163 pHost->m_pHostperlLIO,
164 pHost->m_pHostperlDir,
165 pHost->m_pHostperlSock,
166 pHost->m_pHostperlProc);
168 w32_internal_host = pHost;
169 pHost->host_perl = my_perl;
175 EXTERN_C PerlInterpreter*
178 PerlInterpreter* my_perl = NULL;
179 CPerlHost* pHost = new CPerlHost();
181 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
182 pHost->m_pHostperlMemShared,
183 pHost->m_pHostperlMemParse,
184 pHost->m_pHostperlEnv,
185 pHost->m_pHostperlStdIO,
186 pHost->m_pHostperlLIO,
187 pHost->m_pHostperlDir,
188 pHost->m_pHostperlSock,
189 pHost->m_pHostperlProc);
191 w32_internal_host = pHost;
192 pHost->host_perl = my_perl;
199 win32_delete_internal_host(void *h)
201 CPerlHost *host = (CPerlHost*)h;
205 #endif /* PERL_IMPLICIT_SYS */
207 EXTERN_C HANDLE w32_perldll_handle;
209 EXTERN_C DllExport int
210 RunPerl(int argc, char **argv, char **env)
213 PerlInterpreter *my_perl, *new_perl = NULL;
215 char szModuleName[MAX_PATH];
216 char *arg0 = argv[0];
218 bool use_environ = (env == environ);
220 osver.dwOSVersionInfoSize = sizeof(osver);
221 GetVersionEx(&osver);
223 if (osver.dwMajorVersion > 4) {
224 WCHAR widename[MAX_PATH];
225 GetModuleFileNameW(NULL, widename, sizeof(widename)/sizeof(WCHAR));
226 argv[0] = ansi = win32_ansipath(widename);
229 Win_GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
230 (void)win32_longpath(szModuleName);
231 argv[0] = szModuleName;
234 #ifdef PERL_GLOBAL_STRUCT
235 #define PERLVAR(var,type) /**/
236 #define PERLVARA(var,type) /**/
237 #define PERLVARI(var,type,init) PL_Vars.var = init;
238 #define PERLVARIC(var,type,init) PL_Vars.var = init;
239 #include "perlvars.h"
246 PERL_SYS_INIT(&argc,&argv);
248 if (!(my_perl = perl_alloc()))
250 perl_construct(my_perl);
251 PL_perl_destruct_level = 0;
253 /* PERL_SYS_INIT() may update the environment, e.g. via ansify_path().
254 * This may reallocate the RTL environment block. Therefore we need
255 * to make sure that `env` continues to have the same value as `environ`
256 * if we have been called this way. If we have been called with any
257 * other value for `env` then all environment munging by PERL_SYS_INIT()
258 * will be lost again.
263 exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
265 #if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */
266 new_perl = perl_clone(my_perl, 1);
267 exitstatus = perl_run(new_perl);
268 PERL_SET_THX(my_perl);
270 exitstatus = perl_run(my_perl);
274 perl_destruct(my_perl);
278 PERL_SET_THX(new_perl);
279 perl_destruct(new_perl);
284 /* At least the Borland RTL wants to free argv[] after main() returns. */
295 set_w32_module_name(void);
302 EXTERN_C /* GCC in C++ mode mangles the name, otherwise */
305 DllMain(HANDLE hModule, /* DLL module handle */
306 DWORD fdwReason, /* reason called */
307 LPVOID lpvReserved) /* reserved */
310 /* The DLL is attaching to a process due to process
311 * initialization or a call to LoadLibrary.
313 case DLL_PROCESS_ATTACH:
314 /* #define DEFAULT_BINMODE */
315 #ifdef DEFAULT_BINMODE
316 setmode( fileno( stdin ), O_BINARY );
317 setmode( fileno( stdout ), O_BINARY );
318 setmode( fileno( stderr ), O_BINARY );
323 DisableThreadLibraryCalls((HMODULE)hModule);
326 w32_perldll_handle = hModule;
327 set_w32_module_name();
330 /* The DLL is detaching from a process due to
331 * process termination or call to FreeLibrary.
333 case DLL_PROCESS_DETACH:
334 /* As long as we use TerminateProcess()/TerminateThread() etc. for mimicing kill()
335 anything here had better be harmless if:
336 A. Not called at all.
337 B. Called after memory allocation for Heap has been forcibly removed by OS.
338 PerlIO_cleanup() was done here but fails (B).
341 #if defined(USE_ITHREADS)
347 /* The attached process creates a new thread. */
348 case DLL_THREAD_ATTACH:
351 /* The thread of the attached process terminates. */
352 case DLL_THREAD_DETACH:
362 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
363 EXTERN_C PerlInterpreter *
364 perl_clone_host(PerlInterpreter* proto_perl, UV flags) {
367 h = new CPerlHost(*(CPerlHost*)PL_sys_intern.internal_host);
368 proto_perl = perl_clone_using(proto_perl, flags,
370 h->m_pHostperlMemShared,
371 h->m_pHostperlMemParse,
379 proto_perl->Isys_intern.internal_host = h;
380 h->host_perl = proto_perl;