2 * "The Road goes ever on and on, down from the door where it began."
4 #define PERLIO_NOT_STDIO 0
10 #ifdef PERL_IMPLICIT_SYS
13 #endif /* PERL_IMPLICIT_SYS */
16 /* Register any extra external extensions */
17 char *staticlinkmodules[] = {
19 /* other similar records will be included from "perllibst.h" */
21 #include "perllibst.h"
25 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
26 /* other similar records will be included from "perllibst.h" */
28 #include "perllibst.h"
33 char *file = __FILE__;
35 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
36 /* other similar records will be included from "perllibst.h" */
38 #include "perllibst.h"
41 #ifdef PERL_IMPLICIT_SYS
46 win32_checkTLS(PerlInterpreter *host_perl)
49 if (host_perl != my_perl) {
57 perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
58 struct IPerlMemInfo* perlMemSharedInfo,
59 struct IPerlMemInfo* perlMemParseInfo,
60 struct IPerlEnvInfo* perlEnvInfo,
61 struct IPerlStdIOInfo* perlStdIOInfo,
62 struct IPerlLIOInfo* perlLIOInfo,
63 struct IPerlDirInfo* perlDirInfo,
64 struct IPerlSockInfo* perlSockInfo,
65 struct IPerlProcInfo* perlProcInfo)
68 Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
69 perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
71 if (perlMemSharedInfo) {
72 Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
73 perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
75 if (perlMemParseInfo) {
76 Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
77 perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
80 Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
81 perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
84 Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
85 perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
88 Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
89 perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
92 Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
93 perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
96 Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
97 perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
100 Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
101 perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
105 EXTERN_C PerlInterpreter*
106 perl_alloc_override(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
107 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
108 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
109 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
110 struct IPerlProc** ppProc)
112 PerlInterpreter *my_perl = NULL;
113 CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv,
114 ppStdIO, ppLIO, ppDir, ppSock, ppProc);
117 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
118 pHost->m_pHostperlMemShared,
119 pHost->m_pHostperlMemParse,
120 pHost->m_pHostperlEnv,
121 pHost->m_pHostperlStdIO,
122 pHost->m_pHostperlLIO,
123 pHost->m_pHostperlDir,
124 pHost->m_pHostperlSock,
125 pHost->m_pHostperlProc);
127 w32_internal_host = pHost;
128 pHost->host_perl = my_perl;
134 EXTERN_C PerlInterpreter*
137 PerlInterpreter* my_perl = NULL;
138 CPerlHost* pHost = new CPerlHost();
140 my_perl = perl_alloc_using(pHost->m_pHostperlMem,
141 pHost->m_pHostperlMemShared,
142 pHost->m_pHostperlMemParse,
143 pHost->m_pHostperlEnv,
144 pHost->m_pHostperlStdIO,
145 pHost->m_pHostperlLIO,
146 pHost->m_pHostperlDir,
147 pHost->m_pHostperlSock,
148 pHost->m_pHostperlProc);
150 w32_internal_host = pHost;
151 pHost->host_perl = my_perl;
158 win32_delete_internal_host(void *h)
160 CPerlHost *host = (CPerlHost*)h;
164 #endif /* PERL_IMPLICIT_SYS */
166 EXTERN_C HANDLE w32_perldll_handle;
168 EXTERN_C DllExport int
169 RunPerl(int argc, char **argv, char **env)
172 PerlInterpreter *my_perl, *new_perl = NULL;
175 /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
176 * want to free() argv after main() returns. As luck would have it,
177 * Borland's CRT does the right thing to argv[0] already. */
178 char szModuleName[MAX_PATH];
180 GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
181 (void)win32_longpath(szModuleName);
182 argv[0] = szModuleName;
185 #ifdef PERL_GLOBAL_STRUCT
186 #define PERLVAR(var,type) /**/
187 #define PERLVARA(var,type) /**/
188 #define PERLVARI(var,type,init) PL_Vars.var = init;
189 #define PERLVARIC(var,type,init) PL_Vars.var = init;
190 #include "perlvars.h"
197 PERL_SYS_INIT(&argc,&argv);
199 if (!(my_perl = perl_alloc()))
201 perl_construct(my_perl);
202 PL_perl_destruct_level = 0;
204 exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
206 #if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */
207 new_perl = perl_clone(my_perl, 1);
208 exitstatus = perl_run(new_perl);
209 PERL_SET_THX(my_perl);
211 exitstatus = perl_run(my_perl);
215 perl_destruct(my_perl);
219 PERL_SET_THX(new_perl);
220 perl_destruct(new_perl);
231 set_w32_module_name(void);
238 EXTERN_C /* GCC in C++ mode mangles the name, otherwise */
241 DllMain(HANDLE hModule, /* DLL module handle */
242 DWORD fdwReason, /* reason called */
243 LPVOID lpvReserved) /* reserved */
246 /* The DLL is attaching to a process due to process
247 * initialization or a call to LoadLibrary.
249 case DLL_PROCESS_ATTACH:
250 /* #define DEFAULT_BINMODE */
251 #ifdef DEFAULT_BINMODE
252 setmode( fileno( stdin ), O_BINARY );
253 setmode( fileno( stdout ), O_BINARY );
254 setmode( fileno( stderr ), O_BINARY );
257 DisableThreadLibraryCalls((HMODULE)hModule);
258 w32_perldll_handle = hModule;
259 set_w32_module_name();
262 /* The DLL is detaching from a process due to
263 * process termination or call to FreeLibrary.
265 case DLL_PROCESS_DETACH:
266 /* As long as we use TerminateProcess()/TerminateThread() etc. for mimicing kill()
267 anything here had better be harmless if:
268 A. Not called at all.
269 B. Called after memory allocation for Heap has been forcibly removed by OS.
270 PerlIO_cleanup() was done here but fails (B).
273 #if defined(USE_ITHREADS)
279 /* The attached process creates a new thread. */
280 case DLL_THREAD_ATTACH:
283 /* The thread of the attached process terminates. */
284 case DLL_THREAD_DETACH:
293 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
294 EXTERN_C PerlInterpreter *
295 perl_clone_host(PerlInterpreter* proto_perl, UV flags) {
298 h = new CPerlHost(*(CPerlHost*)PL_sys_intern.internal_host);
299 proto_perl = perl_clone_using(proto_perl, flags,
301 h->m_pHostperlMemShared,
302 h->m_pHostperlMemParse,
310 proto_perl->Isys_intern.internal_host = h;
311 h->host_perl = proto_perl;