client/tests/resource_budget.c (2423B)
1 #include "recomp_types.h" 2 #include "guest_memory.h" 3 #include "guest_crt.h" 4 #include <assert.h> 5 #include <stdio.h> 6 #include <string.h> 7 8 void sub_400026B0(void); 9 static uint32_t physical_memory; 10 11 static void open_database(void) 12 { 13 assert(g_ecx == 0x50000500 && MEM32(g_esp + 4) == 0); 14 g_eax = 17; 15 g_esp += 8; 16 } 17 18 static void memory_status(void) 19 { 20 uint32_t output = MEM32(g_esp + 4); 21 memset((void *)ADDR(output), 0, 32); 22 MEM32(output + 8) = physical_memory; 23 g_esp += 8; 24 } 25 26 static void current_time(void) 27 { 28 assert(!MEM32(g_esp + 4)); 29 g_eax = 12345; 30 g_esp += 4; 31 } 32 33 recomp_func_t recomp_lookup(uint32_t address) 34 { 35 switch (address) { 36 case 0x70000100: return open_database; 37 case 0x70000200: return memory_status; 38 case 0x70000300: return current_time; 39 case 0x40014864: return guest_crt_lookup("_ftol"); 40 default: assert(0); return NULL; 41 } 42 } 43 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 44 recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); } 45 46 static void open_with_memory(uint32_t total, uint32_t expected) 47 { 48 memset((void *)ADDR(0x50000100), 0, 0x300); 49 physical_memory = total; 50 MEM32(0x5000010c) = 0x50000500; 51 MEM32(0x50000500) = 0x50000600; 52 MEM32(0x50000648) = 0x70000100; 53 g_esp = 0x5000ff00; 54 MEM32(g_esp) = RECOMP_RETADDR; 55 g_ecx = 0x50000100; 56 g_ebp = 0x11223344; g_ebx = 0x22334455; 57 g_esi = 0x33445566; g_edi = 0x44556677; 58 59 sub_400026B0(); 60 61 assert(MEM32(0x50000274) == expected); 62 assert(g_eax == 17 && g_esp == 0x5000ff04 && g_fp_top == 0); 63 assert(g_ebp == 0x11223344 && g_ebx == 0x22334455); 64 assert(g_esi == 0x33445566 && g_edi == 0x44556677); 65 assert(MEM8(0x50000108) == 1 && MEM32(0x4001d06c) == 12345); 66 } 67 68 int main(void) 69 { 70 assert(guest_map("resource manager data", 0x40000000, 0x20000)); 71 assert(guest_map("resource manager fixture", 0x50000000, 0x10000)); 72 const double factor = 0.7; 73 memcpy((void *)ADDR(0x40016300), &factor, sizeof(factor)); 74 MEM32(0x40016008) = 0x70000200; 75 MEM32(0x400160dc) = 0x70000300; 76 open_with_memory(0x08000000, 0); 77 open_with_memory(0x09600000, 0); 78 open_with_memory(0x09700000, 734003); 79 open_with_memory(0x10000000, 67108864); 80 open_with_memory(0x7fffffff, 67108864); 81 puts("resource budget: low-memory limits, bounded retention, database result and guest ABI passed"); 82 }