aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/runtime/guest_memory.h (1037B)


      1 #ifndef GUEST_MEMORY_H
      2 #define GUEST_MEMORY_H
      3 
      4 #include <stdint.h>
      5 
      6 /* Module allocations are aligned to 64 KiB in the guest address space. */
      7 uint32_t guest_map(const char *name, uint32_t base, uint32_t size);
      8 
      9 #ifdef RECOMP_PORTABLE
     10 extern unsigned char *guest_pages[65536];
     11 void guest_memory_fault(uint32_t address);
     12 
     13 #if defined(__linux__) && UINTPTR_MAX > UINT32_MAX
     14 extern unsigned char *guest_base;
     15 
     16 static inline uintptr_t guest_address(uint32_t address)
     17 {
     18     /* Unmapped pages remain inaccessible in the reserved guest address space. */
     19     return address ? (uintptr_t)guest_base + address : 0;
     20 }
     21 #else
     22 static inline uintptr_t guest_address(uint32_t address)
     23 {
     24     /* Null pointers also occur in zero-length bulk operations. */
     25     if (!address) return 0;
     26     unsigned char *page = guest_pages[address >> 16];
     27     if (!page) guest_memory_fault(address);
     28     return (uintptr_t)(page + (address & 0xffffu));
     29 }
     30 #endif
     31 #else
     32 static inline uintptr_t guest_address(uint32_t address)
     33 {
     34     return (uintptr_t)address;
     35 }
     36 #endif
     37 
     38 #endif