1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     ro_Module.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: 47425 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_RO_RO_MODULE_H_
17 #define NN_RO_RO_MODULE_H_
18 
19 #include <nn/Handle.h>
20 #include <nn/Result.h>
21 #include <nn/types.h>
22 #include <nn/util.h>
23 #include <nn/config.h>
24 
25 
26 namespace nn {
27 namespace ro {
28 
29     //---------------------------------------------------------------------------
30     //
31     //
32     //
33     //
34     //
35     //
36     //
37     //---------------------------------------------------------------------------
38     class Module : private util::NonCopyable<Module>
39     {
40     private:
41         uptr    m_Dummy;
42 
43     public:
44         //----------------------------------------------------------------------
45         //
46         //
47         //
48         //
49         //
50         //
51         //----------------------------------------------------------------------
52         class EnumerateCallback
53         {
54         public:
55             //----------------------------------------------------------------------
56             //
57             //
58             //
59             //
60             //
61             //
62             //
63             //
64             //
65             //
66             //
67             //----------------------------------------------------------------------
68             virtual bool operator()(Module* p) = 0;
69         };
70 
71     public:
~Module()72         ~Module()
73         {
74             Unload();
75         }
delete(void * p)76         void operator delete(void* p)
77         {
78             NN_UNUSED_VAR(p);
79             // Does nothing
80         }
81 
82         //---------------------------------------------------------------------------
83         //
84         //
85         //
86         //
87         //
88         //
89         //
90         //
91         //
92         //
93         //
94         //---------------------------------------------------------------------------
95         Result  Link();
96 
97         //---------------------------------------------------------------------------
98         //
99         //---------------------------------------------------------------------------
100         Result  Unlink();
101 
102         //---------------------------------------------------------------------------
103         //
104         //
105         //
106         //
107         //
108         //
109         //
110         //
111         //
112         //
113         //
114         //
115         //
116         //
117         //
118         //
119         //
120         //
121         //
122         //
123         //
124         //
125         //---------------------------------------------------------------------------
126         Result  Unload();
127 
128         //---------------------------------------------------------------------------
129         //
130         //
131         //
132         //
133         //
134         //
135         //
136         //
137         //
138         //
139         //
140         //
141         //---------------------------------------------------------------------------
142         bool    IsAllSymbolResolved() const;
143 
144         //---------------------------------------------------------------------------
145         //
146         //
147         //
148         //
149         //
150         //
151         //---------------------------------------------------------------------------
152         const char* GetName() const;
153 
154         //---------------------------------------------------------------------------
155         //
156         //
157         //
158         //
159         //
160         //
161         //
162         //
163         //---------------------------------------------------------------------------
164         void    DoInitialize();
165 
166         //---------------------------------------------------------------------------
167         //
168         //
169         //
170         //
171         //
172         //
173         //
174         //
175         //---------------------------------------------------------------------------
176         void    DoFinalize();
177 
178 
179         //---------------------------------------------------------------------------
180         //
181         //
182         //
183         //
184         //
185         //
186         //
187         //
188         //
189         //
190         //
191         //
192         //
193         //
194         //---------------------------------------------------------------------------
195         template<typename T>
GetPointer(const char * name)196         T       GetPointer(const char* name) const
197         { return reinterpret_cast<T>(GetAddress(name)); }
198 
199         //---------------------------------------------------------------------------
200         //
201         //
202         //
203         //
204         //
205         //
206         //
207         //
208         //
209         //
210         //
211         //
212         //---------------------------------------------------------------------------
213         template<typename T>
GetPointer(s32 index)214         T       GetPointer(s32 index) const
215         { return reinterpret_cast<T>(GetAddress(index)); }
216 
217         //---------------------------------------------------------------------------
218         //
219         //
220         //
221         //---------------------------------------------------------------------------
222         void GetRegionInfo(RegionInfo* pri);
223 
224         //---------------------------------------------------------------------------
225         //
226         //
227         //
228         //
229         //
230         //
231         //
232         //
233         //
234         //
235         //---------------------------------------------------------------------------
236         static void Enumerate(EnumerateCallback* p);
237 
238         //---------------------------------------------------------------------------
239         //
240         //
241         //
242         //
243         //
244         //
245         //
246         //
247         //
248         //
249         //
250         //---------------------------------------------------------------------------
251         static Module*  Find(const char* pName);
252 
253     private:
254         Module();
255         void*   operator new(size_t size) throw ();
256         uptr    GetAddress(const char* name) const;
257         uptr    GetAddress(s32 index) const;
258 
GetHead()259         uptr    GetHead() { return reinterpret_cast<uptr>(this); }
260     };
261 
262 } // end of namespace ro
263 } // end of namespace nn
264 
265 
266 
267 #endif  // ifndef NN_RO_RO_MODULE_H_
268