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

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

Color cursor changes + dll loading fixes

File size: 24.6 KB
Line 
1/* $Id: wprocess.cpp,v 1.42 1999-10-27 10:35:42 sandervl Exp $ */
2
3/*
4 * Win32 process functions
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
10 * we still allocate a TEB to store misc information.
11 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 */
15#include <odin.h>
16#include <odinwrap.h>
17#include <os2win.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include <unicode.h>
23#include <windllbase.h>
24#include <winexebase.h>
25#include <windllpeldr.h>
26#include <winfakepeldr.h>
27
28#ifdef __IBMCPP__
29#include <builtin.h>
30#endif
31
32#include "exceptutil.h"
33#include "oslibmisc.h"
34
35#include "console.h"
36#include "cio.h"
37#include "versionos2.h" /*PLF Wed 98-03-18 02:36:51*/
38#include <wprocess.h>
39#include "mmap.h"
40
41
42ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
43
44
45//******************************************************************************
46//******************************************************************************
47BOOL fFreeLibrary = FALSE;
48BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!)
49 //FALSE -> otherwise
50//Process database
51PDB ProcessPDB = {0};
52USHORT ProcessTIBSel = 0;
53DWORD *TIBFlatPtr = 0;
54
55//******************************************************************************
56//******************************************************************************
57TEB *WIN32API GetThreadTEB()
58{
59 return (TEB *)*TIBFlatPtr;
60}
61//******************************************************************************
62//******************************************************************************
63THDB *WIN32API GetThreadTHDB()
64{
65 TEB *winteb;
66 THDB *thdb;
67
68 winteb = (TEB *)*TIBFlatPtr;
69 if(winteb == NULL) {
70 return NULL;
71 }
72 thdb = (THDB *)(winteb+1);
73
74 return thdb;
75}
76//******************************************************************************
77// Set up the TIB selector and memory for the current thread
78//******************************************************************************
79TEB *InitializeTIB(BOOL fMainThread)
80{
81 TEB *winteb;
82 THDB *thdb;
83
84 USHORT tibsel;
85
86 //Allocate one dword to store the flat address of our TEB
87 if(fMainThread) {
88 TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1);
89 if(TIBFlatPtr == 0) {
90 dprintf(("InitializeTIB: local thread memory alloc failed!!"));
91 DebugInt3();
92 return NULL;
93 }
94 }
95 if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE)
96 {
97 dprintf(("InitializeTIB: selector alloc failed!!"));
98 DebugInt3();
99 return NULL;
100 }
101 winteb = (TEB *)OSLibSelToFlat(tibsel);
102 if(winteb == NULL)
103 {
104 dprintf(("InitializeTIB: DosSelToFlat failed!!"));
105 DebugInt3();
106 return NULL;
107 }
108 memset(winteb, 0, PAGE_SIZE);
109 thdb = (THDB *)(winteb+1);
110 *TIBFlatPtr = (DWORD)winteb;
111
112 winteb->except = (PVOID)-1; /* 00 Head of exception handling chain */
113 winteb->stack_top = (PVOID)OSLibGetTIB(TIB_STACKTOP); /* 04 Top of thread stack */
114 winteb->stack_low = (PVOID)OSLibGetTIB(TIB_STACKLOW); /* 08 Stack low-water mark */
115 winteb->htask16 = (USHORT)OSLibGetPIB(PIB_TASKHNDL); /* 0c Win16 task handle */
116 winteb->stack_sel = getSS(); /* 0e 16-bit stack selector */
117 winteb->self = winteb; /* 18 Pointer to this structure */
118 winteb->flags = TEBF_WIN32; /* 1c Flags */
119 winteb->queue = 0; /* 28 Message queue */
120 winteb->tls_ptr = &thdb->tls_array[0]; /* 2c Pointer to TLS array */
121 winteb->process = &ProcessPDB; /* 30 owning process (used by NT3.51 applets)*/
122
123 memcpy(&thdb->teb, winteb, sizeof(TEB));
124 thdb->process = &ProcessPDB;
125 thdb->exit_code = 0x103; /* STILL_ACTIVE */
126 thdb->teb_sel = tibsel;
127 thdb->OrgTIBSel = GetFS();
128
129 if(OSLibGetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
130 {
131 thdb->flags = 0; //todo gui
132 }
133 else thdb->flags = 0; //todo textmode
134
135 if(fMainThread)
136 {
137 //todo initialize PDB during process creation
138 //todo: initialize TLS array if required
139 //TLS in executable always TLS index 0?
140 ProcessTIBSel = tibsel;
141 }
142 dprintf(("InitializeTIB setup TEB with selector %x", tibsel));
143 dprintf(("InitializeTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
144 return winteb;
145}
146//******************************************************************************
147// Destroy the TIB selector and memory for the current thread
148//******************************************************************************
149void DestroyTIB()
150{
151 SHORT orgtibsel;
152 TEB *winteb;
153 THDB *thdb;
154
155 dprintf(("DestroyTIB: FS = %x", GetFS()));
156 dprintf(("DestroyTIB: FS:[0] = %x", QueryExceptionChain()));
157
158 winteb = (TEB *)*TIBFlatPtr;
159 if(winteb) {
160 thdb = (THDB *)(winteb+1);
161 orgtibsel = thdb->OrgTIBSel;
162
163 //Restore our original FS selector
164 SetFS(orgtibsel);
165
166 //And free our own
167 OSLibFreeSel(thdb->teb_sel);
168 }
169 else dprintf(("Already destroyed TIB"));
170
171 dprintf(("DestroyTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
172 *TIBFlatPtr = 0;
173 return;
174}
175/******************************************************************************/
176/******************************************************************************/
177void WIN32API RestoreOS2TIB()
178{
179 SHORT orgtibsel;
180 TEB *winteb;
181 THDB *thdb;
182
183 //If we're running an Odin32 OS/2 application (not converted!), then we
184 //we don't switch FS selectors
185 if(fIsOS2Image) {
186 return;
187 }
188
189 winteb = (TEB *)*TIBFlatPtr;
190 if(winteb) {
191 thdb = (THDB *)(winteb+1);
192 orgtibsel = thdb->OrgTIBSel;
193
194 //Restore our original FS selector
195 SetFS(orgtibsel);
196 }
197}
198/******************************************************************************/
199/******************************************************************************/
200USHORT WIN32API SetWin32TIB()
201{
202 SHORT win32tibsel;
203 TEB *winteb;
204 THDB *thdb;
205
206 //If we're running an Odin32 OS/2 application (not converted!), then we
207 //we don't switch FS selectors
208 if(fIsOS2Image) {
209 return GetFS();
210 }
211
212 winteb = (TEB *)*TIBFlatPtr;
213 if(winteb) {
214 thdb = (THDB *)(winteb+1);
215 win32tibsel = thdb->teb_sel;
216
217 //Restore our win32 FS selector
218 return SetReturnFS(win32tibsel);
219 }
220 else {
221 //we didn't create this thread, so allocate a selector now
222 //NOTE: Possible memory leak (i.e. DART threads in WINMM)
223 winteb = InitializeTIB();
224 if(winteb == NULL) {
225 DebugInt3();
226 return GetFS();
227 }
228 thdb = (THDB *)(winteb+1);
229 win32tibsel = thdb->teb_sel;
230
231 //Restore our win32 FS selector
232 return SetReturnFS(win32tibsel);
233 }
234 // nested calls are OK, OS2ToWinCallback for instance
235 //else DebugInt3();
236
237 return GetFS();
238}
239//******************************************************************************
240//******************************************************************************
241void _System Win32DllExitList(ULONG reason)
242{
243 dprintf(("Win32DllExitList %d\n", reason));
244
245 if(WinExe) {
246 delete(WinExe);
247 WinExe = NULL;
248 }
249 return;
250}
251//******************************************************************************
252//******************************************************************************
253VOID WIN32API ExitProcess(DWORD exitcode)
254{
255 dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
256 dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
257
258 SetOS2ExceptionChain(-1);
259
260 //Flush and delete all open memory mapped files
261 Win32MemMap::deleteAll();
262
263 Win32DllExitList(0);
264
265 //Restore original OS/2 TIB selector
266 DestroyTIB();
267 SetExceptionChain((ULONG)-1);
268
269 //avoid crashes since win32 & OS/2 exception handler aren't identical
270 //(terminate process generates two exceptions)
271 /* @@@PH 1998/02/12 Added Console Support */
272 if (iConsoleIsActive())
273 iConsoleWaitClose();
274
275 O32_ExitProcess(exitcode);
276}
277//******************************************************************************
278//******************************************************************************
279BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
280{
281 Win32DllBase *winmod;
282 BOOL rc;
283
284 dprintf(("FreeLibrary"));
285 winmod = Win32DllBase::findModule(hinstance);
286 if(winmod) {
287 winmod->Release();
288 return(TRUE);
289 }
290 dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance));
291
292 //TODO: Not thread safe
293 fFreeLibrary = TRUE; //ditch dll
294 rc = O32_FreeLibrary(hinstance);
295 fFreeLibrary = FALSE;
296 dprintf(("FreeLibrary returned %X\n", rc));
297 return(TRUE);
298}
299/******************************************************************************/
300/******************************************************************************/
301static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile, DWORD dwFlags)
302{
303 char modname[CCHMAXPATH];
304 HINSTANCE hDll;
305 Win32DllBase *module;
306
307 module = Win32DllBase::findModule((LPSTR)lpszLibFile);
308 if(module) {
309 module->AddRef();
310 return module->getInstanceHandle();
311 }
312
313 hDll = O32_LoadLibrary(lpszLibFile);
314 dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
315 lpszLibFile,
316 hDll,
317 GetLastError()));
318 if(hDll)
319 {
320 return hDll; //converted dll or win32k took care of it
321 }
322
323 strcpy(modname, lpszLibFile);
324 strupr(modname);
325 if(!strstr(modname, ".")) {
326 strcat(modname,".DLL");
327 }
328
329 if(Win32ImageBase::isPEImage((char *)modname))
330 {
331 module = Win32DllBase::findModule((char *)modname);
332 if(module) {//don't load it again
333 module->AddRef();
334 return module->getInstanceHandle();
335 }
336
337 Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname);
338 if(peldrDll == NULL)
339 return(0);
340
341 peldrDll->init(0);
342 if(peldrDll->getError() != NO_ERROR) {
343 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
344 delete(peldrDll);
345 return(0);
346 }
347 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
348 peldrDll->setNoEntryCalls();
349 }
350
351 if(peldrDll->attachProcess() == FALSE) {
352 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
353 delete(peldrDll);
354 return(0);
355 }
356 peldrDll->AddRef();
357 return peldrDll->getInstanceHandle();
358 }
359 else return(0);
360}
361//******************************************************************************
362//******************************************************************************
363HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
364{
365 HINSTANCE hDll;
366
367 dprintf(("KERNEL32: LoadLibraryA(%s)\n",
368 lpszLibFile));
369 dprintf(("KERNEL32: LoadLibrary FS = %x\n", GetFS()));
370
371 hDll = iLoadLibraryA(lpszLibFile, 0);
372 if (hDll == 0)
373 {
374 char * pszName;
375
376 // remove path from the image name
377 pszName = strrchr((char *)lpszLibFile,
378 '\\');
379 if (pszName != NULL)
380 {
381 pszName++; // skip backslash
382
383 // now try again without fully qualified path
384 hDll = iLoadLibraryA(pszName, 0);
385 }
386 }
387
388 return hDll;
389}
390//******************************************************************************
391//******************************************************************************
392HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
393{
394 HINSTANCE hDll;
395
396 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
397 hDll = iLoadLibraryA(lpszLibFile, dwFlags);
398 if (hDll == 0)
399 {
400 char * pszName;
401
402 // remove path from the image name
403 pszName = strrchr((char *)lpszLibFile,
404 '\\');
405 if (pszName != NULL)
406 {
407 pszName++; // skip backslash
408
409 // now try again without fully qualified path
410 hDll = iLoadLibraryA(pszName, dwFlags);
411 }
412 }
413
414 return hDll;
415}
416//******************************************************************************
417//******************************************************************************
418HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
419{
420 char *asciimodule;
421 HINSTANCE rc;
422
423 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
424 dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
425 rc = LoadLibraryA(asciimodule);
426 free(asciimodule);
427 return(rc);
428}
429//******************************************************************************
430//******************************************************************************
431HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
432{
433 char *asciimodule;
434 HINSTANCE rc;
435
436 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
437 dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
438 rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
439 free(asciimodule);
440 return(rc);
441}
442//******************************************************************************
443//******************************************************************************
444LPCSTR WIN32API GetCommandLineA()
445{
446 LPTSTR cmdline = NULL;
447
448 if(WinExe) {
449 cmdline = WinExe->getCommandLine();
450 }
451 if(cmdline == NULL) //not used for converted exes
452 cmdline = O32_GetCommandLine();
453
454 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
455 dprintf(("KERNEL32: FS = %x\n", GetFS()));
456 return(cmdline);
457}
458//******************************************************************************
459//******************************************************************************
460LPCWSTR WIN32API GetCommandLineW(void)
461{
462 static WCHAR *UnicodeCmdLine = NULL;
463 char *asciicmdline = NULL;
464
465 dprintf(("KERNEL32: FS = %x\n", GetFS()));
466
467 if(UnicodeCmdLine)
468 return(UnicodeCmdLine); //already called before
469
470 if(WinExe) {
471 asciicmdline = WinExe->getCommandLine();
472 }
473 if(asciicmdline == NULL) //not used for converted exes
474 asciicmdline = O32_GetCommandLine();
475
476 if(asciicmdline) {
477 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
478 AsciiToUnicode(asciicmdline, UnicodeCmdLine);
479 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
480 return(UnicodeCmdLine);
481 }
482 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
483 return NULL;
484}
485//******************************************************************************
486//******************************************************************************
487DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
488{
489 DWORD rc;
490 Win32ImageBase *module;
491 char *fpath = NULL;
492
493 dprintf(("GetModuleFileName %X", hinstModule));
494 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
495 module = (Win32ImageBase *)WinExe;
496 }
497 else {
498 module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule);
499 }
500
501 if(module) {
502 fpath = module->getFullPath();
503 }
504 if(fpath) {
505 //SvL: 13-9-98: +1
506 rc = min(strlen(fpath)+1, cchPath);
507 strncpy(lpszPath, fpath, rc);
508 }
509 else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
510
511 if(rc) {
512 dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
513 }
514 return(rc);
515}
516//******************************************************************************
517//******************************************************************************
518DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
519{
520 char *asciifilename = (char *)malloc(nSize+1);
521 DWORD rc;
522
523 dprintf(("KERNEL32: OSLibGetModuleFileNameW\n"));
524 rc = GetModuleFileNameA(hModule, asciifilename, nSize);
525 if(rc) AsciiToUnicode(asciifilename, lpFileName);
526 free(asciifilename);
527 return(rc);
528}
529//******************************************************************************
530//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
531// very.weird.exe)
532//******************************************************************************
533HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
534{
535 HANDLE hMod;
536 Win32DllBase *windll;
537 char szModule[CCHMAXPATH];
538 BOOL fDllModule = FALSE;
539
540 if(lpszModule == NULL) {
541 if(WinExe)
542 hMod = WinExe->getInstanceHandle();
543 else hMod = -1;
544 }
545 else {
546 strcpy(szModule, OSLibStripPath((char *)lpszModule));
547 strupr(szModule);
548 if(strstr(szModule, ".DLL")) {
549 fDllModule = TRUE;
550 }
551 else {
552 if(!strstr(szModule, ".")) {
553 //if there's no extension or trainling dot, we
554 //assume it's a dll (see Win32 SDK docs)
555 fDllModule = TRUE;
556 }
557 }
558 char *dot = strstr(szModule, ".");
559 if(dot)
560 *dot = 0;
561
562 if(!fDllModule && WinExe && !strcmpi(lpszModule, WinExe->getModuleName())) {
563 hMod = WinExe->getInstanceHandle();
564 }
565 else {
566 windll = Win32DllBase::findModule(szModule);
567 if(windll) {
568 hMod = windll->getInstanceHandle();
569 }
570 else hMod = OSLibiGetModuleHandleA((char *)lpszModule);
571 }
572 }
573
574 eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
575 return(hMod);
576}
577//******************************************************************************
578//******************************************************************************
579HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
580{
581 HMODULE rc;
582 char *astring;
583
584 astring = UnicodeToAsciiString((LPWSTR)arg1);
585 rc = GetModuleHandleA(astring);
586 dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
587 FreeAsciiString(astring);
588 return(rc);
589}
590//******************************************************************************
591//******************************************************************************
592BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
593 PSECURITY_ATTRIBUTES arg3,
594 PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
595 PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
596 LPPROCESS_INFORMATION arg10)
597{
598 BOOL rc;
599 char *cmdline;
600 BOOL fAllocStr = FALSE;
601
602 if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
603 return(TRUE);
604
605 //probably a win32 exe, so run it in the pe loader
606 if(lpszImageName) {
607 if(lpszCommandLine) {
608 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
609 sprintf(cmdline, "PE.EXE %s %s", lpszImageName, lpszCommandLine);
610 fAllocStr = TRUE;
611 }
612 else {
613 cmdline = (char *)malloc(strlen(lpszImageName) + 16);
614 sprintf(cmdline, "PE.EXE %s", lpszImageName);
615 fAllocStr = TRUE;
616 }
617 }
618 else {
619 cmdline = (char *)malloc(strlen(lpszCommandLine) + 16);
620 sprintf(cmdline, "PE.EXE %s", lpszCommandLine);
621 fAllocStr = TRUE;
622 }
623 dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
624 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
625 if(fAllocStr)
626 free(cmdline);
627
628 dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
629 return(rc);
630}
631//******************************************************************************
632//******************************************************************************
633BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
634 PSECURITY_ATTRIBUTES arg3,
635 PSECURITY_ATTRIBUTES arg4,
636 BOOL arg5, DWORD arg6, PVOID arg7,
637 LPCWSTR arg8, LPSTARTUPINFOW arg9,
638 LPPROCESS_INFORMATION arg10)
639{
640 BOOL rc;
641 char *astring1, *astring2, *astring3;
642
643 dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
644 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
645 astring2 = UnicodeToAsciiString(arg2);
646 astring3 = UnicodeToAsciiString((LPWSTR)arg8);
647 // NOTE: This will not work as is (needs UNICODE support)
648 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
649 astring3, (LPSTARTUPINFOA)arg9, arg10);
650 FreeAsciiString(astring3);
651 FreeAsciiString(astring2);
652 FreeAsciiString(astring1);
653 return(rc);
654}
655//******************************************************************************
656//******************************************************************************
657FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
658{
659 Win32DllBase *winmod;
660 FARPROC proc;
661 ULONG ulAPIOrdinal;
662
663 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
664 if(winmod) {
665 ulAPIOrdinal = (ULONG)lpszProc;
666 if (ulAPIOrdinal <= 0x0000FFFF) {
667 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
668 }
669 else proc = (FARPROC)winmod->getApi((char *)lpszProc);
670 if(proc == 0) {
671 SetLastError(ERROR_PROC_NOT_FOUND);
672 }
673 return proc;
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 Win32ImageBase *winimage;
685 Win32PeLdrRsrcImg *rsrcimg;
686
687 dprintf(("GetVersionStruct"));
688 if(WinExe && !stricmp(WinExe->getFullPath(), modname)) {
689 winimage = (Win32ImageBase *)WinExe;
690 }
691 else {
692 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
693 if(winimage == NULL)
694 {
695 if(Win32ImageBase::isPEImage(modname) == FALSE)
696 {
697 HINSTANCE hInstance;
698
699 //must be an LX dll, just load it (app will probably load it anyway)
700 hInstance = LoadLibraryA(modname);
701 if(hInstance == 0)
702 return 0;
703 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
704 if(winimage) {
705 return winimage->getVersionStruct(verstruct, bufLength);
706 }
707 return 0;
708 }
709 //SvL: Try to load it
710 rsrcimg = new Win32PeLdrRsrcImg(modname);
711 if(rsrcimg == NULL)
712 return 0;
713
714 rsrcimg->init(0);
715 if(rsrcimg->getError() != NO_ERROR)
716 {
717 dprintf(("GetVersionStruct can't load %s\n", modname));
718 delete rsrcimg;
719 return(FALSE);
720 }
721 BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
722 delete rsrcimg;
723 return rc;
724 }
725 }
726 return winimage->getVersionStruct(verstruct, bufLength);
727}
728//******************************************************************************
729//******************************************************************************
730ULONG SYSTEM GetVersionSize(char *modname)
731{
732 Win32ImageBase *winimage;
733 Win32PeLdrRsrcImg *rsrcimg;
734
735 dprintf(("GetVersionSize of %s\n", modname));
736
737 if(WinExe && !stricmp(WinExe->getFullPath(), modname)) {
738 winimage = (Win32ImageBase *)WinExe;
739 }
740 else {
741 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
742 if(winimage == NULL)
743 {
744 if(Win32ImageBase::isPEImage(modname) == FALSE)
745 {
746 HINSTANCE hInstance;
747
748 //must be an LX dll, just load it (app will probably load it anyway)
749 hInstance = LoadLibraryA(modname);
750 if(hInstance == 0)
751 return 0;
752 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
753 if(winimage) {
754 return winimage->getVersionSize();
755 }
756 return 0;
757 }
758
759 //SvL: Try to load it
760 rsrcimg = new Win32PeLdrRsrcImg(modname);
761 if(rsrcimg == NULL)
762 return 0;
763
764 rsrcimg->init(0);
765 if(rsrcimg->getError() != NO_ERROR)
766 {
767 dprintf(("GetVersionSize can't load %s\n", modname));
768 delete rsrcimg;
769 return(FALSE);
770 }
771 rsrcimg->init(0);
772 int size = rsrcimg->getVersionSize();
773 delete rsrcimg;
774 return size;
775 }
776 }
777 return winimage->getVersionSize();
778}
779//******************************************************************************
780//******************************************************************************
781
782
783/***********************************************************************
784 * RegisterServiceProcess (KERNEL, KERNEL32)
785 *
786 * A service process calls this function to ensure that it continues to run
787 * even after a user logged off.
788 */
789DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
790 DWORD dwType)
791{
792 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
793 dwProcessId,
794 dwType));
795
796 /* I don't think that Wine needs to do anything in that function */
797 return 1; /* success */
798}
799
800//******************************************************************************
801//TODO:What does this do exactly??
802//******************************************************************************
803ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
804{
805 Win32DllBase *winmod;
806 FARPROC proc;
807 ULONG ulAPIOrdinal;
808
809 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
810 if(winmod)
811 {
812 // don't call ATTACH/DETACH thread functions in DLL
813 winmod->setThreadLibraryCalls(FALSE);
814 return TRUE;
815 }
816 else
817 {
818 // raise error condition
819 SetLastError(ERROR_INVALID_HANDLE);
820 return FALSE;
821 }
822}
823
Note: See TracBrowser for help on using the repository browser.