You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error if allocated memory spans over the address 0x100000000 (4GB) #63
FinalizeSections will fail if the allocated memory spans over the address 0x100000000 (4GB) since the addresses in the IMAGE_SECTION_HEADER are only 32-bit values.
I could fix it by putting the following code after the allocation of the variable "code":
#ifdef _WIN64
// check that memory-block does not span over the 4GB border
if(code < (LPVOID)0x100000000 && code + alignedImageSize >= (LPVOID)0x100000000)
{
auto old_code = code;
code = (unsigned char *)allocMemory(NULL,
alignedImageSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE,
userdata);
freeMemory(old_code, 0, MEM_RELEASE, userdata);
if(code == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
}
#endif
The problem is actually in line 295:
when the memory spans the 4 GB boundary the expression
(uintptr_t) sectionData.address + sectionData.size > (uintptr_t) alignedAddress
evaluates to true and thus the code from 297 to 303 the erroneously executed.
Activity
fancycode commentedon May 11, 2017
Hmm, that looks hacky ;-)
From reading the original code, is the problem that
sectionData.addressis wrong in line 280 in your case?https://github.com/fancycode/MemoryModule/blob/master/MemoryModule.c#L280
Also which version/commit are you using?
tobias-loew commentedon May 11, 2017
The problem is actually in line 295:
when the memory spans the 4 GB boundary the expression
(uintptr_t) sectionData.address + sectionData.size > (uintptr_t) alignedAddress
evaluates to true and thus the code from 297 to 303 the erroneously executed.
Please see my PR #64
PS:
I use memorymodule on a 64-bit machine to load like a 100 copies off the same dll, and everything works fine until I step over the 4 GB boundary
tobias-loew commentedon May 11, 2017
You can force the crash by spefifying a load address in line 582 that is just below the 4GB boundary, such address + alignedImageSize is above 4GB
tobias-loew commentedon May 12, 2017
I just figured out that the crash happens every-time the memory spans over A MULTIPLE of 4GB (obviously). My bad. I'll make a new pull request.
ianhbell commentedon Aug 2, 2017
See #67
Prevent memory of library from spanning over 4GB bounaries.