2 * "The Road goes ever on and on, down from the door where it began."
15 #ifdef PERL_IMPLICIT_SYS
18 #endif /* PERL_IMPLICIT_SYS */
21 /* Register any extra external extensions */
22 char *staticlinkmodules[] = {
27 EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv);
32 char *file = __FILE__;
34 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
37 #ifdef PERL_IMPLICIT_SYS
42 perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
43 struct IPerlMemInfo* perlMemSharedInfo,
44 struct IPerlMemInfo* perlMemParseInfo,
45 struct IPerlEnvInfo* perlEnvInfo,
46 struct IPerlStdIOInfo* perlStdIOInfo,
47 struct IPerlLIOInfo* perlLIOInfo,
48 struct IPerlDirInfo* perlDirInfo,
49 struct IPerlSockInfo* perlSockInfo,
50 struct IPerlProcInfo* perlProcInfo)
53 Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
54 perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
56 if (perlMemSharedInfo) {
57 Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
58 perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
60 if (perlMemParseInfo) {
61 Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
62 perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
65 Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
66 perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
69 Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
70 perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
73 Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
74 perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
77 Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
78 perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
81 Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
82 perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
85 Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
86 perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
90 EXTERN_C PerlInterpreter*
91 perl_alloc_override(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
92 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
93 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
94 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
95 struct IPerlProc** ppProc)
97 PerlInterpreter *my_perl = NULL;
98 CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv,
99 ppStdIO, ppLIO, ppDir, ppSock, ppProc);
102 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
103 pHost->m_pHostperlMemShared,
104 pHost->m_pHostperlMemParse,
105 pHost->m_pHostperlEnv,
106 pHost->m_pHostperlStdIO,
107 pHost->m_pHostperlLIO,
108 pHost->m_pHostperlDir,
109 pHost->m_pHostperlSock,
110 pHost->m_pHostperlProc);
113 CPerlObj* pPerl = (CPerlObj*)my_perl;
115 w32_internal_host = pHost;
121 EXTERN_C PerlInterpreter*
124 PerlInterpreter* my_perl = NULL;
125 CPerlHost* pHost = new CPerlHost();
127 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
128 pHost->m_pHostperlMemShared,
129 pHost->m_pHostperlMemParse,
130 pHost->m_pHostperlEnv,
131 pHost->m_pHostperlStdIO,
132 pHost->m_pHostperlLIO,
133 pHost->m_pHostperlDir,
134 pHost->m_pHostperlSock,
135 pHost->m_pHostperlProc);
138 CPerlObj* pPerl = (CPerlObj*)my_perl;
140 w32_internal_host = pHost;
149 perl_construct(PerlInterpreter* my_perl)
151 CPerlObj* pPerl = (CPerlObj*)my_perl;
158 win32_fprintf(stderr, "%s\n",
159 "Error: Unable to construct data structures");
160 CPerlHost* pHost = (CPerlHost*)w32_internal_host;
163 SetPerlInterpreter(NULL);
168 perl_destruct(PerlInterpreter* my_perl)
170 CPerlObj* pPerl = (CPerlObj*)my_perl;
185 perl_free(PerlInterpreter* my_perl)
187 CPerlObj* pPerl = (CPerlObj*)my_perl;
189 CPerlHost* pHost = (CPerlHost*)w32_internal_host;
195 CPerlHost* pHost = (CPerlHost*)w32_internal_host;
203 SetPerlInterpreter(NULL);
207 perl_run(PerlInterpreter* my_perl)
209 CPerlObj* pPerl = (CPerlObj*)my_perl;
220 win32_fprintf(stderr, "Error: Runtime exception\n");
228 perl_parse(PerlInterpreter* my_perl, void (*xsinit)(CPerlObj*), int argc, char** argv, char** env)
231 CPerlObj* pPerl = (CPerlObj*)my_perl;
233 retVal = Perl_parse(xsinit, argc, argv, env);
237 retVal = Perl_parse(xsinit, argc, argv, env);
241 win32_fprintf(stderr, "Error: Parse exception\n");
249 #undef PL_perl_destruct_level
250 #define PL_perl_destruct_level int dummy
252 #endif /* PERL_OBJECT */
253 #endif /* PERL_IMPLICIT_SYS */
255 EXTERN_C HANDLE w32_perldll_handle;
257 static DWORD g_TlsAllocIndex;
259 EXTERN_C DllExport bool
260 SetPerlInterpreter(void *interp)
262 return TlsSetValue(g_TlsAllocIndex, interp);
265 EXTERN_C DllExport void*
266 GetPerlInterpreter(void)
268 return TlsGetValue(g_TlsAllocIndex);
271 EXTERN_C DllExport int
272 RunPerl(int argc, char **argv, char **env)
275 PerlInterpreter *my_perl, *new_perl = NULL;
276 struct perl_thread *thr;
279 /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
280 * want to free() argv after main() returns. As luck would have it,
281 * Borland's CRT does the right thing to argv[0] already. */
282 char szModuleName[MAX_PATH];
285 GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
286 (void)win32_longpath(szModuleName);
287 argv[0] = szModuleName;
290 #ifdef PERL_GLOBAL_STRUCT
291 #define PERLVAR(var,type) /**/
292 #define PERLVARA(var,type) /**/
293 #define PERLVARI(var,type,init) PL_Vars.var = init;
294 #define PERLVARIC(var,type,init) PL_Vars.var = init;
295 #include "perlvars.h"
302 PERL_SYS_INIT(&argc,&argv);
304 if (!(my_perl = perl_alloc()))
306 perl_construct( my_perl );
307 PL_perl_destruct_level = 0;
309 exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
311 #if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */
313 CPerlHost *h = new CPerlHost();
314 new_perl = perl_clone_using(my_perl, 1,
316 h->m_pHostperlMemShared,
317 h->m_pHostperlMemParse,
325 CPerlObj *pPerl = (CPerlObj*)new_perl;
327 new_perl = perl_clone(my_perl, 1);
329 exitstatus = perl_run( new_perl );
330 SetPerlInterpreter(my_perl);
332 exitstatus = perl_run( my_perl );
336 perl_destruct( my_perl );
337 perl_free( my_perl );
340 SetPerlInterpreter(new_perl);
341 perl_destruct(new_perl);
352 DllMain(HANDLE hModule, /* DLL module handle */
353 DWORD fdwReason, /* reason called */
354 LPVOID lpvReserved) /* reserved */
357 /* The DLL is attaching to a process due to process
358 * initialization or a call to LoadLibrary.
360 case DLL_PROCESS_ATTACH:
361 /* #define DEFAULT_BINMODE */
362 #ifdef DEFAULT_BINMODE
363 setmode( fileno( stdin ), O_BINARY );
364 setmode( fileno( stdout ), O_BINARY );
365 setmode( fileno( stderr ), O_BINARY );
368 g_TlsAllocIndex = TlsAlloc();
369 DisableThreadLibraryCalls((HMODULE)hModule);
370 w32_perldll_handle = hModule;
373 /* The DLL is detaching from a process due to
374 * process termination or call to FreeLibrary.
376 case DLL_PROCESS_DETACH:
377 TlsFree(g_TlsAllocIndex);
380 /* The attached process creates a new thread. */
381 case DLL_THREAD_ATTACH:
384 /* The thread of the attached process terminates. */
385 case DLL_THREAD_DETACH: