1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_StackMemory.h
4 
5   Copyright (C)2009 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: 38846 $
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 class StackMemory : public MemoryBlockBase
55 {
56 private:
57     uptr    m_MemoryAddress;
58 
59 public:
60     /* Please see man pages for details
61 
62 
63 
64 
65 
66     */
StackMemory()67     StackMemory() {}
68 
69     /* Please see man pages for details
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80     */
StackMemory(void * pMem,size_t size)81     explicit StackMemory(void* pMem, size_t size) { Initialize(pMem, size); }
82 
83 
84     /* Please see man pages for details
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98     */
99     Result TryInitialize(void* pMem, size_t size);
100 
101     /* Please see man pages for details
102 
103 
104 
105 
106 
107 
108 
109 
110 
111     */
112     void Initialize(void* pMem, size_t size);
113 
114     /* Please see man pages for details
115 
116 
117 
118 
119     */
~StackMemory()120     ~StackMemory() { Finalize(); }
121 
122     /* Please see man pages for details
123 
124 
125 
126 
127 
128 
129     */
130     void* Finalize();
131 
132     /* Please see man pages for details
133 
134 
135 
136 
137 
138     */
GetStackBottom()139     uptr GetStackBottom() const { return GetAddress() + GetSize(); }
140 
141     /* Please see man pages for details
142 
143 
144 
145 
146 
147     */
GetStackSize()148     size_t GetStackSize() const { return GetSize(); }
149 
150     void MoveFrom(StackMemory* pFrom);
151 };
152 
153 
154 
155 }} // namespace nn::os
156 
157 #endif // __cplusplus
158 
159 // Below is the C declaration
160 
161 #include <nn/util/detail/util_CLibImpl.h>
162 
163 /* Please see man pages for details
164 
165 
166 
167 
168 
169 
170 
171 
172 */
173 
174 /* Please see man pages for details
175 
176 
177 
178 
179 */
180 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnosStackMemory, nn::os::StackMemory, 24, u32);
181 
182 
183 /* Please see man pages for details
184 
185 */
186 NN_EXTERN_C void nnosStackMemoryProtect(nnosStackMemory* p, void* pMem, size_t size);
187 
188 /*
189 
190 */
191 NN_EXTERN_C void nnosStackMemoryUnprotect(nnosStackMemory* p);
192 
193 /* Please see man pages for details
194 
195 */
196 NN_EXTERN_C uptr nnosStackMemoryGetAddress(nnosStackMemory* p);
197 
198 /* Please see man pages for details
199 
200 */
201 NN_EXTERN_C size_t nnosStackMemoryGetSize(nnosStackMemory* p);
202 
203 /* Please see man pages for details
204 
205 */
206 NN_EXTERN_C uptr nnosStackMemoryGetStackBottom(nnosStackMemory* p);
207 
208 /*
209 
210 
211 
212 */
213 
214 #endif  // if NN_PLATFORM_HAS_MMU
215 #endif /* NN_OS_OS_STACKMEMORY_H_ */
216