mem_arena.h 2.1 KB

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