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

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

WinExec rewrite + mmap bugfixes

File size: 25.2 KB
Line 
1/* $Id: wprocess.cpp,v 1.43 1999-10-27 18:11:40 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//******************************************************************************
657HINSTANCE WIN32API WinExec(LPCSTR lpCmdLine, UINT nCmdShow)
658{
659 STARTUPINFOA startinfo = {0};
660 PROCESS_INFORMATION procinfo;
661
662 dprintf(("KERNEL32: WinExec %s\n", lpCmdLine));
663 startinfo.dwFlags = nCmdShow;
664 if(CreateProcessA(NULL, (LPSTR)lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL,
665 &startinfo, &procinfo) == FALSE)
666 {
667 return 0;
668 }
669 return procinfo.hProcess; //correct?
670}
671//******************************************************************************
672//******************************************************************************
673FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
674{
675 Win32DllBase *winmod;
676 FARPROC proc;
677 ULONG ulAPIOrdinal;
678
679 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
680 if(winmod) {
681 ulAPIOrdinal = (ULONG)lpszProc;
682 if (ulAPIOrdinal <= 0x0000FFFF) {
683 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
684 }
685 else proc = (FARPROC)winmod->getApi((char *)lpszProc);
686 if(proc == 0) {
687 SetLastError(ERROR_PROC_NOT_FOUND);
688 }
689 return proc;
690 }
691 proc = O32_GetProcAddress(hModule, lpszProc);
692 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
693 return(proc);
694}
695//******************************************************************************
696//Retrieve the version
697//******************************************************************************
698BOOL SYSTEM GetVersionStruct(char *modname, char *verstruct, ULONG bufLength)
699{
700 Win32ImageBase *winimage;
701 Win32PeLdrRsrcImg *rsrcimg;
702
703 dprintf(("GetVersionStruct"));
704 if(WinExe && !stricmp(WinExe->getFullPath(), modname)) {
705 winimage = (Win32ImageBase *)WinExe;
706 }
707 else {
708 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
709 if(winimage == NULL)
710 {
711 if(Win32ImageBase::isPEImage(modname) == FALSE)
712 {
713 HINSTANCE hInstance;
714
715 //must be an LX dll, just load it (app will probably load it anyway)
716 hInstance = LoadLibraryA(modname);
717 if(hInstance == 0)
718 return 0;
719 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
720 if(winimage) {
721 return winimage->getVersionStruct(verstruct, bufLength);
722 }
723 return 0;
724 }
725 //SvL: Try to load it
726 rsrcimg = new Win32PeLdrRsrcImg(modname);
727 if(rsrcimg == NULL)
728 return 0;
729
730 rsrcimg->init(0);
731 if(rsrcimg->getError() != NO_ERROR)
732 {
733 dprintf(("GetVersionStruct can't load %s\n", modname));
734 delete rsrcimg;
735 return(FALSE);
736 }
737 BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
738 delete rsrcimg;
739 return rc;
740 }
741 }
742 return winimage->getVersionStruct(verstruct, bufLength);
743}
744//******************************************************************************
745//******************************************************************************
746ULONG SYSTEM GetVersionSize(char *modname)
747{
748 Win32ImageBase *winimage;
749 Win32PeLdrRsrcImg *rsrcimg;
750
751 dprintf(("GetVersionSize of %s\n", modname));
752
753 if(WinExe && !stricmp(WinExe->getFullPath(), modname)) {
754 winimage = (Win32ImageBase *)WinExe;
755 }
756 else {
757 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
758 if(winimage == NULL)
759 {
760 if(Win32ImageBase::isPEImage(modname) == FALSE)
761 {
762 HINSTANCE hInstance;
763
764 //must be an LX dll, just load it (app will probably load it anyway)
765 hInstance = LoadLibraryA(modname);
766 if(hInstance == 0)
767 return 0;
768 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
769 if(winimage) {
770 return winimage->getVersionSize();
771 }
772 return 0;
773 }
774
775 //SvL: Try to load it
776 rsrcimg = new Win32PeLdrRsrcImg(modname);
777 if(rsrcimg == NULL)
778 return 0;
779
780 rsrcimg->init(0);
781 if(rsrcimg->getError() != NO_ERROR)
782 {
783 dprintf(("GetVersionSize can't load %s\n", modname));
784 delete rsrcimg;
785 return(FALSE);
786 }
787 rsrcimg->init(0);
788 int size = rsrcimg->getVersionSize();
789 delete rsrcimg;
790 return size;
791 }
792 }
793 return winimage->getVersionSize();
794}
795//******************************************************************************
796//******************************************************************************
797
798
799/***********************************************************************
800 * RegisterServiceProcess (KERNEL, KERNEL32)
801 *
802 * A service process calls this function to ensure that it continues to run
803 * even after a user logged off.
804 */
805DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
806 DWORD dwType)
807{
808 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
809 dwProcessId,
810 dwType));
811
812 /* I don't think that Wine needs to do anything in that function */
813 return 1; /* success */
814}
815
816//******************************************************************************
817//TODO:What does this do exactly??
818//******************************************************************************
819ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
820{
821 Win32DllBase *winmod;
822 FARPROC proc;
823 ULONG ulAPIOrdinal;
824
825 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
826 if(winmod)
827 {
828 // don't call ATTACH/DETACH thread functions in DLL
829 winmod->setThreadLibraryCalls(FALSE);
830 return TRUE;
831 }
832 else
833 {
834 // raise error condition
835 SetLastError(ERROR_INVALID_HANDLE);
836 return FALSE;
837 }
838}
839
Note: See TracBrowser for help on using the repository browser.