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

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

Exception handler changes

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