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

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

Fix: fixes and updates for ODINCRT support

File size: 23.9 KB
Line 
1/* $Id: wprocess.cpp,v 1.17 1999-08-09 22:10:09 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#include <odincrt.h>
17
18#include "unicode.h"
19#include "windll.h"
20#include "winexe.h"
21
22#ifdef __IBMCPP__
23#include <builtin.h>
24#endif
25
26#include "except.h"
27#include "os2util.h"
28
29#include "console.h"
30#include "cio.h"
31#include "versionos2.h" /*PLF Wed 98-03-18 02:36:51*/
32#include <wprocess.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//******************************************************************************
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 ODIN_delete(WinExe);
210
211
212 CheckVersion(Pe2lxVersion, OS2GetDllName(hinstance));
213
214 if(getenv("WIN32_IOPL2")) {
215 io_init1();
216 }
217
218 //SvL: Use 0 instead of the real instance handle (for resource lookup)
219 Win32Exe *winexe;
220
221 ODIN_FS_BEGIN
222 winexe = new Win32Exe(0, NameTableId, Win32TableId);
223 ODIN_FS_END
224
225 if(winexe) {
226 dprintf(("RegisterExe Win32TableId = %x", Win32TableId));
227 dprintf(("RegisterExe NameTableId = %x", NameTableId));
228 dprintf(("RegisterExe VersionResId = %x", VersionResId));
229 dprintf(("RegisterExe Pe2lxVersion = %x", Pe2lxVersion));
230
231 winexe->setVersionId(VersionResId);
232 winexe->setOS2InstanceHandle(hinstance);
233 winexe->setEntryPoint((ULONG)EntryPoint);
234 winexe->setTLSAddress(TlsAddress);
235 winexe->setTLSInitSize(TlsInitSize);
236 winexe->setTLSTotalSize(TlsTotalSize);
237 winexe->setTLSIndexAddr(TlsIndexAddr);
238 winexe->setTLSCallBackAddr(TlsCallbackAddr);
239
240 char *modname = getenv("WIN32MODULE");
241
242 if(modname != NULL)
243 {
244 dprintf(("Set full path for exe to %s", modname));
245 winexe->setFullPath(modname);
246 }
247 winexe->start();
248 }
249 else {
250 eprintf(("Win32Exe creation failed!\n"));
251 DebugInt3();
252 return;
253 }
254}
255//******************************************************************************
256//******************************************************************************
257ULONG WIN32API RegisterDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
258 LPDWORD TlsIndexAddr, ULONG TlsInitSize,
259 ULONG TlsTotalSize, LPVOID TlsAddress,
260 LONG Win32TableId, LONG NameTableId, LONG VersionResId,
261 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)
262{
263 char *name;
264
265 Win32Dll *winmod = Win32Dll::findModule(hinstance);
266 if(dwAttachType == 0)
267 { //Process attach
268 if(getenv("WIN32_IOPL2")) {
269 io_init1();
270 }
271 name = OS2GetDllName(hinstance);
272 CheckVersion(Pe2lxVersion, name);
273
274 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));
275 dprintf(("RegisterDll Win32TableId = %x", Win32TableId));
276 dprintf(("RegisterDll NameTableId = %x", NameTableId));
277 dprintf(("RegisterDll VersionResId = %x", VersionResId));
278 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));
279
280 if(winmod != NULL) {
281 //dll manually loaded by PE loader (Win32Dll::init)
282 winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);
283 }
284 else {
285 //converted win32 dll loaded by OS/2 loader
286 ODIN_FS_BEGIN
287 winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
288 ODIN_FS_END
289 if(winmod == NULL) {
290 eprintf(("Failed to allocate module object!\n"));
291 DebugInt3();
292 return 0; //fail dll load
293 }
294 }
295 winmod->setTLSAddress(TlsAddress);
296 winmod->setTLSInitSize(TlsInitSize);
297 winmod->setTLSTotalSize(TlsTotalSize);
298 winmod->setTLSIndexAddr(TlsIndexAddr);
299 winmod->setTLSCallBackAddr(TlsCallbackAddr);
300
301 /* @@@PH 1998/03/17 console devices initialization */
302 iConsoleDevicesRegister();
303
304 //SvL: 19-8-'98
305 winmod->AddRef();
306 winmod->setVersionId(VersionResId);
307
308 winmod->attachProcess();
309 }
310 else {//process detach
311 if(winmod != NULL && !fFreeLibrary) {
312 return 0; //don't unload (OS/2 dll unload bug)
313 }
314//Runtime environment could already be gone, so don't do this
315// dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
316 }
317 return 1; //success
318}
319//******************************************************************************
320//******************************************************************************
321void _System Win32DllExitList(ULONG reason)
322{
323 dprintf(("Win32DllExitList %d\n", reason));
324
325 if(WinExe) {
326 ODIN_delete(WinExe);
327 WinExe = NULL;
328 }
329 return;
330}
331//******************************************************************************
332//******************************************************************************
333VOID WIN32API ExitProcess(DWORD exitcode)
334{
335 dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
336 dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
337
338 //avoid crashes since win32 & OS/2 exception handler aren't identical
339 //(terminate process generates two exceptions)
340 /* @@@PH 1998/02/12 Added Console Support */
341 if (iConsoleIsActive())
342 iConsoleWaitClose();
343
344 Win32DllExitList(0);
345
346 //Restore original OS/2 TIB selector
347 DestroyTIB();
348 SetExceptionChain((ULONG)-1);
349
350 O32_ExitProcess(exitcode);
351}
352//******************************************************************************
353//******************************************************************************
354BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
355{
356 Win32Dll *winmod;
357 BOOL rc;
358
359 dprintf(("FreeLibrary"));
360 winmod = Win32Dll::findModule(hinstance);
361 if(winmod) {
362 winmod->Release();
363 return(TRUE);
364 }
365 dprintf(("KERNEL32: FreeLibrary %s %X\n", OS2GetDllName(hinstance), hinstance));
366
367 //TODO: Not thread safe
368 fFreeLibrary = TRUE; //ditch dll
369 rc = O32_FreeLibrary(hinstance);
370 fFreeLibrary = FALSE;
371 dprintf(("FreeLibrary returned %X\n", rc));
372 return(TRUE);
373}
374/******************************************************************************/
375/******************************************************************************/
376static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile)
377{
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 if(Win32Image::isPEImage((char *)lpszLibFile)) {
392 module = Win32Dll::findModule((char *)lpszLibFile);
393 if(module) {//don't load it again
394 module->AddRef();
395 return module->getInstanceHandle();
396 }
397
398 ODIN_FS_BEGIN
399 module = new Win32Dll((char *)lpszLibFile);
400 ODIN_FS_END
401 if(module == NULL)
402 return(0);
403
404 module->init();
405 if(module->getError() != NO_ERROR) {
406 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
407 ODIN_delete(module);
408 return(0);
409 }
410 if(module->attachProcess() == FALSE) {
411 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
412 ODIN_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
451//******************************************************************************
452//******************************************************************************
453HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
454{
455 Win32Dll *module;
456 HINSTANCE hDll;
457
458 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
459 hDll = O32_LoadLibrary(lpszLibFile);
460 if(hDll) {
461 return hDll; //converted dll or win32k took care of it
462 }
463
464 if(Win32Image::isPEImage((char *)lpszLibFile)) {
465 module = Win32Dll::findModule((char *)lpszLibFile);
466 if(module) {//don't load it again
467 module->AddRef();
468 return module->getInstanceHandle();
469 }
470
471 ODIN_FS_BEGIN
472 module = new Win32Dll((char *)lpszLibFile);
473 ODIN_FS_END
474
475 if(module == NULL)
476 return(0);
477
478 module->init();
479 if(module->getError() != NO_ERROR) {
480 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
481 ODIN_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 ODIN_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->getOS2InstanceHandle())) {
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: OS2GetModuleFileNameW\n"));
605 rc = GetModuleFileNameA(hModule, asciifilename, nSize);
606 if(rc) AsciiToUnicode(asciifilename, lpFileName);
607 free(asciifilename);
608 return(rc);
609}
610//******************************************************************************
611//******************************************************************************
612BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
613 PSECURITY_ATTRIBUTES arg3,
614 PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
615 PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
616 LPPROCESS_INFORMATION arg10)
617{
618 BOOL rc;
619 char *cmdline;
620 BOOL fAllocStr = FALSE;
621
622 if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
623 return(TRUE);
624
625 //probably a win32 exe, so run it in the pe loader
626 if(lpszImageName) {
627 if(lpszCommandLine) {
628 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
629 sprintf(cmdline, "%s %s", lpszImageName, lpszCommandLine);
630 fAllocStr = TRUE;
631 }
632 else cmdline = (char *)lpszImageName;
633 }
634 else cmdline = (char *)lpszCommandLine;
635
636 dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
637 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
638 if(fAllocStr)
639 free(cmdline);
640
641 dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
642 return(rc);
643}
644//******************************************************************************
645//******************************************************************************
646BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
647 PSECURITY_ATTRIBUTES arg3,
648 PSECURITY_ATTRIBUTES arg4,
649 BOOL arg5, DWORD arg6, PVOID arg7,
650 LPCWSTR arg8, LPSTARTUPINFOW arg9,
651 LPPROCESS_INFORMATION arg10)
652{
653 BOOL rc;
654 char *astring1, *astring2, *astring3;
655
656 dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
657 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
658 astring2 = UnicodeToAsciiString(arg2);
659 astring3 = UnicodeToAsciiString((LPWSTR)arg8);
660 // NOTE: This will not work as is (needs UNICODE support)
661 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
662 astring3, (LPSTARTUPINFOA)arg9, arg10);
663 FreeAsciiString(astring3);
664 FreeAsciiString(astring2);
665 FreeAsciiString(astring1);
666 return(rc);
667}
668//******************************************************************************
669//******************************************************************************
670FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
671{
672 Win32Dll *winmod;
673 FARPROC proc;
674 ULONG ulAPIOrdinal;
675
676 winmod = Win32Dll::findModule((HINSTANCE)hModule);
677 if(winmod) {
678 ulAPIOrdinal = (ULONG)lpszProc;
679 if (ulAPIOrdinal <= 0x0000FFFF) {
680 return (FARPROC)winmod->getApi((int)ulAPIOrdinal);
681 }
682 else return (FARPROC)winmod->getApi((char *)lpszProc);
683 }
684 proc = O32_GetProcAddress(hModule, lpszProc);
685 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
686 return(proc);
687}
688//******************************************************************************
689//Retrieve the version
690//******************************************************************************
691BOOL SYSTEM GetVersionStruct(char *modname, char *verstruct, ULONG bufLength)
692{
693 HINSTANCE hinstance;
694 Win32Image *winimage;
695
696 dprintf(("GetVersionStruct"));
697 hinstance = OS2QueryModuleHandle(modname);
698 if(hinstance == 0) {
699 dprintf(("GetVersionStruct can't find handle for %s\n", modname));
700 return(FALSE);
701 }
702 if(WinExe && WinExe->getOS2InstanceHandle() == hinstance) {
703 winimage = (Win32Image *)WinExe;
704 }
705 else {
706 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
707 if(winimage == NULL) {
708 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname));
709 return(FALSE);
710 }
711 }
712 if(winimage->getVersionId() == -1) {
713 dprintf(("GetVersionStruct: %s has no version resource!\n", modname));
714 return(FALSE);
715 }
716 return OS2GetResource(hinstance, winimage->getVersionId(), verstruct, bufLength);
717}
718//******************************************************************************
719//******************************************************************************
720ULONG SYSTEM GetVersionSize(char *modname)
721{
722 HINSTANCE hinstance;
723 Win32Image *winimage;
724
725 dprintf(("GetVersionSize of %s\n", modname));
726 hinstance = OS2QueryModuleHandle(modname);
727 if(hinstance == 0) {
728 dprintf(("GetVersionSize can't find handle for %s\n", modname));
729 return(FALSE);
730 }
731
732 if(WinExe && WinExe->getOS2InstanceHandle() == hinstance) {
733 winimage = (Win32Image *)WinExe;
734 }
735 else {
736 winimage = (Win32Image *)Win32Dll::findModule(hinstance);
737 if(winimage == NULL) {
738 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname));
739 return(FALSE);
740 }
741 }
742 if(winimage->getVersionId() == -1) {
743 dprintf(("GetVersionSize: %s has no version resource!\n", modname));
744 return(FALSE);
745 }
746 ULONG size = OS2GetResourceSize(hinstance, winimage->getVersionId());
747
748 dprintf(("Version resource size = %d, id %d\n", size, winimage->getVersionId()));
749 return(size);
750}
751//******************************************************************************
752//******************************************************************************
753
754
755/***********************************************************************
756 * RegisterServiceProcess (KERNEL, KERNEL32)
757 *
758 * A service process calls this function to ensure that it continues to run
759 * even after a user logged off.
760 */
761DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
762 DWORD dwType)
763{
764 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
765 dwProcessId,
766 dwType));
767
768 /* I don't think that Wine needs to do anything in that function */
769 return 1; /* success */
770}
771
Note: See TracBrowser for help on using the repository browser.