source: trunk/src/kernel32/wprocess.cpp@ 622

Last change on this file since 622 was 622, checked in by sandervl, 26 years ago

PE loader bugfixes

File size: 25.5 KB
Line 
1/* $Id: wprocess.cpp,v 1.25 1999-08-22 14:24:35 sandervl Exp $ */
2
3/*
4 * Win32 process functions
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17#include "unicode.h"
18#include "windll.h"
19#include "winexe.h"
20
21#ifdef __IBMCPP__
22#include <builtin.h>
23#endif
24
25#include "exceptutil.h"
26#include "os2util.h"
27
28#include "console.h"
29#include "cio.h"
30#include "versionos2.h" /*PLF Wed 98-03-18 02:36:51*/
31#include <wprocess.h>
32
33BOOL fExeStarted = FALSE;
34BOOL fFreeLibrary = FALSE;
35
36//Process database
37PDB ProcessPDB = {0};
38USHORT ProcessTIBSel = 0;
39DWORD *TIBFlatPtr = 0;
40
41extern "C" ULONG QueryExceptionChain();
42
43
44//******************************************************************************
45//******************************************************************************
46TEB *WIN32API GetThreadTEB()
47{
48 return (TEB *)*TIBFlatPtr;
49}
50//******************************************************************************
51//******************************************************************************
52THDB *WIN32API GetThreadTHDB()
53{
54 TEB *winteb;
55 THDB *thdb;
56
57 winteb = (TEB *)*TIBFlatPtr;
58 if(winteb == NULL) {
59 return NULL;
60 }
61 thdb = (THDB *)(winteb+1);
62
63 return thdb;
64}
65//******************************************************************************
66// Set up the TIB selector and memory for the current thread
67//******************************************************************************
68TEB *InitializeTIB(BOOL fMainThread)
69{
70 TEB *winteb;
71 THDB *thdb;
72
73 USHORT tibsel;
74
75 //Allocate one dword to store the flat address of our TEB
76 TIBFlatPtr = (DWORD *)OS2AllocThreadLocalMemory(1);
77 if(TIBFlatPtr == 0) {
78 dprintf(("InitializeTIB: local thread memory alloc failed!!"));
79 DebugInt3();
80 return NULL;
81 }
82 if(OS2AllocSel(PAGE_SIZE, &tibsel) == FALSE)
83 {
84 dprintf(("InitializeTIB: selector alloc failed!!"));
85 DebugInt3();
86 return NULL;
87 }
88 winteb = (TEB *)OS2SelToFlat(tibsel);
89 if(winteb == NULL)
90 {
91 dprintf(("InitializeTIB: DosSelToFlat failed!!"));
92 DebugInt3();
93 return NULL;
94 }
95 memset(winteb, 0, PAGE_SIZE);
96 thdb = (THDB *)(winteb+1);
97 *TIBFlatPtr = (DWORD)winteb;
98
99 winteb->except = (PVOID)-1; /* 00 Head of exception handling chain */
100 winteb->stack_top = (PVOID)OS2GetTIB(TIB_STACKTOP); /* 04 Top of thread stack */
101 winteb->stack_low = (PVOID)OS2GetTIB(TIB_STACKLOW); /* 08 Stack low-water mark */
102 winteb->htask16 = (USHORT)OS2GetPIB(PIB_TASKHNDL); /* 0c Win16 task handle */
103 winteb->stack_sel = getSS(); /* 0e 16-bit stack selector */
104 winteb->self = winteb; /* 18 Pointer to this structure */
105 winteb->flags = TEBF_WIN32; /* 1c Flags */
106 winteb->queue = 0; /* 28 Message queue */
107 winteb->tls_ptr = &thdb->tls_array[0]; /* 2c Pointer to TLS array */
108 winteb->process = &ProcessPDB; /* 30 owning process (used by NT3.51 applets)*/
109
110 memcpy(&thdb->teb, winteb, sizeof(TEB));
111 thdb->process = &ProcessPDB;
112 thdb->exit_code = 0x103; /* STILL_ACTIVE */
113 thdb->teb_sel = tibsel;
114 thdb->OrgTIBSel = GetFS();
115
116 if(OS2GetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
117 {
118 thdb->flags = 0; //todo gui
119 }
120 else thdb->flags = 0; //todo textmode
121
122 if(fMainThread)
123 {
124 //todo initialize PDB during process creation
125 //todo: initialize TLS array if required
126 //TLS in executable always TLS index 0?
127 ProcessTIBSel = tibsel;
128 }
129 dprintf(("InitializeTIB setup TEB with selector %x", tibsel));
130 dprintf(("InitializeTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
131 return winteb;
132}
133//******************************************************************************
134// Destroy the TIB selector and memory for the current thread
135//******************************************************************************
136void DestroyTIB()
137{
138 SHORT orgtibsel;
139 TEB *winteb;
140 THDB *thdb;
141
142 dprintf(("DestroyTIB: FS = %x", GetFS()));
143 dprintf(("DestroyTIB: FS:[0] = %x", QueryExceptionChain()));
144
145 winteb = (TEB *)*TIBFlatPtr;
146 if(winteb) {
147 thdb = (THDB *)(winteb+1);
148 orgtibsel = thdb->OrgTIBSel;
149
150 //Restore our original FS selector
151 SetFS(orgtibsel);
152
153 //And free our own
154 OS2FreeSel(thdb->teb_sel);
155 }
156 else dprintf(("Already destroyed TIB"));
157
158 dprintf(("DestroyTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
159 *TIBFlatPtr = 0;
160 return;
161}
162/******************************************************************************/
163/******************************************************************************/
164void WIN32API RestoreOS2TIB()
165{
166 SHORT orgtibsel;
167 TEB *winteb;
168 THDB *thdb;
169
170 winteb = (TEB *)*TIBFlatPtr;
171 if(winteb) {
172 thdb = (THDB *)(winteb+1);
173 orgtibsel = thdb->OrgTIBSel;
174
175 //Restore our original FS selector
176 SetFS(orgtibsel);
177 }
178}
179/******************************************************************************/
180/******************************************************************************/
181USHORT WIN32API SetWin32TIB()
182{
183 SHORT win32tibsel;
184 TEB *winteb;
185 THDB *thdb;
186
187 winteb = (TEB *)*TIBFlatPtr;
188 if(winteb) {
189 thdb = (THDB *)(winteb+1);
190 win32tibsel = thdb->teb_sel;
191
192 //Restore our win32 FS selector
193 return SetReturnFS(win32tibsel);
194 }
195 // nested calls are OK, OS2ToWinCallback for instance
196 //else DebugInt3();
197
198 return GetFS();
199}
200/******************************************************************************/
201//******************************************************************************
202void WIN32API RegisterExe(WIN32EXEENTRY EntryPoint, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
203 LPDWORD TlsIndexAddr, ULONG TlsInitSize,
204 ULONG TlsTotalSize, LPVOID TlsAddress,
205 LONG Win32TableId, LONG NameTableId, LONG VersionResId,
206 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwReserved)
207{
208 if(WinExe != NULL) //should never happen
209 delete(WinExe);
210
211 CheckVersion(Pe2lxVersion, OS2GetDllName(hinstance));
212
213 if(getenv("WIN32_IOPL2")) {
214 io_init1();
215 }
216
217 Win32Exe *winexe;
218
219 winexe = new Win32Exe(hinstance, NameTableId, Win32TableId);
220
221 if(winexe) {
222 dprintf(("RegisterExe Win32TableId = %x", Win32TableId));
223 dprintf(("RegisterExe NameTableId = %x", NameTableId));
224 dprintf(("RegisterExe VersionResId = %x", VersionResId));
225 dprintf(("RegisterExe Pe2lxVersion = %x", Pe2lxVersion));
226
227 winexe->setVersionId(VersionResId);
228 winexe->setEntryPoint((ULONG)EntryPoint);
229 winexe->setTLSAddress(TlsAddress);
230 winexe->setTLSInitSize(TlsInitSize);
231 winexe->setTLSTotalSize(TlsTotalSize);
232 winexe->setTLSIndexAddr(TlsIndexAddr);
233 winexe->setTLSCallBackAddr(TlsCallbackAddr);
234
235 char *modname = getenv("WIN32MODULE");
236
237 if(modname != NULL)
238 {
239 dprintf(("Set full path for exe to %s", modname));
240 winexe->setFullPath(modname);
241 }
242 winexe->start();
243 }
244 else {
245 eprintf(("Win32Exe creation failed!\n"));
246 DebugInt3();
247 return;
248 }
249}
250//******************************************************************************
251//******************************************************************************
252ULONG WIN32API RegisterDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
253 LPDWORD TlsIndexAddr, ULONG TlsInitSize,
254 ULONG TlsTotalSize, LPVOID TlsAddress,
255 LONG Win32TableId, LONG NameTableId, LONG VersionResId,
256 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)
257{
258 char *name;
259
260 Win32Dll *winmod = Win32Dll::findModule(hinstance);
261 if(dwAttachType == 0)
262 { //Process attach
263 if(getenv("WIN32_IOPL2")) {
264 io_init1();
265 }
266 name = OS2GetDllName(hinstance);
267 CheckVersion(Pe2lxVersion, name);
268
269 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));
270 dprintf(("RegisterDll Win32TableId = %x", Win32TableId));
271 dprintf(("RegisterDll NameTableId = %x", NameTableId));
272 dprintf(("RegisterDll VersionResId = %x", VersionResId));
273 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));
274
275 if(winmod != NULL) {
276 //dll manually loaded by PE loader (Win32Dll::init)
277 winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);
278 }
279 else {
280 //converted win32 dll loaded by OS/2 loader
281 winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
282 if(winmod == NULL) {
283 eprintf(("Failed to allocate module object!\n"));
284 DebugInt3();
285 return 0; //fail dll load
286 }
287 }
288 winmod->setTLSAddress(TlsAddress);
289 winmod->setTLSInitSize(TlsInitSize);
290 winmod->setTLSTotalSize(TlsTotalSize);
291 winmod->setTLSIndexAddr(TlsIndexAddr);
292 winmod->setTLSCallBackAddr(TlsCallbackAddr);
293
294 /* @@@PH 1998/03/17 console devices initialization */
295 iConsoleDevicesRegister();
296
297 //SvL: 19-8-'98
298 winmod->AddRef();
299 winmod->setVersionId(VersionResId);
300
301 winmod->attachProcess();
302 }
303 else {//process detach
304 if(winmod != NULL && !fFreeLibrary) {
305 return 0; //don't unload (OS/2 dll unload bug)
306 }
307 //Runtime environment could already be gone, so don't do this
308 // dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
309 }
310 return 1; //success
311}
312//******************************************************************************
313//******************************************************************************
314void _System Win32DllExitList(ULONG reason)
315{
316 dprintf(("Win32DllExitList %d\n", reason));
317
318 if(WinExe) {
319 delete(WinExe);
320 WinExe = NULL;
321 }
322 return;
323}
324//******************************************************************************
325//******************************************************************************
326VOID WIN32API ExitProcess(DWORD exitcode)
327{
328 dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
329 dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
330
331 //avoid crashes since win32 & OS/2 exception handler aren't identical
332 //(terminate process generates two exceptions)
333 /* @@@PH 1998/02/12 Added Console Support */
334 if (iConsoleIsActive())
335 iConsoleWaitClose();
336
337 Win32DllExitList(0);
338
339 //Restore original OS/2 TIB selector
340 DestroyTIB();
341 SetExceptionChain((ULONG)-1);
342
343 O32_ExitProcess(exitcode);
344}
345//******************************************************************************
346//******************************************************************************
347BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
348{
349 Win32Dll *winmod;
350 BOOL rc;
351
352 dprintf(("FreeLibrary"));
353 winmod = Win32Dll::findModule(hinstance);
354 if(winmod) {
355 winmod->Release();
356 return(TRUE);
357 }
358 dprintf(("KERNEL32: FreeLibrary %s %X\n", OS2GetDllName(hinstance), hinstance));
359
360 //TODO: Not thread safe
361 fFreeLibrary = TRUE; //ditch dll
362 rc = O32_FreeLibrary(hinstance);
363 fFreeLibrary = FALSE;
364 dprintf(("FreeLibrary returned %X\n", rc));
365 return(TRUE);
366}
367/******************************************************************************/
368/******************************************************************************/
369static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile)
370{
371 char modname[CCHMAXPATH];
372 HINSTANCE hDll;
373 Win32Dll *module;
374
375 hDll = O32_LoadLibrary(lpszLibFile);
376 dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
377 lpszLibFile,
378 hDll,
379 GetLastError()));
380 if(hDll)
381 {
382 return hDll; //converted dll or win32k took care of it
383 }
384
385 strcpy(modname, lpszLibFile);
386 strupr(modname);
387 if(!strstr(modname, ".DLL")) {
388 strcat(modname,".DLL");
389 }
390
391 if(Win32Image::isPEImage((char *)modname)) {
392 module = Win32Dll::findModule((char *)modname);
393 if(module) {//don't load it again
394 module->AddRef();
395 return module->getInstanceHandle();
396 }
397
398 module = new Win32Dll((char *)modname);
399 if(module == NULL)
400 return(0);
401
402 module->init(0);
403 if(module->getError() != NO_ERROR) {
404 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
405 delete(module);
406 return(0);
407 }
408 if(module->attachProcess() == FALSE) {
409 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
410 delete(module);
411 return(0);
412 }
413 module->AddRef();
414 return module->getInstanceHandle();
415 }
416 else
417 return(0);
418}
419
420
421HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
422{
423 HINSTANCE hDll;
424
425 dprintf(("KERNEL32: LoadLibraryA(%s)\n",
426 lpszLibFile));
427
428 hDll = iLoadLibraryA(lpszLibFile);
429 if (hDll == 0)
430 {
431 PSZ pszName;
432
433 // remove path from the image name
434 pszName = strrchr((PSZ)lpszLibFile,
435 '\\');
436 if (pszName != NULL)
437 {
438 pszName++; // skip backslash
439
440 // now try again without fully qualified path
441 hDll = iLoadLibraryA(pszName);
442 }
443 }
444
445 return hDll;
446}
447//******************************************************************************
448//******************************************************************************
449HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
450{
451 Win32Dll *module;
452 HINSTANCE hDll;
453
454 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
455 hDll = O32_LoadLibrary(lpszLibFile);
456 if(hDll) {
457 return hDll; //converted dll or win32k took care of it
458 }
459
460 if(Win32Image::isPEImage((char *)lpszLibFile)) {
461 module = Win32Dll::findModule((char *)lpszLibFile);
462 if(module) {//don't load it again
463 module->AddRef();
464 return module->getInstanceHandle();
465 }
466
467 module = new Win32Dll((char *)lpszLibFile);
468
469 if(module == NULL)
470 return(0);
471
472 module->init(0);
473 if(module->getError() != NO_ERROR) {
474 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
475 delete(module);
476 return(0);
477 }
478 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
479 module->setNoEntryCalls();
480 }
481 if(module->attachProcess() == FALSE) {
482 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
483 delete(module);
484 return(0);
485 }
486 module->AddRef();
487 return module->getInstanceHandle();
488 }
489 return(0);
490}
491//******************************************************************************
492//******************************************************************************
493HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
494{
495 char *asciimodule;
496 HINSTANCE rc;
497
498 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
499 dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
500 rc = LoadLibraryA(asciimodule);
501 free(asciimodule);
502 return(rc);
503}
504//******************************************************************************
505//******************************************************************************
506HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
507{
508 char *asciimodule;
509 HINSTANCE rc;
510
511 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
512 dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
513 rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
514 free(asciimodule);
515 return(rc);
516}
517//******************************************************************************
518//******************************************************************************
519LPCSTR WIN32API GetCommandLineA()
520{
521 LPTSTR cmdline = NULL;
522
523 if(WinExe) {
524 cmdline = WinExe->getCommandLine();
525 }
526 if(cmdline == NULL) //not used for converted exes
527 cmdline = O32_GetCommandLine();
528
529 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
530 dprintf(("KERNEL32: FS = %x\n", GetFS()));
531 return(cmdline);
532}
533//******************************************************************************
534//******************************************************************************
535LPCWSTR WIN32API GetCommandLineW(void)
536{
537 static WCHAR *UnicodeCmdLine = NULL;
538 char *asciicmdline = NULL;
539
540 dprintf(("KERNEL32: FS = %x\n", GetFS()));
541
542 if(UnicodeCmdLine)
543 return(UnicodeCmdLine); //already called before
544
545 if(WinExe) {
546 asciicmdline = WinExe->getCommandLine();
547 }
548 if(asciicmdline == NULL) //not used for converted exes
549 asciicmdline = O32_GetCommandLine();
550
551 if(asciicmdline) {
552 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
553 AsciiToUnicode(asciicmdline, UnicodeCmdLine);
554 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
555 return(UnicodeCmdLine);
556 }
557 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
558 return NULL;
559}
560//******************************************************************************
561//******************************************************************************
562DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
563{
564 DWORD rc;
565 Win32Image *module;
566 char *fpath = NULL;
567
568 dprintf(("GetModuleFileName %X", hinstModule));
569 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
570 module = (Win32Image *)WinExe;
571 }
572 else {
573 module = (Win32Image *)Win32Dll::findModule(hinstModule);
574 }
575
576 if(module) {
577 fpath = module->getFullPath();
578 }
579 if(fpath) {
580 //SvL: 13-9-98: +1
581 rc = min(strlen(fpath)+1, cchPath);
582 strncpy(lpszPath, fpath, rc);
583 }
584 else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
585
586 if(rc) {
587 dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
588 }
589 return(rc);
590}
591//******************************************************************************
592//******************************************************************************
593DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
594{
595 char *asciifilename = (char *)malloc(nSize+1);
596 DWORD rc;
597
598 dprintf(("KERNEL32: OS2GetModuleFileNameW\n"));
599 rc = GetModuleFileNameA(hModule, asciifilename, nSize);
600 if(rc) AsciiToUnicode(asciifilename, lpFileName);
601 free(asciifilename);
602 return(rc);
603}
604//******************************************************************************
605//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
606// very.weird.exe)
607//******************************************************************************
608HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
609{
610 HANDLE hMod;
611 Win32Dll *windll;
612 char szModule[CCHMAXPATH];
613 BOOL fDllModule = FALSE;
614
615 if(lpszModule == NULL) {
616 hMod = WinExe->getInstanceHandle();
617 }
618 else {
619 strcpy(szModule, StripPath((char *)lpszModule));
620 strupr(szModule);
621 if(strstr(szModule, ".DLL")) {
622 fDllModule = TRUE;
623 }
624 else {
625 if(!strstr(szModule, ".")) {
626 //if there's no extension or trainling dot, we
627 //assume it's a dll (see Win32 SDK docs)
628 fDllModule = TRUE;
629 }
630 }
631 char *dot = strstr(szModule, ".");
632 if(dot)
633 *dot = 0;
634
635 if(!fDllModule && !strcmpi(lpszModule, WinExe->getModuleName())) {
636 hMod = WinExe->getInstanceHandle();
637 }
638 else {
639 windll = Win32Dll::findModule(szModule);
640 if(windll) {
641 hMod = windll->getInstanceHandle();
642 }
643 else hMod = OS2iGetModuleHandleA( (PSZ) lpszModule);
644 }
645 }
646
647 eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
648 return(hMod);
649}
650//******************************************************************************
651//******************************************************************************
652HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
653{
654 HMODULE rc;
655 char *astring;
656
657 astring = UnicodeToAsciiString((LPWSTR)arg1);
658 rc = GetModuleHandleA(astring);
659 dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
660 FreeAsciiString(astring);
661 return(rc);
662}
663//******************************************************************************
664//******************************************************************************
665BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
666 PSECURITY_ATTRIBUTES arg3,
667 PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
668 PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
669 LPPROCESS_INFORMATION arg10)
670{
671 BOOL rc;
672 char *cmdline;
673 BOOL fAllocStr = FALSE;
674
675 if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
676 return(TRUE);
677
678 //probably a win32 exe, so run it in the pe loader
679 if(lpszImageName) {
680 if(lpszCommandLine) {
681 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
682 sprintf(cmdline, "%s %s", lpszImageName, lpszCommandLine);
683 fAllocStr = TRUE;
684 }
685 else cmdline = (char *)lpszImageName;
686 }
687 else cmdline = (char *)lpszCommandLine;
688
689 dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
690 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
691 if(fAllocStr)
692 free(cmdline);
693
694 dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
695 return(rc);
696}
697//******************************************************************************
698//******************************************************************************
699BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
700 PSECURITY_ATTRIBUTES arg3,
701 PSECURITY_ATTRIBUTES arg4,
702 BOOL arg5, DWORD arg6, PVOID arg7,
703 LPCWSTR arg8, LPSTARTUPINFOW arg9,
704 LPPROCESS_INFORMATION arg10)
705{
706 BOOL rc;
707 char *astring1, *astring2, *astring3;
708
709 dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
710 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
711 astring2 = UnicodeToAsciiString(arg2);
712 astring3 = UnicodeToAsciiString((LPWSTR)arg8);
713 // NOTE: This will not work as is (needs UNICODE support)
714 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
715 astring3, (LPSTARTUPINFOA)arg9, arg10);
716 FreeAsciiString(astring3);
717 FreeAsciiString(astring2);
718 FreeAsciiString(astring1);
719 return(rc);
720}
721//******************************************************************************
722//******************************************************************************
723FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
724{
725 Win32Dll *winmod;
726 FARPROC proc;
727 ULONG ulAPIOrdinal;
728
729 winmod = Win32Dll::findModule((HINSTANCE)hModule);
730 if(winmod) {
731 ulAPIOrdinal = (ULONG)lpszProc;
732 if (ulAPIOrdinal <= 0x0000FFFF) {
733 return (FARPROC)winmod->getApi((int)ulAPIOrdinal);
734 }
735 else return (FARPROC)winmod->getApi((char *)lpszProc);
736 }
737 proc = O32_GetProcAddress(hModule, lpszProc);
738 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
739 return(proc);
740}
741//******************************************************************************
742//Retrieve the version
743//******************************************************************************
744BOOL SYSTEM GetVersionStruct(char *modname, char *verstruct, ULONG bufLength)
745{
746 HINSTANCE hinstance;
747 Win32Image *winimage;
748
749 dprintf(("GetVersionStruct"));
750 hinstance = OS2QueryModuleHandle(modname);
751 if(hinstance == 0) {
752 dprintf(("GetVersionStruct can't find handle for %s\n", modname));
753 return(FALSE);
754 }
755 if(WinExe && WinExe->getInstanceHandle() == hinstance) {
756 winimage = (Win32Image *)WinExe;
757 }
758 else {
759 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
760 if(winimage == NULL) {
761 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname));
762 return(FALSE);
763 }
764 }
765 if(winimage->getVersionId() == -1) {
766 dprintf(("GetVersionStruct: %s has no version resource!\n", modname));
767 return(FALSE);
768 }
769 return OS2GetResource(hinstance, winimage->getVersionId(), verstruct, bufLength);
770}
771//******************************************************************************
772//******************************************************************************
773ULONG SYSTEM GetVersionSize(char *modname)
774{
775 HINSTANCE hinstance;
776 Win32Image *winimage;
777
778 dprintf(("GetVersionSize of %s\n", modname));
779 hinstance = OS2QueryModuleHandle(modname);
780 if(hinstance == 0) {
781 dprintf(("GetVersionSize can't find handle for %s\n", modname));
782 return(FALSE);
783 }
784
785 if(WinExe && WinExe->getInstanceHandle() == hinstance) {
786 winimage = (Win32Image *)WinExe;
787 }
788 else {
789 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
790 if(winimage == NULL) {
791 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname));
792 return(FALSE);
793 }
794 }
795 if(winimage->getVersionId() == -1) {
796 dprintf(("GetVersionSize: %s has no version resource!\n", modname));
797 return(FALSE);
798 }
799 ULONG size = OS2GetResourceSize(hinstance, winimage->getVersionId());
800
801 dprintf(("Version resource size = %d, id %d\n", size, winimage->getVersionId()));
802 return(size);
803}
804//******************************************************************************
805//******************************************************************************
806
807
808/***********************************************************************
809 * RegisterServiceProcess (KERNEL, KERNEL32)
810 *
811 * A service process calls this function to ensure that it continues to run
812 * even after a user logged off.
813 */
814DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
815 DWORD dwType)
816{
817 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
818 dwProcessId,
819 dwType));
820
821 /* I don't think that Wine needs to do anything in that function */
822 return 1; /* success */
823}
824
Note: See TracBrowser for help on using the repository browser.