MemArena.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #ifdef _WIN32
  7. #include <windows.h>
  8. #endif
  9. #include "Common/CommonTypes.h"
  10. // This class lets you create a block of anonymous RAM, and then arbitrarily map views into it.
  11. // Multiple views can mirror the same section of the block, which makes it very convenient for emulating
  12. // memory mirrors.
  13. class MemArena
  14. {
  15. public:
  16. void GrabSHMSegment(size_t size);
  17. void ReleaseSHMSegment();
  18. void *CreateView(s64 offset, size_t size, void *base = nullptr);
  19. void ReleaseView(void *view, size_t size);
  20. // This finds 1 GB in 32-bit, 16 GB in 64-bit.
  21. static u8 *FindMemoryBase();
  22. private:
  23. #ifdef _WIN32
  24. HANDLE hMemoryMapping;
  25. #else
  26. int fd;
  27. #endif
  28. };
  29. enum {
  30. MV_MIRROR_PREVIOUS = 1,
  31. MV_FAKE_VMEM = 2,
  32. MV_WII_ONLY = 4,
  33. };
  34. struct MemoryView
  35. {
  36. u8** out_ptr;
  37. u64 virtual_address;
  38. u32 size;
  39. u32 flags;
  40. void* mapped_ptr;
  41. void* view_ptr;
  42. u32 shm_position;
  43. };
  44. // Uses a memory arena to set up an emulator-friendly memory map according to
  45. // a passed-in list of MemoryView structures.
  46. u8 *MemoryMap_Setup(MemoryView *views, int num_views, u32 flags, MemArena *arena);
  47. void MemoryMap_Shutdown(MemoryView *views, int num_views, u32 flags, MemArena *arena);