Commit | Line | Data |
---|---|---|
0a753a76 | 1 | /* |
2 | * "The Road goes ever on and on, down from the door where it began." | |
3 | */ | |
adb71456 | 4 | #define PERLIO_NOT_STDIO 0 |
0a753a76 | 5 | #include "EXTERN.h" |
6 | #include "perl.h" | |
0cb96387 | 7 | |
96e4d5b1 | 8 | #include "XSUB.h" |
0a753a76 | 9 | |
32e30700 | 10 | #ifdef PERL_IMPLICIT_SYS |
0cb96387 GS |
11 | #include "win32iop.h" |
12 | #include <fcntl.h> | |
7766f137 | 13 | #endif /* PERL_IMPLICIT_SYS */ |
0cb96387 | 14 | |
0cb96387 | 15 | |
7766f137 GS |
16 | /* Register any extra external extensions */ |
17 | char *staticlinkmodules[] = { | |
18 | "DynaLoader", | |
19 | NULL, | |
0cb96387 GS |
20 | }; |
21 | ||
acfe0abc | 22 | EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); |
0cb96387 | 23 | |
7766f137 | 24 | static void |
acfe0abc | 25 | xs_init(pTHX) |
0cb96387 | 26 | { |
7766f137 GS |
27 | char *file = __FILE__; |
28 | dXSUB_SYS; | |
29 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); | |
0cb96387 GS |
30 | } |
31 | ||
7766f137 | 32 | #ifdef PERL_IMPLICIT_SYS |
0cb96387 | 33 | |
7766f137 | 34 | #include "perlhost.h" |
0cb96387 | 35 | |
32e30700 GS |
36 | EXTERN_C void |
37 | perl_get_host_info(struct IPerlMemInfo* perlMemInfo, | |
7766f137 GS |
38 | struct IPerlMemInfo* perlMemSharedInfo, |
39 | struct IPerlMemInfo* perlMemParseInfo, | |
32e30700 GS |
40 | struct IPerlEnvInfo* perlEnvInfo, |
41 | struct IPerlStdIOInfo* perlStdIOInfo, | |
42 | struct IPerlLIOInfo* perlLIOInfo, | |
43 | struct IPerlDirInfo* perlDirInfo, | |
44 | struct IPerlSockInfo* perlSockInfo, | |
45 | struct IPerlProcInfo* perlProcInfo) | |
0cb96387 | 46 | { |
7766f137 | 47 | if (perlMemInfo) { |
0cb96387 GS |
48 | Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*); |
49 | perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*)); | |
50 | } | |
7766f137 GS |
51 | if (perlMemSharedInfo) { |
52 | Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*); | |
53 | perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*)); | |
54 | } | |
55 | if (perlMemParseInfo) { | |
56 | Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*); | |
57 | perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*)); | |
58 | } | |
59 | if (perlEnvInfo) { | |
0cb96387 GS |
60 | Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*); |
61 | perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*)); | |
62 | } | |
7766f137 | 63 | if (perlStdIOInfo) { |
0cb96387 GS |
64 | Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*); |
65 | perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*)); | |
66 | } | |
7766f137 | 67 | if (perlLIOInfo) { |
0cb96387 GS |
68 | Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*); |
69 | perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*)); | |
70 | } | |
7766f137 | 71 | if (perlDirInfo) { |
0cb96387 GS |
72 | Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*); |
73 | perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*)); | |
74 | } | |
7766f137 | 75 | if (perlSockInfo) { |
0cb96387 GS |
76 | Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*); |
77 | perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*)); | |
78 | } | |
7766f137 | 79 | if (perlProcInfo) { |
0cb96387 GS |
80 | Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*); |
81 | perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*)); | |
82 | } | |
83 | } | |
84 | ||
7766f137 GS |
85 | EXTERN_C PerlInterpreter* |
86 | perl_alloc_override(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared, | |
87 | struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv, | |
88 | struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO, | |
89 | struct IPerlDir** ppDir, struct IPerlSock** ppSock, | |
90 | struct IPerlProc** ppProc) | |
0cb96387 | 91 | { |
7766f137 | 92 | PerlInterpreter *my_perl = NULL; |
8a85dc4e GS |
93 | CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv, |
94 | ppStdIO, ppLIO, ppDir, ppSock, ppProc); | |
7766f137 | 95 | |
8a85dc4e GS |
96 | if (pHost) { |
97 | my_perl = perl_alloc_using(pHost->m_pHostperlMem, | |
98 | pHost->m_pHostperlMemShared, | |
99 | pHost->m_pHostperlMemParse, | |
100 | pHost->m_pHostperlEnv, | |
101 | pHost->m_pHostperlStdIO, | |
102 | pHost->m_pHostperlLIO, | |
103 | pHost->m_pHostperlDir, | |
104 | pHost->m_pHostperlSock, | |
105 | pHost->m_pHostperlProc); | |
106 | if (my_perl) { | |
8a85dc4e | 107 | w32_internal_host = pHost; |
7766f137 | 108 | } |
0cb96387 | 109 | } |
7766f137 | 110 | return my_perl; |
0cb96387 GS |
111 | } |
112 | ||
7766f137 GS |
113 | EXTERN_C PerlInterpreter* |
114 | perl_alloc(void) | |
0cb96387 | 115 | { |
7766f137 | 116 | PerlInterpreter* my_perl = NULL; |
8a85dc4e GS |
117 | CPerlHost* pHost = new CPerlHost(); |
118 | if (pHost) { | |
119 | my_perl = perl_alloc_using(pHost->m_pHostperlMem, | |
120 | pHost->m_pHostperlMemShared, | |
121 | pHost->m_pHostperlMemParse, | |
122 | pHost->m_pHostperlEnv, | |
123 | pHost->m_pHostperlStdIO, | |
124 | pHost->m_pHostperlLIO, | |
125 | pHost->m_pHostperlDir, | |
126 | pHost->m_pHostperlSock, | |
127 | pHost->m_pHostperlProc); | |
128 | if (my_perl) { | |
8a85dc4e | 129 | w32_internal_host = pHost; |
7766f137 | 130 | } |
0cb96387 | 131 | } |
7766f137 | 132 | return my_perl; |
0cb96387 GS |
133 | } |
134 | ||
1c0ca838 GS |
135 | EXTERN_C void |
136 | win32_delete_internal_host(void *h) | |
137 | { | |
138 | CPerlHost *host = (CPerlHost*)h; | |
139 | delete host; | |
140 | } | |
141 | ||
32e30700 GS |
142 | #endif /* PERL_IMPLICIT_SYS */ |
143 | ||
7766f137 GS |
144 | EXTERN_C HANDLE w32_perldll_handle; |
145 | ||
c5be433b | 146 | EXTERN_C DllExport int |
0cb96387 | 147 | RunPerl(int argc, char **argv, char **env) |
0a753a76 | 148 | { |
68dc0745 | 149 | int exitstatus; |
ed094faf | 150 | PerlInterpreter *my_perl, *new_perl = NULL; |
0a753a76 | 151 | |
0cb96387 GS |
152 | #ifndef __BORLANDC__ |
153 | /* XXX this _may_ be a problem on some compilers (e.g. Borland) that | |
154 | * want to free() argv after main() returns. As luck would have it, | |
155 | * Borland's CRT does the right thing to argv[0] already. */ | |
156 | char szModuleName[MAX_PATH]; | |
157 | char *ptr; | |
158 | ||
159 | GetModuleFileName(NULL, szModuleName, sizeof(szModuleName)); | |
160 | (void)win32_longpath(szModuleName); | |
161 | argv[0] = szModuleName; | |
162 | #endif | |
163 | ||
22239a37 NIS |
164 | #ifdef PERL_GLOBAL_STRUCT |
165 | #define PERLVAR(var,type) /**/ | |
51371543 | 166 | #define PERLVARA(var,type) /**/ |
533c011a NIS |
167 | #define PERLVARI(var,type,init) PL_Vars.var = init; |
168 | #define PERLVARIC(var,type,init) PL_Vars.var = init; | |
22239a37 NIS |
169 | #include "perlvars.h" |
170 | #undef PERLVAR | |
51371543 | 171 | #undef PERLVARA |
22239a37 | 172 | #undef PERLVARI |
3fe35a81 | 173 | #undef PERLVARIC |
22239a37 NIS |
174 | #endif |
175 | ||
0a753a76 | 176 | PERL_SYS_INIT(&argc,&argv); |
177 | ||
68dc0745 | 178 | if (!(my_perl = perl_alloc())) |
179 | return (1); | |
642f9deb | 180 | perl_construct(my_perl); |
b28d0864 | 181 | PL_perl_destruct_level = 0; |
0a753a76 | 182 | |
4f63d024 | 183 | exitstatus = perl_parse(my_perl, xs_init, argc, argv, env); |
0a753a76 | 184 | if (!exitstatus) { |
7766f137 | 185 | #if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */ |
7766f137 | 186 | new_perl = perl_clone(my_perl, 1); |
642f9deb | 187 | exitstatus = perl_run(new_perl); |
ba869deb | 188 | PERL_SET_THX(my_perl); |
d18c6117 | 189 | #else |
642f9deb | 190 | exitstatus = perl_run(my_perl); |
d18c6117 | 191 | #endif |
0a753a76 | 192 | } |
193 | ||
642f9deb GS |
194 | perl_destruct(my_perl); |
195 | perl_free(my_perl); | |
ed094faf GS |
196 | #ifdef USE_ITHREADS |
197 | if (new_perl) { | |
ba869deb | 198 | PERL_SET_THX(new_perl); |
ed094faf GS |
199 | perl_destruct(new_perl); |
200 | perl_free(new_perl); | |
201 | } | |
202 | #endif | |
0a753a76 | 203 | |
204 | PERL_SYS_TERM(); | |
205 | ||
68dc0745 | 206 | return (exitstatus); |
0a753a76 | 207 | } |
208 | ||
2fa86c13 GS |
209 | EXTERN_C void |
210 | set_w32_module_name(void); | |
211 | ||
b73db59c GS |
212 | EXTERN_C void |
213 | EndSockets(void); | |
214 | ||
215 | ||
f8fb7c90 GS |
216 | #ifdef __MINGW32__ |
217 | EXTERN_C /* GCC in C++ mode mangles the name, otherwise */ | |
218 | #endif | |
68dc0745 | 219 | BOOL APIENTRY |
220 | DllMain(HANDLE hModule, /* DLL module handle */ | |
221 | DWORD fdwReason, /* reason called */ | |
222 | LPVOID lpvReserved) /* reserved */ | |
0a753a76 | 223 | { |
68dc0745 | 224 | switch (fdwReason) { |
225 | /* The DLL is attaching to a process due to process | |
226 | * initialization or a call to LoadLibrary. | |
227 | */ | |
228 | case DLL_PROCESS_ATTACH: | |
229 | /* #define DEFAULT_BINMODE */ | |
0a753a76 | 230 | #ifdef DEFAULT_BINMODE |
3e3baf6d TB |
231 | setmode( fileno( stdin ), O_BINARY ); |
232 | setmode( fileno( stdout ), O_BINARY ); | |
233 | setmode( fileno( stderr ), O_BINARY ); | |
234 | _fmode = O_BINARY; | |
0a753a76 | 235 | #endif |
5db10396 | 236 | DisableThreadLibraryCalls((HMODULE)hModule); |
2d7a9237 | 237 | w32_perldll_handle = hModule; |
2fa86c13 | 238 | set_w32_module_name(); |
68dc0745 | 239 | break; |
0a753a76 | 240 | |
68dc0745 | 241 | /* The DLL is detaching from a process due to |
242 | * process termination or call to FreeLibrary. | |
243 | */ | |
244 | case DLL_PROCESS_DETACH: | |
ce3e5b80 NIS |
245 | /* As long as we use TerminateProcess()/TerminateThread() etc. for mimicing kill() |
246 | anything here had better be harmless if: | |
247 | A. Not called at all. | |
248 | B. Called after memory allocation for Heap has been forcibly removed by OS. | |
249 | PerlIO_cleanup() was done here but fails (B). | |
250 | */ | |
b73db59c | 251 | EndSockets(); |
4d1ff10f | 252 | #if defined(USE_5005THREADS) || defined(USE_ITHREADS) |
e1b5da64 GS |
253 | if (PL_curinterp) |
254 | FREE_THREAD_KEY; | |
255 | #endif | |
68dc0745 | 256 | break; |
0a753a76 | 257 | |
68dc0745 | 258 | /* The attached process creates a new thread. */ |
259 | case DLL_THREAD_ATTACH: | |
260 | break; | |
0a753a76 | 261 | |
68dc0745 | 262 | /* The thread of the attached process terminates. */ |
263 | case DLL_THREAD_DETACH: | |
264 | break; | |
0a753a76 | 265 | |
68dc0745 | 266 | default: |
267 | break; | |
268 | } | |
269 | return TRUE; | |
0a753a76 | 270 | } |
c43294b8 | 271 | |
9613994f | 272 | #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) |
c43294b8 AB |
273 | EXTERN_C PerlInterpreter * |
274 | perl_clone_host(PerlInterpreter* proto_perl, UV flags) { | |
acfe0abc | 275 | dTHX; |
c43294b8 AB |
276 | CPerlHost *h; |
277 | h = new CPerlHost(*(CPerlHost*)PL_sys_intern.internal_host); | |
278 | proto_perl = perl_clone_using(proto_perl, flags, | |
279 | h->m_pHostperlMem, | |
280 | h->m_pHostperlMemShared, | |
281 | h->m_pHostperlMemParse, | |
282 | h->m_pHostperlEnv, | |
283 | h->m_pHostperlStdIO, | |
284 | h->m_pHostperlLIO, | |
285 | h->m_pHostperlDir, | |
286 | h->m_pHostperlSock, | |
287 | h->m_pHostperlProc | |
288 | ); | |
289 | proto_perl->Isys_intern.internal_host = h; | |
290 | return proto_perl; | |
291 | ||
292 | } | |
293 | #endif |