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

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

Fix: SetLastError/GetLastError behaviour changed

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