Commit aabef029 authored by Alexandre Julliard's avatar Alexandre Julliard

Include space for resources in the module header instead of doing a

separate allocation.
parent ebc32253
...@@ -89,9 +89,10 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr ) ...@@ -89,9 +89,10 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
IMAGE_SECTION_HEADER *sec; IMAGE_SECTION_HEADER *sec;
IMAGE_EXPORT_DIRECTORY *exp; IMAGE_EXPORT_DIRECTORY *exp;
IMAGE_IMPORT_DESCRIPTOR *imp; IMAGE_IMPORT_DESCRIPTOR *imp;
const BUILTIN32_RESOURCE *rsrc = descr->rsrc;
LPVOID *funcs; LPVOID *funcs;
LPSTR *names; LPSTR *names;
LPSTR pfwd; LPSTR pfwd, rtab;
DEBUG_ENTRY_POINT *debug; DEBUG_ENTRY_POINT *debug;
INT i, size, nb_sections; INT i, size, nb_sections;
BYTE *addr; BYTE *addr;
...@@ -112,6 +113,7 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr ) ...@@ -112,6 +113,7 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
if (WARN_ON(relay) || TRACE_ON(relay)) if (WARN_ON(relay) || TRACE_ON(relay))
size += descr->nb_funcs * sizeof(DEBUG_ENTRY_POINT); size += descr->nb_funcs * sizeof(DEBUG_ENTRY_POINT);
#endif #endif
if (rsrc) size += rsrc->restabsize;
addr = VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); addr = VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
if (!addr) return 0; if (!addr) return 0;
dos = (IMAGE_DOS_HEADER *)addr; dos = (IMAGE_DOS_HEADER *)addr;
...@@ -122,7 +124,8 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr ) ...@@ -122,7 +124,8 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
funcs = (LPVOID *)(exp + 1); funcs = (LPVOID *)(exp + 1);
names = (LPSTR *)(funcs + descr->nb_funcs); names = (LPSTR *)(funcs + descr->nb_funcs);
pfwd = (LPSTR)(names + descr->nb_names); pfwd = (LPSTR)(names + descr->nb_names);
debug = (DEBUG_ENTRY_POINT *)(pfwd + descr->fwd_size); rtab = pfwd + descr->fwd_size;
debug = (DEBUG_ENTRY_POINT *)(rtab + (rsrc ? rsrc->restabsize : 0));
/* Build the DOS and NT headers */ /* Build the DOS and NT headers */
...@@ -219,21 +222,11 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr ) ...@@ -219,21 +222,11 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
sec++; sec++;
/* Build the resource directory */ /* Build the resource directory */
if(descr->rsrc)
if (rsrc)
{ {
const BUILTIN32_RESOURCE *rsrc = descr->rsrc;
int i;
void *rtab;
IMAGE_RESOURCE_DATA_ENTRY *rdep; IMAGE_RESOURCE_DATA_ENTRY *rdep;
rtab = HeapAlloc(GetProcessHeap(), 0, rsrc->restabsize);
if(!rtab)
{
ERR("Failed to get memory for resource directory\n");
VirtualFree(addr, size, MEM_RELEASE);
return 0;
}
/* /*
* The resource directory has to be copied because it contains * The resource directory has to be copied because it contains
* RVAs. These would be invalid if the dll is instantiated twice. * RVAs. These would be invalid if the dll is instantiated twice.
...@@ -241,7 +234,7 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr ) ...@@ -241,7 +234,7 @@ static HMODULE BUILTIN32_DoLoadImage( const BUILTIN32_DESCRIPTOR *descr )
memcpy(rtab, rsrc->restab, rsrc->restabsize); memcpy(rtab, rsrc->restab, rsrc->restabsize);
dir = &nt->OptionalHeader.DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY]; dir = &nt->OptionalHeader.DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY];
dir->VirtualAddress = (DWORD)rtab - (DWORD)addr; dir->VirtualAddress = (BYTE *)rtab - addr;
dir->Size = rsrc->restabsize; dir->Size = rsrc->restabsize;
rdep = (IMAGE_RESOURCE_DATA_ENTRY *)((DWORD)rtab + (DWORD)rsrc->entries - (DWORD)rsrc->restab); rdep = (IMAGE_RESOURCE_DATA_ENTRY *)((DWORD)rtab + (DWORD)rsrc->entries - (DWORD)rsrc->restab);
for(i = 0; i < rsrc->nresources; i++) for(i = 0; i < rsrc->nresources; i++)
......
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