@@ -257,6 +257,55 @@ void TestFreeAfterDefaultAlloc(void *data, size_t size) {
257
257
assert (expected_calls.current_free_call == free_calls_after_loading + 1 );
258
258
}
259
259
260
+ #ifdef _WIN64
261
+
262
+ LPVOID MemoryAllocHigh (LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect, void * userdata)
263
+ {
264
+ int * counter = static_cast <int *>(userdata);
265
+ if (*counter == 0 ) {
266
+ // Make sure the image gets loaded to an address above 32bit.
267
+ uintptr_t offset = 0x10000000000 ;
268
+ address = (LPVOID) ((uintptr_t ) address + offset);
269
+ }
270
+ (*counter)++;
271
+ return MemoryDefaultAlloc (address, size, allocationType, protect, NULL );
272
+ }
273
+
274
+ void TestAllocHighMemory (void *data, size_t size) {
275
+ HMEMORYMODULE handle;
276
+ int counter = 0 ;
277
+ addNumberProc addNumber;
278
+ HMEMORYRSRC resourceInfo;
279
+ DWORD resourceSize;
280
+ LPVOID resourceData;
281
+ TCHAR buffer[100 ];
282
+
283
+ handle = MemoryLoadLibraryEx (
284
+ data, size, MemoryAllocHigh, MemoryDefaultFree, MemoryDefaultLoadLibrary,
285
+ MemoryDefaultGetProcAddress, MemoryDefaultFreeLibrary, &counter);
286
+
287
+ assert (handle != NULL );
288
+
289
+ addNumber = (addNumberProc)MemoryGetProcAddress (handle, " addNumbers" );
290
+ _tprintf (_T (" From memory: %d\n " ), addNumber (1 , 2 ));
291
+
292
+ resourceInfo = MemoryFindResource (handle, MAKEINTRESOURCE (VS_VERSION_INFO), RT_VERSION);
293
+ _tprintf (_T (" MemoryFindResource returned 0x%p\n " ), resourceInfo);
294
+
295
+ resourceSize = MemorySizeofResource (handle, resourceInfo);
296
+ resourceData = MemoryLoadResource (handle, resourceInfo);
297
+ _tprintf (_T (" Memory resource data: %ld bytes at 0x%p\n " ), resourceSize, resourceData);
298
+
299
+ MemoryLoadString (handle, 1 , buffer, sizeof (buffer));
300
+ _tprintf (_T (" String1: %s\n " ), buffer);
301
+
302
+ MemoryLoadString (handle, 20 , buffer, sizeof (buffer));
303
+ _tprintf (_T (" String2: %s\n " ), buffer);
304
+
305
+ MemoryFreeLibrary (handle);
306
+ }
307
+ #endif // _WIN64
308
+
260
309
void TestCustomAllocAndFree (void )
261
310
{
262
311
void *data;
@@ -274,6 +323,10 @@ void TestCustomAllocAndFree(void)
274
323
TestCleanupAfterFailingAllocation (data, size);
275
324
_tprintf (_T (" Test custom free function after MemoryLoadLibraryEx\n " ));
276
325
TestFreeAfterDefaultAlloc (data, size);
326
+ #ifdef _WIN64
327
+ _tprintf (_T (" Test allocating in high memory\n " ));
328
+ TestAllocHighMemory (data, size);
329
+ #endif
277
330
278
331
free (data);
279
332
}
0 commit comments