MemoryManagerType.cs
1 namespace ARMeilleure.Memory 2 { 3 /// <summary> 4 /// Indicates the type of a memory manager and the method it uses for memory mapping 5 /// and address translation. This controls the code generated for memory accesses on the JIT. 6 /// </summary> 7 public enum MemoryManagerType 8 { 9 /// <summary> 10 /// Complete software MMU implementation, the read/write methods are always called, 11 /// without any attempt to perform faster memory access. 12 /// </summary> 13 SoftwareMmu, 14 15 /// <summary> 16 /// High level implementation using a software flat page table for address translation, 17 /// used to speed up address translation if possible without calling the read/write methods. 18 /// </summary> 19 SoftwarePageTable, 20 21 /// <summary> 22 /// High level implementation with mappings managed by the host OS, effectively using hardware 23 /// page tables. No address translation is performed in software and the memory is just accessed directly. 24 /// </summary> 25 HostMapped, 26 27 /// <summary> 28 /// Same as the host mapped memory manager type, but without masking the address within the address space. 29 /// Allows invalid access from JIT code to the rest of the program, but is faster. 30 /// </summary> 31 HostMappedUnsafe, 32 33 /// <summary> 34 /// High level implementation using a software flat page table for address translation 35 /// with no support for handling invalid or non-contiguous memory access. 36 /// </summary> 37 HostTracked, 38 39 /// <summary> 40 /// High level implementation using a software flat page table for address translation 41 /// without masking the address and no support for handling invalid or non-contiguous memory access. 42 /// </summary> 43 HostTrackedUnsafe, 44 } 45 46 public static class MemoryManagerTypeExtensions 47 { 48 public static bool IsHostMapped(this MemoryManagerType type) 49 { 50 return type == MemoryManagerType.HostMapped || type == MemoryManagerType.HostMappedUnsafe; 51 } 52 53 public static bool IsHostTracked(this MemoryManagerType type) 54 { 55 return type == MemoryManagerType.HostTracked || type == MemoryManagerType.HostTrackedUnsafe; 56 } 57 58 public static bool IsHostMappedOrTracked(this MemoryManagerType type) 59 { 60 return type.IsHostMapped() || type.IsHostTracked(); 61 } 62 } 63 }