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