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

Last change on this file since 669 was 669, checked in by phaller, 26 years ago

Fix: ExitProcess: restore OS/2 TIB a little earlier, before console closes

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