1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: os_MemoryBlock.h 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 24156 $ 11 *--------------------------------------------------------------------------- 12 13 14 */ 15 16 /* Please see man pages for details 17 18 19 20 */ 21 22 #ifndef NN_OS_OS_MEMORYBLOCK_H_ 23 #define NN_OS_OS_MEMORYBLOCK_H_ 24 25 #include <nn/config.h> 26 #if NN_PLATFORM_HAS_MMU 27 28 #include <nn/types.h> 29 #include <nn/Handle.h> 30 #include <nn/svc.h> 31 #include <nn/os/CTR/os_MemoryConfig.h> 32 #include <nn/os/os_MemoryBlockBase.h> 33 34 #ifdef __cplusplus 35 36 #include <nn/util/util_NonCopyable.h> 37 #include <nn/os/os_SvcTypes.autogen.h> 38 #include <nn/util/util_Result.h> 39 40 namespace nn{ namespace os{ 41 42 class MemoryBlock; 43 44 namespace detail 45 { 46 uptr AllocateFromMemoryBlockSpace(MemoryBlockBase* p, size_t s); 47 void FreeToMemoryBlockSpace(MemoryBlockBase* p); 48 void Switch(MemoryBlock* pTo, MemoryBlock* pFrom); 49 50 bool IsMemoryBlockEnabled(); 51 } 52 53 54 /* Please see man pages for details 55 56 57 58 59 */ 60 class MemoryBlock : public MemoryBlockBase 61 { 62 public: 63 /* Please see man pages for details 64 65 66 67 68 69 */ MemoryBlock()70 MemoryBlock() {} 71 72 /* Please see man pages for details 73 74 75 76 77 78 79 80 81 */ MemoryBlock(size_t size)82 explicit MemoryBlock(size_t size) { Initialize(size); } 83 84 /* Please see man pages for details 85 86 87 88 89 90 91 92 */ 93 void Initialize(size_t size); 94 95 /* Please see man pages for details 96 97 98 99 100 */ ~MemoryBlock()101 ~MemoryBlock() { Finalize(); } 102 103 /* Please see man pages for details 104 105 */ 106 void Finalize(); 107 108 /* Please see man pages for details 109 110 111 112 */ 113 void SetReadOnly(bool readOnly = true); 114 GetPageAlignedSize(size_t size)115 static size_t GetPageAlignedSize(size_t size) { return (size + NN_OS_MEMORY_PAGE_SIZE - 1) & ~(NN_OS_MEMORY_PAGE_SIZE - 1); } 116 }; 117 118 /* 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 */ 139 void InitializeMemoryBlock(uptr begin, size_t size); 140 141 142 }} // namespace nn::os 143 144 #endif // __cplusplus 145 146 // C declarations follow 147 148 #include <nn/util/detail/util_CLibImpl.h> 149 150 /* Please see man pages for details 151 152 153 154 155 156 157 158 159 */ 160 161 /* Please see man pages for details 162 163 164 165 166 */ 167 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnosMemoryBlock, nn::os::MemoryBlock, 20, u32); 168 169 /* Please see man pages for details 170 171 */ 172 NN_EXTERN_C void nnosMemoryBlockAllocate(nnosMemoryBlock* p, size_t size); 173 174 /* Please see man pages for details 175 176 */ 177 NN_EXTERN_C void nnosMemoryBlockSetReadOnly(nnosMemoryBlock* p, bool readOnly); 178 179 /* 180 181 */ 182 NN_EXTERN_C void nnosMemoryBlockFree(nnosMemoryBlock* p); 183 184 /* Please see man pages for details 185 186 */ 187 NN_EXTERN_C uptr nnosMemoryBlockGetAddress(nnosMemoryBlock* p); 188 189 /* Please see man pages for details 190 191 */ 192 NN_EXTERN_C size_t nnosMemoryBlockGetSize(nnosMemoryBlock* p); 193 194 /* Please see man pages for details 195 196 */ 197 NN_EXTERN_C bool nnosMemoryBlockIsReadOnly(nnosMemoryBlock* p); 198 199 /* 200 201 202 203 */ 204 205 #endif // if NN_PLATFORM_HAS_MMU 206 #endif /* NN_OS_OS_MEMORYBLOCK_H_ */ 207