Commit f5d21eb2 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Don't cache file handles for NE executable modules so that we don't

lock the CDROM.
parent 160ab19a
...@@ -421,22 +421,18 @@ BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset ) ...@@ -421,22 +421,18 @@ BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
*/ */
HANDLE NE_OpenFile( NE_MODULE *pModule ) HANDLE NE_OpenFile( NE_MODULE *pModule )
{ {
HANDLE handle;
char *name; char *name;
static HANDLE cachedfd = INVALID_HANDLE_VALUE; TRACE("(%p)\n", pModule );
/* mjm - removed module caching because it keeps open file handles
TRACE("(%p) cache: mod=%p fd=%d\n", thus preventing CDROMs from being ejected */
pModule, pCachedModule, cachedfd );
if (pCachedModule == pModule) return cachedfd;
CloseHandle( cachedfd );
pCachedModule = pModule;
name = NE_MODULE_NAME( pModule ); name = NE_MODULE_NAME( pModule );
if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ, if ((handle = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE) NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self ); MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
TRACE("opened '%s' -> %d\n", TRACE("opened '%s' -> %d\n", name, handle);
name, cachedfd ); return handle;
return cachedfd;
} }
......
...@@ -246,6 +246,7 @@ HGLOBAL16 WINAPI NE_DefResourceHandler( HGLOBAL16 hMemObj, HMODULE16 hModule, ...@@ -246,6 +246,7 @@ HGLOBAL16 WINAPI NE_DefResourceHandler( HGLOBAL16 hMemObj, HMODULE16 hModule,
ReadFile( fd, GlobalLock16( handle ), (int)pNameInfo->length << sizeShift, ReadFile( fd, GlobalLock16( handle ), (int)pNameInfo->length << sizeShift,
&res, NULL ); &res, NULL );
} }
CloseHandle(fd);
return handle; return handle;
} }
return (HGLOBAL16)0; return (HGLOBAL16)0;
......
...@@ -189,7 +189,7 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) ...@@ -189,7 +189,7 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
if(buff == NULL) { if(buff == NULL) {
WARN_(dll)("Memory exausted!"); WARN_(dll)("Memory exausted!");
return FALSE; goto fail;
} }
ReadFile(hf, buff, size, &res, NULL); ReadFile(hf, buff, size, &res, NULL);
...@@ -213,10 +213,10 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) ...@@ -213,10 +213,10 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
NE_FixupSegmentPrologs( pModule, segnum ); NE_FixupSegmentPrologs( pModule, segnum );
if (!(pSeg->flags & NE_SEGFLAGS_RELOC_DATA)) if (!(pSeg->flags & NE_SEGFLAGS_RELOC_DATA))
return TRUE; /* No relocation data, we are done */ goto succeed; /* No relocation data, we are done */
ReadFile(hf, &count, sizeof(count), &res, NULL); ReadFile(hf, &count, sizeof(count), &res, NULL);
if (!count) return TRUE; if (!count) goto succeed;
TRACE_(fixup)("Fixups for %.*s, segment %d, hSeg %04x\n", TRACE_(fixup)("Fixups for %.*s, segment %d, hSeg %04x\n",
*((BYTE *)pModule + pModule->name_table), *((BYTE *)pModule + pModule->name_table),
...@@ -230,13 +230,13 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) ...@@ -230,13 +230,13 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
reloc_entries = (struct relocation_entry_s *)HeapAlloc(GetProcessHeap(), 0, count * sizeof(struct relocation_entry_s)); reloc_entries = (struct relocation_entry_s *)HeapAlloc(GetProcessHeap(), 0, count * sizeof(struct relocation_entry_s));
if(reloc_entries == NULL) { if(reloc_entries == NULL) {
WARN_(fixup)("Not enough memory for relocation entries!"); WARN_(fixup)("Not enough memory for relocation entries!");
return FALSE; goto fail;
} }
if (!ReadFile( hf, reloc_entries, count * sizeof(struct relocation_entry_s), &res, NULL) || if (!ReadFile( hf, reloc_entries, count * sizeof(struct relocation_entry_s), &res, NULL) ||
(res != count * sizeof(struct relocation_entry_s))) (res != count * sizeof(struct relocation_entry_s)))
{ {
WARN_(fixup)("Unable to read relocation information\n" ); WARN_(fixup)("Unable to read relocation information\n" );
return FALSE; goto fail;
} }
/* /*
...@@ -419,6 +419,9 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) ...@@ -419,6 +419,9 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
} }
HeapFree(GetProcessHeap(), 0, reloc_entries); HeapFree(GetProcessHeap(), 0, reloc_entries);
succeed:
CloseHandle(hf);
return TRUE; return TRUE;
unknown: unknown:
...@@ -427,6 +430,9 @@ unknown: ...@@ -427,6 +430,9 @@ unknown:
i + 1, rep->address_type, rep->relocation_type, i + 1, rep->address_type, rep->relocation_type,
rep->offset, rep->target1, rep->target2); rep->offset, rep->target1, rep->target2);
HeapFree(GetProcessHeap(), 0, reloc_entries); HeapFree(GetProcessHeap(), 0, reloc_entries);
fail:
CloseHandle(hf);
return FALSE; return FALSE;
} }
...@@ -464,8 +470,7 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule ) ...@@ -464,8 +470,7 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule )
NtCurrentTeb()->cur_stack = MAKESEGPTR(pModule->self_loading_sel, NtCurrentTeb()->cur_stack = MAKESEGPTR(pModule->self_loading_sel,
0xff00 - sizeof(STACK16FRAME) ); 0xff00 - sizeof(STACK16FRAME) );
DuplicateHandle( GetCurrentProcess(), NE_OpenFile(pModule), hf = NE_OpenFile(pModule);
GetCurrentProcess(), &hf, 0, FALSE, DUPLICATE_SAME_ACCESS );
hFile16 = Win32HandleToDosFileHandle( hf ); hFile16 = Win32HandleToDosFileHandle( hf );
TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n", TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n",
pModule->self,hFile16); pModule->self,hFile16);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment