source: trunk/src/kernel32/old/wprocess.cpp@ 3830

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

Backup copy of old kernel32

File size: 25.5 KB
Line 
1/* $Id: wprocess.cpp,v 1.1 1999-09-15 23:33:02 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 winexe->start();
237 }
238 else {
239 eprintf(("Win32Exe creation failed!\n"));
240 DebugInt3();
241 return;
242 }
243}
244//******************************************************************************
245//******************************************************************************
246ULONG WIN32API RegisterDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
247 LPDWORD TlsIndexAddr, ULONG TlsInitSize,
248 ULONG TlsTotalSize, LPVOID TlsAddress,
249 LONG Win32TableId, LONG NameTableId, LONG VersionResId,
250 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)
251{
252 char *name;
253
254 Win32Dll *winmod = Win32Dll::findModule(hinstance);
255 if(dwAttachType == 0)
256 { //Process attach
257 if(getenv("WIN32_IOPL2")) {
258 io_init1();
259 }
260 name = OSLibGetDllName(hinstance);
261 CheckVersion(Pe2lxVersion, name);
262
263 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));
264 dprintf(("RegisterDll Win32TableId = %x", Win32TableId));
265 dprintf(("RegisterDll NameTableId = %x", NameTableId));
266 dprintf(("RegisterDll VersionResId = %x", VersionResId));
267 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));
268
269 if(winmod != NULL) {
270 //dll manually loaded by PE loader (Win32Dll::init)
271 winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);
272 }
273 else {
274 //converted win32 dll loaded by OS/2 loader
275 winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
276 if(winmod == NULL) {
277 eprintf(("Failed to allocate module object!\n"));
278 DebugInt3();
279 return 0; //fail dll load
280 }
281 }
282 winmod->setTLSAddress(TlsAddress);
283 winmod->setTLSInitSize(TlsInitSize);
284 winmod->setTLSTotalSize(TlsTotalSize);
285 winmod->setTLSIndexAddr(TlsIndexAddr);
286 winmod->setTLSCallBackAddr(TlsCallbackAddr);
287
288 /* @@@PH 1998/03/17 console devices initialization */
289 iConsoleDevicesRegister();
290
291 //SvL: 19-8-'98
292 winmod->AddRef();
293 winmod->setVersionId(VersionResId);
294
295 winmod->attachProcess();
296 }
297 else {//process detach
298 if(winmod != NULL && !fFreeLibrary) {
299 return 0; //don't unload (OS/2 dll unload bug)
300 }
301 //Runtime environment could already be gone, so don't do this
302 // dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
303 }
304 return 1; //success
305}
306//******************************************************************************
307//******************************************************************************
308void _System Win32DllExitList(ULONG reason)
309{
310 dprintf(("Win32DllExitList %d\n", reason));
311
312 if(WinExe) {
313 delete(WinExe);
314 WinExe = NULL;
315 }
316 return;
317}
318//******************************************************************************
319//******************************************************************************
320VOID WIN32API ExitProcess(DWORD exitcode)
321{
322 dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
323 dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
324
325 SetOS2ExceptionChain(-1);
326
327 //Flush and delete all open memory mapped files
328 Win32MemMap::deleteAll();
329
330 Win32DllExitList(0);
331
332 //Restore original OS/2 TIB selector
333 DestroyTIB();
334 SetExceptionChain((ULONG)-1);
335
336 //avoid crashes since win32 & OS/2 exception handler aren't identical
337 //(terminate process generates two exceptions)
338 /* @@@PH 1998/02/12 Added Console Support */
339 if (iConsoleIsActive())
340 iConsoleWaitClose();
341
342 O32_ExitProcess(exitcode);
343}
344//******************************************************************************
345//******************************************************************************
346BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
347{
348 Win32Dll *winmod;
349 BOOL rc;
350
351 dprintf(("FreeLibrary"));
352 winmod = Win32Dll::findModule(hinstance);
353 if(winmod) {
354 winmod->Release();
355 return(TRUE);
356 }
357 dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance));
358
359 //TODO: Not thread safe
360 fFreeLibrary = TRUE; //ditch dll
361 rc = O32_FreeLibrary(hinstance);
362 fFreeLibrary = FALSE;
363 dprintf(("FreeLibrary returned %X\n", rc));
364 return(TRUE);
365}
366/******************************************************************************/
367/******************************************************************************/
368static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile)
369{
370 char modname[CCHMAXPATH];
371 HINSTANCE hDll;
372 Win32Dll *module;
373
374 hDll = O32_LoadLibrary(lpszLibFile);
375 dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
376 lpszLibFile,
377 hDll,
378 GetLastError()));
379 if(hDll)
380 {
381 return hDll; //converted dll or win32k took care of it
382 }
383
384 strcpy(modname, lpszLibFile);
385 strupr(modname);
386 if(!strstr(modname, ".DLL")) {
387 strcat(modname,".DLL");
388 }
389
390 if(Win32Image::isPEImage((char *)modname)) {
391 module = Win32Dll::findModule((char *)modname);
392 if(module) {//don't load it again
393 module->AddRef();
394 return module->getInstanceHandle();
395 }
396
397 module = new Win32Dll((char *)modname);
398 if(module == NULL)
399 return(0);
400
401 module->init(0);
402 if(module->getError() != NO_ERROR) {
403 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
404 delete(module);
405 return(0);
406 }
407 if(module->attachProcess() == FALSE) {
408 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
409 delete(module);
410 return(0);
411 }
412 module->AddRef();
413 return module->getInstanceHandle();
414 }
415 else
416 return(0);
417}
418
419
420HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
421{
422 HINSTANCE hDll;
423
424 dprintf(("KERNEL32: LoadLibraryA(%s)\n",
425 lpszLibFile));
426
427 hDll = iLoadLibraryA(lpszLibFile);
428 if (hDll == 0)
429 {
430 char * pszName;
431
432 // remove path from the image name
433 pszName = strrchr((char *)lpszLibFile,
434 '\\');
435 if (pszName != NULL)
436 {
437 pszName++; // skip backslash
438
439 // now try again without fully qualified path
440 hDll = iLoadLibraryA(pszName);
441 }
442 }
443
444 return hDll;
445}
446//******************************************************************************
447//******************************************************************************
448HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
449{
450 Win32Dll *module;
451 HINSTANCE hDll;
452
453 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
454 hDll = O32_LoadLibrary(lpszLibFile);
455 if(hDll) {
456 return hDll; //converted dll or win32k took care of it
457 }
458
459 if(Win32Image::isPEImage((char *)lpszLibFile)) {
460 module = Win32Dll::findModule((char *)lpszLibFile);
461 if(module) {//don't load it again
462 module->AddRef();
463 return module->getInstanceHandle();
464 }
465
466 module = new Win32Dll((char *)lpszLibFile);
467
468 if(module == NULL)
469 return(0);
470
471 module->init(0);
472 if(module->getError() != NO_ERROR) {
473 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
474 delete(module);
475 return(0);
476 }
477 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
478 module->setNoEntryCalls();
479 }
480 if(module->attachProcess() == FALSE) {
481 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
482 delete(module);
483 return(0);
484 }
485 module->AddRef();
486 return module->getInstanceHandle();
487 }
488 return(0);
489}
490//******************************************************************************
491//******************************************************************************
492HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
493{
494 char *asciimodule;
495 HINSTANCE rc;
496
497 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
498 dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
499 rc = LoadLibraryA(asciimodule);
500 free(asciimodule);
501 return(rc);
502}
503//******************************************************************************
504//******************************************************************************
505HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
506{
507 char *asciimodule;
508 HINSTANCE rc;
509
510 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
511 dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
512 rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
513 free(asciimodule);
514 return(rc);
515}
516//******************************************************************************
517//******************************************************************************
518LPCSTR WIN32API GetCommandLineA()
519{
520 LPTSTR cmdline = NULL;
521
522 if(WinExe) {
523 cmdline = WinExe->getCommandLine();
524 }
525 if(cmdline == NULL) //not used for converted exes
526 cmdline = O32_GetCommandLine();
527
528 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
529 dprintf(("KERNEL32: FS = %x\n", GetFS()));
530 return(cmdline);
531}
532//******************************************************************************
533//******************************************************************************
534LPCWSTR WIN32API GetCommandLineW(void)
535{
536 static WCHAR *UnicodeCmdLine = NULL;
537 char *asciicmdline = NULL;
538
539 dprintf(("KERNEL32: FS = %x\n", GetFS()));
540
541 if(UnicodeCmdLine)
542 return(UnicodeCmdLine); //already called before
543
544 if(WinExe) {
545 asciicmdline = WinExe->getCommandLine();
546 }
547 if(asciicmdline == NULL) //not used for converted exes
548 asciicmdline = O32_GetCommandLine();
549
550 if(asciicmdline) {
551 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
552 AsciiToUnicode(asciicmdline, UnicodeCmdLine);
553 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
554 return(UnicodeCmdLine);
555 }
556 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
557 return NULL;
558}
559//******************************************************************************
560//******************************************************************************
561DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
562{
563 DWORD rc;
564 Win32Image *module;
565 char *fpath = NULL;
566
567 dprintf(("GetModuleFileName %X", hinstModule));
568 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
569 module = (Win32Image *)WinExe;
570 }
571 else {
572 module = (Win32Image *)Win32Dll::findModule(hinstModule);
573 }
574
575 if(module) {
576 fpath = module->getFullPath();
577 }
578 if(fpath) {
579 //SvL: 13-9-98: +1
580 rc = min(strlen(fpath)+1, cchPath);
581 strncpy(lpszPath, fpath, rc);
582 }
583 else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
584
585 if(rc) {
586 dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
587 }
588 return(rc);
589}
590//******************************************************************************
591//******************************************************************************
592DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
593{
594 char *asciifilename = (char *)malloc(nSize+1);
595 DWORD rc;
596
597 dprintf(("KERNEL32: OSLibGetModuleFileNameW\n"));
598 rc = GetModuleFileNameA(hModule, asciifilename, nSize);
599 if(rc) AsciiToUnicode(asciifilename, lpFileName);
600 free(asciifilename);
601 return(rc);
602}
603//******************************************************************************
604//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
605// very.weird.exe)
606//******************************************************************************
607HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
608{
609 HANDLE hMod;
610 Win32Dll *windll;
611 char szModule[CCHMAXPATH];
612 BOOL fDllModule = FALSE;
613
614 if(lpszModule == NULL) {
615 hMod = WinExe->getInstanceHandle();
616 }
617 else {
618 strcpy(szModule, OSLibStripPath((char *)lpszModule));
619 strupr(szModule);
620 if(strstr(szModule, ".DLL")) {
621 fDllModule = TRUE;
622 }
623 else {
624 if(!strstr(szModule, ".")) {
625 //if there's no extension or trainling dot, we
626 //assume it's a dll (see Win32 SDK docs)
627 fDllModule = TRUE;
628 }
629 }
630 char *dot = strstr(szModule, ".");
631 if(dot)
632 *dot = 0;
633
634 if(!fDllModule && !strcmpi(lpszModule, WinExe->getModuleName())) {
635 hMod = WinExe->getInstanceHandle();
636 }
637 else {
638 windll = Win32Dll::findModule(szModule);
639 if(windll) {
640 hMod = windll->getInstanceHandle();
641 }
642 else hMod = OSLibiGetModuleHandleA((char *)lpszModule);
643 }
644 }
645
646 eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
647 return(hMod);
648}
649//******************************************************************************
650//******************************************************************************
651HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
652{
653 HMODULE rc;
654 char *astring;
655
656 astring = UnicodeToAsciiString((LPWSTR)arg1);
657 rc = GetModuleHandleA(astring);
658 dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
659 FreeAsciiString(astring);
660 return(rc);
661}
662//******************************************************************************
663//******************************************************************************
664BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
665 PSECURITY_ATTRIBUTES arg3,
666 PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
667 PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
668 LPPROCESS_INFORMATION arg10)
669{
670 BOOL rc;
671 char *cmdline;
672 BOOL fAllocStr = FALSE;
673
674 if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
675 return(TRUE);
676
677 //probably a win32 exe, so run it in the pe loader
678 if(lpszImageName) {
679 if(lpszCommandLine) {
680 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
681 sprintf(cmdline, "%s %s", lpszImageName, lpszCommandLine);
682 fAllocStr = TRUE;
683 }
684 else cmdline = (char *)lpszImageName;
685 }
686 else cmdline = (char *)lpszCommandLine;
687
688 dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
689 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
690 if(fAllocStr)
691 free(cmdline);
692
693 dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
694 return(rc);
695}
696//******************************************************************************
697//******************************************************************************
698BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
699 PSECURITY_ATTRIBUTES arg3,
700 PSECURITY_ATTRIBUTES arg4,
701 BOOL arg5, DWORD arg6, PVOID arg7,
702 LPCWSTR arg8, LPSTARTUPINFOW arg9,
703 LPPROCESS_INFORMATION arg10)
704{
705 BOOL rc;
706 char *astring1, *astring2, *astring3;
707
708 dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
709 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
710 astring2 = UnicodeToAsciiString(arg2);
711 astring3 = UnicodeToAsciiString((LPWSTR)arg8);
712 // NOTE: This will not work as is (needs UNICODE support)
713 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
714 astring3, (LPSTARTUPINFOA)arg9, arg10);
715 FreeAsciiString(astring3);
716 FreeAsciiString(astring2);
717 FreeAsciiString(astring1);
718 return(rc);
719}
720//******************************************************************************
721//******************************************************************************
722FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
723{
724 Win32Dll *winmod;
725 FARPROC proc;
726 ULONG ulAPIOrdinal;
727
728 winmod = Win32Dll::findModule((HINSTANCE)hModule);
729 if(winmod) {
730 ulAPIOrdinal = (ULONG)lpszProc;
731 if (ulAPIOrdinal <= 0x0000FFFF) {
732 return (FARPROC)winmod->getApi((int)ulAPIOrdinal);
733 }
734 else return (FARPROC)winmod->getApi((char *)lpszProc);
735 }
736 proc = O32_GetProcAddress(hModule, lpszProc);
737 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
738 return(proc);
739}
740//******************************************************************************
741//Retrieve the version
742//******************************************************************************
743BOOL SYSTEM GetVersionStruct(char *modname, char *verstruct, ULONG bufLength)
744{
745 HINSTANCE hinstance;
746 Win32Image *winimage;
747
748 dprintf(("GetVersionStruct"));
749 hinstance = OSLibQueryModuleHandle(modname);
750 if(hinstance == 0) {
751 dprintf(("GetVersionStruct can't find handle for %s\n", modname));
752 return(FALSE);
753 }
754 if(WinExe && WinExe->getInstanceHandle() == hinstance) {
755 winimage = (Win32Image *)WinExe;
756 }
757 else {
758 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
759 if(winimage == NULL) {
760 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname));
761 return(FALSE);
762 }
763 }
764 if(winimage->getVersionId() == -1) {
765 dprintf(("GetVersionStruct: %s has no version resource!\n", modname));
766 return(FALSE);
767 }
768 return OSLibGetResource(hinstance, winimage->getVersionId(), verstruct, bufLength);
769}
770//******************************************************************************
771//******************************************************************************
772ULONG SYSTEM GetVersionSize(char *modname)
773{
774 HINSTANCE hinstance;
775 Win32Image *winimage;
776
777 dprintf(("GetVersionSize of %s\n", modname));
778 hinstance = OSLibQueryModuleHandle(modname);
779 if(hinstance == 0) {
780 dprintf(("GetVersionSize can't find handle for %s\n", modname));
781 return(FALSE);
782 }
783
784 if(WinExe && WinExe->getInstanceHandle() == hinstance) {
785 winimage = (Win32Image *)WinExe;
786 }
787 else {
788 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
789 if(winimage == NULL) {
790 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname));
791 return(FALSE);
792 }
793 }
794 if(winimage->getVersionId() == -1) {
795 dprintf(("GetVersionSize: %s has no version resource!\n", modname));
796 return(FALSE);
797 }
798 ULONG size = OSLibGetResourceSize(hinstance, winimage->getVersionId());
799
800 dprintf(("Version resource size = %d, id %d\n", size, winimage->getVersionId()));
801 return(size);
802}
803//******************************************************************************
804//******************************************************************************
805
806
807/***********************************************************************
808 * RegisterServiceProcess (KERNEL, KERNEL32)
809 *
810 * A service process calls this function to ensure that it continues to run
811 * even after a user logged off.
812 */
813DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
814 DWORD dwType)
815{
816 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
817 dwProcessId,
818 dwType));
819
820 /* I don't think that Wine needs to do anything in that function */
821 return 1; /* success */
822}
823
Note: See TracBrowser for help on using the repository browser.