Don't cache file handles for NE executable modules so that we don't
lock the CDROM.
diff --git a/loader/ne/module.c b/loader/ne/module.c
index 8947e26..525a684 100644
--- a/loader/ne/module.c
+++ b/loader/ne/module.c
@@ -421,22 +421,18 @@
*/
HANDLE NE_OpenFile( NE_MODULE *pModule )
{
+ HANDLE handle;
char *name;
- static HANDLE cachedfd = INVALID_HANDLE_VALUE;
-
- TRACE("(%p) cache: mod=%p fd=%d\n",
- pModule, pCachedModule, cachedfd );
- if (pCachedModule == pModule) return cachedfd;
- CloseHandle( cachedfd );
- pCachedModule = pModule;
+ TRACE("(%p)\n", pModule );
+ /* mjm - removed module caching because it keeps open file handles
+ thus preventing CDROMs from being ejected */
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)
MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
- TRACE("opened '%s' -> %d\n",
- name, cachedfd );
- return cachedfd;
+ TRACE("opened '%s' -> %d\n", name, handle);
+ return handle;
}
diff --git a/loader/ne/resource.c b/loader/ne/resource.c
index b12409c..1a48c77 100644
--- a/loader/ne/resource.c
+++ b/loader/ne/resource.c
@@ -246,6 +246,7 @@
ReadFile( fd, GlobalLock16( handle ), (int)pNameInfo->length << sizeShift,
&res, NULL );
}
+ CloseHandle(fd);
return handle;
}
return (HGLOBAL16)0;
diff --git a/loader/ne/segment.c b/loader/ne/segment.c
index 365e286..5678ee6 100644
--- a/loader/ne/segment.c
+++ b/loader/ne/segment.c
@@ -189,7 +189,7 @@
if(buff == NULL) {
WARN_(dll)("Memory exausted!");
- return FALSE;
+ goto fail;
}
ReadFile(hf, buff, size, &res, NULL);
@@ -213,10 +213,10 @@
NE_FixupSegmentPrologs( pModule, segnum );
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);
- if (!count) return TRUE;
+ if (!count) goto succeed;
TRACE_(fixup)("Fixups for %.*s, segment %d, hSeg %04x\n",
*((BYTE *)pModule + pModule->name_table),
@@ -230,13 +230,13 @@
reloc_entries = (struct relocation_entry_s *)HeapAlloc(GetProcessHeap(), 0, count * sizeof(struct relocation_entry_s));
if(reloc_entries == NULL) {
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) ||
(res != count * sizeof(struct relocation_entry_s)))
{
WARN_(fixup)("Unable to read relocation information\n" );
- return FALSE;
+ goto fail;
}
/*
@@ -419,6 +419,9 @@
}
HeapFree(GetProcessHeap(), 0, reloc_entries);
+
+succeed:
+ CloseHandle(hf);
return TRUE;
unknown:
@@ -427,6 +430,9 @@
i + 1, rep->address_type, rep->relocation_type,
rep->offset, rep->target1, rep->target2);
HeapFree(GetProcessHeap(), 0, reloc_entries);
+
+fail:
+ CloseHandle(hf);
return FALSE;
}
@@ -464,8 +470,7 @@
NtCurrentTeb()->cur_stack = MAKESEGPTR(pModule->self_loading_sel,
0xff00 - sizeof(STACK16FRAME) );
- DuplicateHandle( GetCurrentProcess(), NE_OpenFile(pModule),
- GetCurrentProcess(), &hf, 0, FALSE, DUPLICATE_SAME_ACCESS );
+ hf = NE_OpenFile(pModule);
hFile16 = Win32HandleToDosFileHandle( hf );
TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n",
pModule->self,hFile16);