mem_arena.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2003 Dolphin Project.
  2. // This program is free software: you can redistribute it and/or modify
  3. // it under the terms of the GNU General Public License as published by
  4. // the Free Software Foundation, version 2.0 or later versions.
  5. // This program is distributed in the hope that it will be useful,
  6. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. // GNU General Public License 2.0 for more details.
  9. // A copy of the GPL 2.0 should have been included with the program.
  10. // If not, see http://www.gnu.org/licenses/
  11. // Official SVN repository and contact information can be found at
  12. // http://code.google.com/p/dolphin-emu/
  13. #pragma once
  14. #ifdef _WIN32
  15. #include <windows.h>
  16. #endif
  17. #include "common/common_types.h"
  18. // This class lets you create a block of anonymous RAM, and then arbitrarily map views into it.
  19. // Multiple views can mirror the same section of the block, which makes it very convient for emulating
  20. // memory mirrors.
  21. class MemArena
  22. {
  23. public:
  24. void GrabLowMemSpace(size_t size);
  25. void ReleaseSpace();
  26. void *CreateView(s64 offset, size_t size, void *base = 0);
  27. void ReleaseView(void *view, size_t size);
  28. // This only finds 1 GB in 32-bit
  29. static u8 *Find4GBBase();
  30. private:
  31. #ifdef _WIN32
  32. HANDLE hMemoryMapping;
  33. #else
  34. int fd;
  35. #endif
  36. };
  37. enum {
  38. MV_MIRROR_PREVIOUS = 1,
  39. // MV_FAKE_VMEM = 2,
  40. // MV_WII_ONLY = 4,
  41. MV_IS_PRIMARY_RAM = 0x100,
  42. MV_IS_EXTRA1_RAM = 0x200,
  43. MV_IS_EXTRA2_RAM = 0x400,
  44. };
  45. struct MemoryView
  46. {
  47. u8 **out_ptr_low;
  48. u8 **out_ptr;
  49. u32 virtual_address;
  50. u32 size;
  51. u32 flags;
  52. };
  53. // Uses a memory arena to set up an emulator-friendly memory map according to
  54. // a passed-in list of MemoryView structures.
  55. u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena *arena);
  56. void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemArena *arena);