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

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

Cleanup

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