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

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

PE loader changes (exes without fixups + TLS support)

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