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

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

Exports for getting THDB & TEB added

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