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

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

Fix: removed debug tracepoint in nested SetWin32TIB

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