@@ -273,15 +273,17 @@ void DumpProfilingHeat(const char* path) {
273
273
}
274
274
}
275
275
276
- void MapMemory (void * memory , uint32_t address , uint32_t size , bool read , bool write , bool execute ) {
276
+ void * MapMemory (uint32_t address , uint32_t size , bool read , bool write , bool execute ) {
277
277
//FIXME: Permissions!
278
278
uc_err err ;
279
279
assert (size % ucAlignment == 0 );
280
+ void * memory = aligned_alloc (ucAlignment , size );
280
281
err = uc_mem_map_ptr (uc , address , size , UC_PROT_ALL , memory );
281
282
if (err ) {
282
283
printf ("Failed on uc_mem_map_ptr() with error returned %u: %s\n" , err , uc_strerror (err ));
283
284
}
284
285
//FIXME: Add to mapped memory list
286
+ return memory ;
285
287
}
286
288
287
289
Address Allocate (Size size ) {
@@ -428,7 +430,7 @@ void InitializeEmulation() {
428
430
429
431
#ifndef UC_KVM
430
432
// Setup segments
431
- SegmentDescriptor * gdtEntries = (SegmentDescriptor * )aligned_malloc ( ucAlignment , AlignUp (gdtSize , ucAlignment ));
433
+ SegmentDescriptor * gdtEntries = (SegmentDescriptor * ) = MapMemory ( gdtAddress , AlignUp (gdtSize , ucAlignment ), true, true, false );
432
434
memset (gdtEntries , 0x00 , gdtSize );
433
435
434
436
gdtEntries [14 ] = CreateDescriptor (0x00000000 , 0xFFFFF000 , true); // CS
@@ -439,8 +441,6 @@ void InitializeEmulation() {
439
441
gdtEntries [17 ] = CreateDescriptor (0x00000000 , 0xFFFFF000 , false); // Ring 0
440
442
gdtEntries [17 ].dpl = 0 ; //set descriptor privilege level
441
443
442
- err = uc_mem_map_ptr (uc , gdtAddress , AlignUp (gdtSize , ucAlignment ), UC_PROT_WRITE | UC_PROT_READ , gdtEntries );
443
-
444
444
uc_x86_mmr gdtr ;
445
445
gdtr .base = gdtAddress ;
446
446
gdtr .limit = gdtSize - 1 ;
@@ -478,14 +478,12 @@ void InitializeEmulation() {
478
478
#endif
479
479
480
480
// Map and set TLS (not exposed via flat memory)
481
- uint8_t * tls = aligned_malloc ( ucAlignment , tlsSize );
481
+ uint8_t * tls = MapMemory ( tlsAddress , tlsSize , true, true, false );
482
482
memset (tls , 0xBB , tlsSize );
483
- err = uc_mem_map_ptr (uc , tlsAddress , tlsSize , UC_PROT_WRITE | UC_PROT_READ , tls );
484
483
485
484
// Allocate a heap
486
- heap = aligned_malloc ( ucAlignment , heapSize );
485
+ heap = MapMemory ( heapAddress , heapSize , true, true, true );
487
486
memset (heap , 0xAA , heapSize );
488
- MapMemory (heap , heapAddress , heapSize , true, true, true);
489
487
}
490
488
491
489
void SetTracing (bool enabled ) {
@@ -548,8 +546,7 @@ unsigned int CreateEmulatedThread(uint32_t eip) {
548
546
// Map and set stack
549
547
//FIXME: Use requested size
550
548
if (stack == NULL ) {
551
- stack = aligned_malloc (ucAlignment , stackSize );
552
- MapMemory (stack , stackAddress , stackSize , true, true, false);
549
+ stack = MapMemory (stackAddress , stackSize , true, true, false);
553
550
}
554
551
static int threadId = 0 ;
555
552
uint32_t esp = stackAddress + stackSize / 2 + 256 * 1024 * threadId ++ ; // 256 kiB per late thread
0 commit comments