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

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

heapstring fixes + dll renaming support added

File size: 25.6 KB
Line 
1/* $Id: wprocess.cpp,v 1.45 1999-11-09 14:19:47 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 strcpy(modname, lpszLibFile);
314 strupr(modname);
315 //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
316 Win32DllBase::renameDll(modname);
317
318 hDll = O32_LoadLibrary(modname);
319 dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
320 lpszLibFile,
321 hDll,
322 GetLastError()));
323 if(hDll)
324 {
325 return hDll; //converted dll or win32k took care of it
326 }
327
328 if(!strstr(modname, ".")) {
329 strcat(modname,".DLL");
330 }
331
332 if(Win32ImageBase::isPEImage((char *)modname))
333 {
334 module = Win32DllBase::findModule((char *)modname);
335 if(module) {//don't load it again
336 module->AddRef();
337 return module->getInstanceHandle();
338 }
339
340 Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname);
341 if(peldrDll == NULL)
342 return(0);
343
344 peldrDll->init(0);
345 if(peldrDll->getError() != NO_ERROR) {
346 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
347 delete(peldrDll);
348 return(0);
349 }
350 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
351 peldrDll->setNoEntryCalls();
352 }
353
354 if(peldrDll->attachProcess() == FALSE) {
355 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
356 delete(peldrDll);
357 return(0);
358 }
359 peldrDll->AddRef();
360 return peldrDll->getInstanceHandle();
361 }
362 else return(0);
363}
364//******************************************************************************
365//******************************************************************************
366HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
367{
368 HINSTANCE hDll;
369
370 dprintf(("KERNEL32: LoadLibraryA(%s)\n",
371 lpszLibFile));
372 dprintf(("KERNEL32: LoadLibrary FS = %x\n", GetFS()));
373
374 hDll = iLoadLibraryA(lpszLibFile, 0);
375 if (hDll == 0)
376 {
377 char * pszName;
378
379 // remove path from the image name
380 pszName = strrchr((char *)lpszLibFile,
381 '\\');
382 if (pszName != NULL)
383 {
384 pszName++; // skip backslash
385
386 // now try again without fully qualified path
387 hDll = iLoadLibraryA(pszName, 0);
388 }
389 }
390
391 return hDll;
392}
393//******************************************************************************
394//******************************************************************************
395HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
396{
397 HINSTANCE hDll;
398
399 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
400 hDll = iLoadLibraryA(lpszLibFile, dwFlags);
401 if (hDll == 0)
402 {
403 char * pszName;
404
405 // remove path from the image name
406 pszName = strrchr((char *)lpszLibFile,
407 '\\');
408 if (pszName != NULL)
409 {
410 pszName++; // skip backslash
411
412 // now try again without fully qualified path
413 hDll = iLoadLibraryA(pszName, dwFlags);
414 }
415 }
416
417 return hDll;
418}
419//******************************************************************************
420//******************************************************************************
421HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
422{
423 char *asciimodule;
424 HINSTANCE rc;
425
426 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
427 dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
428 rc = LoadLibraryA(asciimodule);
429 free(asciimodule);
430 return(rc);
431}
432//******************************************************************************
433//******************************************************************************
434HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
435{
436 char *asciimodule;
437 HINSTANCE rc;
438
439 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
440 dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
441 rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
442 free(asciimodule);
443 return(rc);
444}
445//******************************************************************************
446//******************************************************************************
447LPCSTR WIN32API GetCommandLineA()
448{
449 LPTSTR cmdline = NULL;
450
451 if(WinExe) {
452 cmdline = WinExe->getCommandLine();
453 }
454 if(cmdline == NULL) //not used for converted exes
455 cmdline = O32_GetCommandLine();
456
457 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
458 dprintf(("KERNEL32: FS = %x\n", GetFS()));
459 return(cmdline);
460}
461//******************************************************************************
462//******************************************************************************
463LPCWSTR WIN32API GetCommandLineW(void)
464{
465 static WCHAR *UnicodeCmdLine = NULL;
466 char *asciicmdline = NULL;
467
468 dprintf(("KERNEL32: FS = %x\n", GetFS()));
469
470 if(UnicodeCmdLine)
471 return(UnicodeCmdLine); //already called before
472
473 if(WinExe) {
474 asciicmdline = WinExe->getCommandLine();
475 }
476 if(asciicmdline == NULL) //not used for converted exes
477 asciicmdline = O32_GetCommandLine();
478
479 if(asciicmdline) {
480 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
481 AsciiToUnicode(asciicmdline, UnicodeCmdLine);
482 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
483 return(UnicodeCmdLine);
484 }
485 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
486 return NULL;
487}
488//******************************************************************************
489//******************************************************************************
490DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
491{
492 DWORD rc;
493 Win32ImageBase *module;
494 char *fpath = NULL;
495
496 dprintf(("GetModuleFileName %X", hinstModule));
497 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
498 module = (Win32ImageBase *)WinExe;
499 }
500 else {
501 module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule);
502 }
503
504 if(module) {
505 fpath = module->getFullPath();
506 }
507 if(fpath) {
508 //SvL: 13-9-98: +1
509 rc = min(strlen(fpath)+1, cchPath);
510 strncpy(lpszPath, fpath, rc);
511 }
512 else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
513
514 if(rc) {
515 dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
516 }
517 return(rc);
518}
519//******************************************************************************
520//******************************************************************************
521DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
522{
523 char *asciifilename = (char *)malloc(nSize+1);
524 DWORD rc;
525
526 dprintf(("KERNEL32: OSLibGetModuleFileNameW\n"));
527 rc = GetModuleFileNameA(hModule, asciifilename, nSize);
528 if(rc) AsciiToUnicode(asciifilename, lpFileName);
529 free(asciifilename);
530 return(rc);
531}
532//******************************************************************************
533//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
534// very.weird.exe)
535//******************************************************************************
536HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
537{
538 HANDLE hMod;
539 Win32DllBase *windll;
540 char szModule[CCHMAXPATH];
541 BOOL fDllModule = FALSE;
542
543 if(lpszModule == NULL) {
544 if(WinExe)
545 hMod = WinExe->getInstanceHandle();
546 else hMod = -1;
547 }
548 else {
549 strcpy(szModule, OSLibStripPath((char *)lpszModule));
550 strupr(szModule);
551 if(strstr(szModule, ".DLL")) {
552 fDllModule = TRUE;
553 }
554 else {
555 if(!strstr(szModule, ".")) {
556 //if there's no extension or trainling dot, we
557 //assume it's a dll (see Win32 SDK docs)
558 fDllModule = TRUE;
559 }
560 }
561 char *dot = strstr(szModule, ".");
562 if(dot)
563 *dot = 0;
564
565 if(!fDllModule && WinExe && !strcmpi(szModule, WinExe->getModuleName())) {
566 hMod = WinExe->getInstanceHandle();
567 }
568 else {
569 windll = Win32DllBase::findModule(szModule);
570 if(windll) {
571 hMod = windll->getInstanceHandle();
572 }
573 else hMod = OSLibiGetModuleHandleA((char *)lpszModule);
574 }
575 }
576
577 eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
578 return(hMod);
579}
580//******************************************************************************
581//******************************************************************************
582HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
583{
584 HMODULE rc;
585 char *astring;
586
587 astring = UnicodeToAsciiString((LPWSTR)arg1);
588 rc = GetModuleHandleA(astring);
589 dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
590 FreeAsciiString(astring);
591 return(rc);
592}
593//******************************************************************************
594//******************************************************************************
595BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
596 PSECURITY_ATTRIBUTES arg3,
597 PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
598 PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
599 LPPROCESS_INFORMATION arg10)
600{
601 BOOL rc;
602 char *cmdline;
603 BOOL fAllocStr = FALSE;
604
605 if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
606 return(TRUE);
607
608 //probably a win32 exe, so run it in the pe loader
609 if(lpszImageName) {
610 if(lpszCommandLine) {
611 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
612 sprintf(cmdline, "PE.EXE %s %s", lpszImageName, lpszCommandLine);
613 fAllocStr = TRUE;
614 }
615 else {
616 cmdline = (char *)malloc(strlen(lpszImageName) + 16);
617 sprintf(cmdline, "PE.EXE %s", lpszImageName);
618 fAllocStr = TRUE;
619 }
620 }
621 else {
622 cmdline = (char *)malloc(strlen(lpszCommandLine) + 16);
623 sprintf(cmdline, "PE.EXE %s", lpszCommandLine);
624 fAllocStr = TRUE;
625 }
626 dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
627 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
628 if(fAllocStr)
629 free(cmdline);
630
631 dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
632 return(rc);
633}
634//******************************************************************************
635//******************************************************************************
636BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
637 PSECURITY_ATTRIBUTES arg3,
638 PSECURITY_ATTRIBUTES arg4,
639 BOOL arg5, DWORD arg6, PVOID arg7,
640 LPCWSTR arg8, LPSTARTUPINFOW arg9,
641 LPPROCESS_INFORMATION arg10)
642{
643 BOOL rc;
644 char *astring1, *astring2, *astring3;
645
646 dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
647 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
648 astring2 = UnicodeToAsciiString(arg2);
649 astring3 = UnicodeToAsciiString((LPWSTR)arg8);
650 // NOTE: This will not work as is (needs UNICODE support)
651 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
652 astring3, (LPSTARTUPINFOA)arg9, arg10);
653 FreeAsciiString(astring3);
654 FreeAsciiString(astring2);
655 FreeAsciiString(astring1);
656 return(rc);
657}
658//******************************************************************************
659//******************************************************************************
660HINSTANCE WIN32API WinExec(LPCSTR lpCmdLine, UINT nCmdShow)
661{
662 STARTUPINFOA startinfo = {0};
663 PROCESS_INFORMATION procinfo;
664
665 dprintf(("KERNEL32: WinExec %s\n", lpCmdLine));
666 startinfo.dwFlags = nCmdShow;
667 if(CreateProcessA(NULL, (LPSTR)lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL,
668 &startinfo, &procinfo) == FALSE)
669 {
670 return 0;
671 }
672 return procinfo.hProcess; //correct?
673}
674//******************************************************************************
675//******************************************************************************
676FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
677{
678 Win32DllBase *winmod;
679 FARPROC proc;
680 ULONG ulAPIOrdinal;
681
682 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
683 if(winmod) {
684 ulAPIOrdinal = (ULONG)lpszProc;
685 if (ulAPIOrdinal <= 0x0000FFFF) {
686 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
687 }
688 else proc = (FARPROC)winmod->getApi((char *)lpszProc);
689 if(proc == 0) {
690 SetLastError(ERROR_PROC_NOT_FOUND);
691 }
692 return proc;
693 }
694 proc = O32_GetProcAddress(hModule, lpszProc);
695 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
696 return(proc);
697}
698//******************************************************************************
699//Retrieve the version
700//******************************************************************************
701BOOL SYSTEM GetVersionStruct(char *lpszModName, char *verstruct, ULONG bufLength)
702{
703 Win32ImageBase *winimage;
704 Win32PeLdrRsrcImg *rsrcimg;
705
706 dprintf(("GetVersionStruct of module %s", lpszModName));
707 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
708 winimage = (Win32ImageBase *)WinExe;
709 }
710 else {
711 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
712 if(winimage == NULL)
713 {
714 char modname[CCHMAXPATH];
715
716 strcpy(modname, lpszModName);
717 //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
718 Win32DllBase::renameDll(modname);
719
720 if(Win32ImageBase::isPEImage(modname) == FALSE)
721 {
722 HINSTANCE hInstance;
723
724 //must be an LX dll, just load it (app will probably load it anyway)
725 hInstance = LoadLibraryA(modname);
726 if(hInstance == 0)
727 return 0;
728 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
729 if(winimage) {
730 return winimage->getVersionStruct(verstruct, bufLength);
731 }
732 return 0;
733 }
734 //SvL: Try to load it
735 rsrcimg = new Win32PeLdrRsrcImg(modname);
736 if(rsrcimg == NULL)
737 return 0;
738
739 rsrcimg->init(0);
740 if(rsrcimg->getError() != NO_ERROR)
741 {
742 dprintf(("GetVersionStruct can't load %s\n", modname));
743 delete rsrcimg;
744 return(FALSE);
745 }
746 BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
747 delete rsrcimg;
748 return rc;
749 }
750 }
751 return winimage->getVersionStruct(verstruct, bufLength);
752}
753//******************************************************************************
754//******************************************************************************
755ULONG SYSTEM GetVersionSize(char *lpszModName)
756{
757 Win32ImageBase *winimage;
758 Win32PeLdrRsrcImg *rsrcimg;
759
760 dprintf(("GetVersionSize of %s\n", lpszModName));
761
762 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
763 winimage = (Win32ImageBase *)WinExe;
764 }
765 else {
766 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
767 if(winimage == NULL)
768 {
769 char modname[CCHMAXPATH];
770
771 strcpy(modname, lpszModName);
772 //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
773 Win32DllBase::renameDll(modname);
774
775 if(Win32ImageBase::isPEImage(modname) == FALSE)
776 {
777 HINSTANCE hInstance;
778
779 //must be an LX dll, just load it (app will probably load it anyway)
780 hInstance = LoadLibraryA(modname);
781 if(hInstance == 0)
782 return 0;
783 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
784 if(winimage) {
785 return winimage->getVersionSize();
786 }
787 return 0;
788 }
789
790 //SvL: Try to load it
791 rsrcimg = new Win32PeLdrRsrcImg(modname);
792 if(rsrcimg == NULL)
793 return 0;
794
795 rsrcimg->init(0);
796 if(rsrcimg->getError() != NO_ERROR)
797 {
798 dprintf(("GetVersionSize can't load %s\n", modname));
799 delete rsrcimg;
800 return(FALSE);
801 }
802 rsrcimg->init(0);
803 int size = rsrcimg->getVersionSize();
804 delete rsrcimg;
805 return size;
806 }
807 }
808 return winimage->getVersionSize();
809}
810//******************************************************************************
811//******************************************************************************
812
813
814/***********************************************************************
815 * RegisterServiceProcess (KERNEL, KERNEL32)
816 *
817 * A service process calls this function to ensure that it continues to run
818 * even after a user logged off.
819 */
820DWORD WIN32API RegisterServiceProcess(DWORD dwProcessId,
821 DWORD dwType)
822{
823 dprintf(("KERNEL32: RegisterServiceProcess(%08xh,%08xh) not implemented.\n",
824 dwProcessId,
825 dwType));
826
827 /* I don't think that Wine needs to do anything in that function */
828 return 1; /* success */
829}
830
831//******************************************************************************
832//TODO:What does this do exactly??
833//******************************************************************************
834ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
835{
836 Win32DllBase *winmod;
837 FARPROC proc;
838 ULONG ulAPIOrdinal;
839
840 winmod = Win32DllBase::findModule((HINSTANCE)hModule);
841 if(winmod)
842 {
843 // don't call ATTACH/DETACH thread functions in DLL
844 winmod->setThreadLibraryCalls(FALSE);
845 return TRUE;
846 }
847 else
848 {
849 // raise error condition
850 SetLastError(ERROR_INVALID_HANDLE);
851 return FALSE;
852 }
853}
854
Note: See TracBrowser for help on using the repository browser.