mem_arena.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifdef __SYMBIAN32__
  18. #include <e32std.h>
  19. #endif
  20. #include "common/common.h"
  21. // This class lets you create a block of anonymous RAM, and then arbitrarily map views into it.
  22. // Multiple views can mirror the same section of the block, which makes it very convient for emulating
  23. // memory mirrors.
  24. class MemArena
  25. {
  26. public:
  27. void GrabLowMemSpace(size_t size);
  28. void ReleaseSpace();
  29. void *CreateView(s64 offset, size_t size, void *base = 0);
  30. void ReleaseView(void *view, size_t size);
  31. #ifdef __SYMBIAN32__
  32. RChunk* memmap;
  33. #else
  34. // This only finds 1 GB in 32-bit
  35. static u8 *Find4GBBase();
  36. #endif
  37. private:
  38. #ifdef _WIN32
  39. HANDLE hMemoryMapping;
  40. #else
  41. int fd;
  42. #endif
  43. };
  44. enum {
  45. MV_MIRROR_PREVIOUS = 1,
  46. // MV_FAKE_VMEM = 2,
  47. // MV_WII_ONLY = 4,
  48. MV_IS_PRIMARY_RAM = 0x100,
  49. MV_IS_EXTRA1_RAM = 0x200,
  50. MV_IS_EXTRA2_RAM = 0x400,
  51. };
  52. struct MemoryView
  53. {
  54. u8 **out_ptr_low;
  55. u8 **out_ptr;
  56. u32 virtual_address;
  57. u32 size;
  58. u32 flags;
  59. };
  60. // Uses a memory arena to set up an emulator-friendly memory map according to
  61. // a passed-in list of MemoryView structures.
  62. u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena *arena);
  63. void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemArena *arena);