| 463 | } |
| 464 | |
| 465 | bool MapMemory(const std::function<void*(uint64_t, size_t)>& DoMMap) { |
| 466 | bool LimitedSize = true; |
| 467 | auto AllocPageSize = sysconf(_SC_PAGESIZE); |
| 468 | if (AllocPageSize <= 0) { |
| 469 | AllocPageSize = FEXCore::Utils::FEX_PAGE_SIZE; |
| 470 | } |
| 471 | |
| 472 | if (LimitedSize) { |
| 473 | DoMMap(0xe000'0000, AllocPageSize * 10); |
| 474 | |
| 475 | // SIB8 |
| 476 | // We test [-128, -126] (Bottom) |
| 477 | // We test [-8, 8] (Middle) |
| 478 | // We test [120, 127] (Top) |
| 479 | // Can fit in two pages |
| 480 | DoMMap(0xe800'0000 - AllocPageSize, AllocPageSize * 2); |
| 481 | } else { |
| 482 | // This is scratch memory location and SIB8 location |
| 483 | DoMMap(0xe000'0000, 0x1000'0000); |
| 484 | // This is for large SIB 32bit displacement testing |
| 485 | DoMMap(0x2'0000'0000, 0x1'0000'1000); |
| 486 | } |
| 487 | |
| 488 | // Map in the memory region for the test file |
| 489 | #ifndef _WIN32 |
| 490 | size_t Length = FEXCore::AlignUp(RawASMFile.size(), FEXCore::Utils::FEX_PAGE_SIZE); |
| 491 | auto ASMPtr = DoMMap(Code_start_page, Length); |
| 492 | #else |
| 493 | // Special magic DOS area that starts at 0x1'0000 |
| 494 | auto ASMPtr = DoMMap(1, 0x110000 - 1); |
| 495 | #endif |
| 496 | LOGMAN_THROW_A_FMT((uint64_t)ASMPtr == Code_start_page, "Couldn't allocate code at expected page: 0x{:x} != 0x{:x}", (uint64_t)ASMPtr, |
| 497 | Code_start_page); |
| 498 | memcpy(ASMPtr, RawASMFile.data(), RawASMFile.size()); |
| 499 | RIP = Code_start_page; |
| 500 | |
| 501 | // Map the memory regions the test file asks for |
| 502 | for (auto& [region, size] : Config.GetMemoryRegions()) { |
| 503 | DoMMap(region, size); |
| 504 | } |
| 505 | |
| 506 | if (!Config.Is64BitMode()) { |
| 507 | // 32-bit gets a fixed page allocated for stack. |
| 508 | DoMMap(STACK_OFFSET, StackSize()); |
| 509 | } |
| 510 | |
| 511 | LoadMemory(); |
| 512 | |
| 513 | return true; |
| 514 | } |
| 515 | |
| 516 | void LoadMemory() { |
| 517 | // Memory base here starts at the start location we passed back with GetLayout() |
nothing calls this directly
no test coverage detected