author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 39 | 2bb754abd467 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\include\emulator.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@publishedPartner |
|
21 |
@released |
|
22 |
*/ |
|
23 |
||
24 |
#ifndef __EMULATOR_H__ |
|
25 |
#define __EMULATOR_H__ |
|
26 |
||
27 |
#include <e32def.h> |
|
28 |
#define WIN32_LEAN_AND_MEAN |
|
29 |
#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union |
|
30 |
#include <windows.h> |
|
31 |
#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union |
|
32 |
||
33 |
class TUidType; |
|
34 |
class TProcessCreateInfo; |
|
35 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
// Names of sections that we are interested in looking at. These are used by the GetSectionsSize() |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
37 |
// routine to determine the minimum number of bytes of a DLL to map into memory in order to examine |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
38 |
// its sections. If a new section is added here then it must also be added to the list of sections |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
// held in the sectionNames array in GetSectionsSize() |
0 | 40 |
static const BYTE KWin32SectionName_Symbian[IMAGE_SIZEOF_SHORT_NAME] = {'.','S','Y','M','B','I','A','N'}; |
41 |
static const BYTE KWin32SectionName_Import[IMAGE_SIZEOF_SHORT_NAME] = {'.','i','d','a','t','a','\0','\0'}; |
|
42 |
static const BYTE KWin32SectionName_EpocData[IMAGE_SIZEOF_SHORT_NAME] = {'.','d','a','t','a','\0','\0','\0'}; |
|
43 |
static const BYTE KWin32SectionName_EpocBss[IMAGE_SIZEOF_SHORT_NAME] = {'.','b','s','s','\0','\0','\0','\0'}; |
|
44 |
static const BYTE KWin32SectionName_Text[IMAGE_SIZEOF_SHORT_NAME] = {'.','t','e','x','t','\0','\0','\0'}; |
|
45 |
static const BYTE KWin32SectionName_RData[IMAGE_SIZEOF_SHORT_NAME] = {'.','r','d','a','t','a','\0','\0'}; |
|
46 |
static const BYTE KWin32SectionName_NmdExpData[IMAGE_SIZEOF_SHORT_NAME] = {'.','e','x','p','d','a','t','a'}; |
|
47 |
||
48 |
/** |
|
49 |
Emulator utility functions. These APIs should only be used for extensions to emulator |
|
50 |
functionality and are unsupported on non-emulator platforms. |
|
51 |
||
52 |
@publishedPartner |
|
53 |
@released |
|
54 |
*/ |
|
55 |
struct Emulator |
|
56 |
{ |
|
57 |
public: |
|
58 |
||
59 |
/** |
|
60 |
Declares a function pointer to TLock. |
|
61 |
||
62 |
@see TLock. |
|
63 |
*/ |
|
64 |
typedef void (*TLockFunc)(); |
|
65 |
||
66 |
/** |
|
67 |
Declares a function pointer to Win32SEHException. |
|
68 |
||
69 |
@see Win32SEHException. |
|
70 |
*/ |
|
71 |
typedef DWORD (*TExceptionFunc)(EXCEPTION_RECORD* aException, CONTEXT* aContext); |
|
72 |
||
73 |
/** |
|
74 |
A structure which packs parameters to be inintialized. |
|
75 |
*/ |
|
76 |
struct SInit |
|
77 |
{ |
|
78 |
TUint iCodePage; |
|
79 |
TLockFunc iLock; |
|
80 |
TLockFunc iUnlock; |
|
81 |
TLockFunc iEscape; |
|
82 |
TLockFunc iReenter; |
|
83 |
TExceptionFunc iException; |
|
84 |
}; |
|
85 |
||
86 |
/** |
|
87 |
A structure which handles the global lock for host interaction. |
|
88 |
*/ |
|
89 |
struct TLock |
|
90 |
{ |
|
91 |
||
92 |
/** |
|
93 |
Constructor which calls the Emulator::Lock() function. |
|
94 |
||
95 |
@see Emulator::Lock(). |
|
96 |
*/ |
|
97 |
inline TLock() |
|
98 |
{Emulator::Lock();} |
|
99 |
||
100 |
/** |
|
101 |
Destructor which calls the Emulator::Unlock() function. |
|
102 |
||
103 |
@see Emulator::Unlock(). |
|
104 |
*/ |
|
105 |
inline ~TLock() |
|
106 |
{Emulator::Unlock();} |
|
107 |
}; |
|
108 |
||
109 |
/** |
|
110 |
A structure which handles current thread by taking in or out of the emulator scheduling model. |
|
111 |
*/ |
|
112 |
struct TEscape |
|
113 |
{ |
|
114 |
||
115 |
/** |
|
116 |
Constructor which calls the Emulator::Escape() function. |
|
117 |
||
118 |
@see Emulator::Escape(). |
|
119 |
*/ |
|
120 |
inline TEscape() |
|
121 |
{Emulator::Escape();} |
|
122 |
||
123 |
/** |
|
124 |
Destructor which calls the Emulator::Reenter() function. |
|
125 |
||
126 |
@see Emulator::Reenter(). |
|
127 |
*/ |
|
128 |
inline ~TEscape() |
|
129 |
{Emulator::Reenter();} |
|
130 |
}; |
|
131 |
#define __LOCK_HOST Emulator::TLock __lock |
|
132 |
#define __ESCAPE_HOST Emulator::TEscape __escape |
|
133 |
public: |
|
134 |
||
135 |
IMPORT_C static void Init(const SInit& aInit); |
|
136 |
// |
|
137 |
IMPORT_C static void Lock(); |
|
138 |
IMPORT_C static void Unlock(); |
|
139 |
IMPORT_C static void Escape(); |
|
140 |
IMPORT_C static void Reenter(); |
|
141 |
// |
|
142 |
IMPORT_C static DWORD Win32SEHException(EXCEPTION_RECORD* aException, CONTEXT* aContext); |
|
143 |
// |
|
144 |
IMPORT_C static TInt LastError(); |
|
145 |
IMPORT_C static BOOL CreateDirectory(LPCTSTR, LPSECURITY_ATTRIBUTES); |
|
146 |
IMPORT_C static BOOL CreateAllDirectories(LPCSTR); |
|
147 |
IMPORT_C static HANDLE CreateFile(LPCTSTR ,DWORD ,DWORD ,LPSECURITY_ATTRIBUTES ,DWORD ,DWORD ,HANDLE); |
|
148 |
IMPORT_C static BOOL DeleteFile(LPCTSTR); |
|
149 |
IMPORT_C static HANDLE FindFirstFile(LPCTSTR ,LPWIN32_FIND_DATA); |
|
150 |
IMPORT_C static BOOL FindNextFile(HANDLE ,LPWIN32_FIND_DATA); |
|
151 |
IMPORT_C static BOOL GetDiskFreeSpace(LPCTSTR ,LPDWORD ,LPDWORD ,LPDWORD ,LPDWORD); |
|
152 |
IMPORT_C static DWORD GetFileAttributes(LPCTSTR); |
|
153 |
IMPORT_C static HMODULE GetModuleHandle(LPCTSTR); |
|
154 |
IMPORT_C static DWORD GetCurrentDirectory(DWORD ,LPTSTR); |
|
155 |
IMPORT_C static DWORD GetTempPath(DWORD ,LPTSTR); |
|
156 |
IMPORT_C static BOOL GetVolumeInformation(LPCTSTR ,LPTSTR ,DWORD ,LPDWORD ,LPDWORD ,LPDWORD ,LPTSTR,DWORD); |
|
157 |
IMPORT_C static HMODULE LoadLibrary(LPCTSTR); |
|
158 |
IMPORT_C static BOOL FreeLibrary(HMODULE); |
|
159 |
IMPORT_C static BOOL MoveFile(LPCTSTR ,LPCTSTR); |
|
160 |
IMPORT_C static BOOL CopyFile(LPCTSTR ,LPCTSTR, BOOL); |
|
161 |
IMPORT_C static VOID OutputDebugString(LPCTSTR); |
|
162 |
IMPORT_C static BOOL RemoveDirectory(LPCTSTR); |
|
163 |
IMPORT_C static BOOL SetFileAttributes(LPCTSTR ,DWORD); |
|
164 |
IMPORT_C static BOOL SetVolumeLabel(LPCTSTR ,LPCTSTR); |
|
165 |
IMPORT_C static FARPROC GetProcAddress(HMODULE, LPCSTR); |
|
166 |
IMPORT_C static DWORD GetModuleFileName(HMODULE hModule, LPWSTR lpFilename); |
|
167 |
public: |
|
168 |
||
169 |
/** |
|
170 |
A class which holds a loaded module of the file system. |
|
171 |
*/ |
|
172 |
class TModule |
|
173 |
{ |
|
174 |
public: |
|
175 |
||
176 |
/** |
|
177 |
Constructor which sets the handles of loaded module to current instance of the application. |
|
178 |
||
179 |
@param aModule A handle to the current instance of the application. |
|
180 |
*/ |
|
181 |
inline TModule(HINSTANCE aModule) |
|
182 |
:iModule(aModule), iBase(aModule) |
|
183 |
{} |
|
184 |
||
185 |
IMPORT_C TModule(LPCSTR aModuleName); |
|
186 |
||
187 |
/** |
|
188 |
Checks the validity of the loaded module. |
|
189 |
||
190 |
@return TRUE, if the function succeeds |
|
191 |
FALSE, if the function fails |
|
192 |
*/ |
|
193 |
inline TBool IsValid() const |
|
194 |
{return iBase!=NULL;} |
|
195 |
||
196 |
/** |
|
197 |
Relocates the address of the loaded module by appending aRawVirtualAddress to the handle of loaded module. |
|
198 |
||
199 |
@param aRawVirtualAddress Contains the address of the first byte of the section when loaded into |
|
200 |
memory, relative to the image base. For object files, this is the |
|
201 |
address of the first byte before relocation is applied. |
|
202 |
||
203 |
@return Returns the actual address of the handle. |
|
204 |
*/ |
|
205 |
inline const TAny* Translate(TInt32 aRawVirtualAddress) const |
|
206 |
{return (const TUint8*)iBase + aRawVirtualAddress;} |
|
207 |
||
208 |
||
209 |
IMPORT_C void GetUids(TUidType& aType) const; |
|
210 |
IMPORT_C void GetInfo(TProcessCreateInfo& aInfo) const; |
|
211 |
public: |
|
212 |
||
213 |
/** |
|
214 |
Default constructor which sets the handles of loaded module or mapped file image to the default handle. |
|
215 |
*/ |
|
216 |
inline TModule() |
|
217 |
:iModule(0), iBase(0) |
|
218 |
{} |
|
219 |
||
220 |
/** |
|
221 |
Checks whether the current module is a loaded module, or just a mapped file image. |
|
222 |
||
223 |
@return TRUE, if the current module is a loaded module |
|
224 |
FALSE, if the current module is a mapped image |
|
225 |
*/ |
|
226 |
TBool IsLoaded() const // Is this a loaded module, or just a mapped file image. |
|
227 |
{return iModule != 0;} |
|
228 |
||
229 |
IMPORT_C const IMAGE_NT_HEADERS32* NtHeader() const; |
|
230 |
||
231 |
/** |
|
232 |
Passes the handle of a loaded module to the calling module. |
|
233 |
||
234 |
@return Returns a handle of a loaded module. |
|
235 |
*/ |
|
236 |
const TAny* Base() const |
|
237 |
{return iBase;} |
|
238 |
||
239 |
IMPORT_C const IMAGE_SECTION_HEADER* SectionHeader(const BYTE aSection[]) const; |
|
240 |
IMPORT_C const TAny* Section(const BYTE aSection[]) const; |
|
241 |
IMPORT_C const IMAGE_IMPORT_DESCRIPTOR* Imports() const; |
|
242 |
public: |
|
243 |
||
244 |
/** |
|
245 |
A handle to a loaded module. |
|
246 |
*/ |
|
247 |
HMODULE iModule; |
|
248 |
||
249 |
/** |
|
250 |
A handle to a loaded module for the mapped view. |
|
251 |
*/ |
|
252 |
const TAny* iBase; |
|
253 |
}; |
|
254 |
||
255 |
/** |
|
256 |
A class which holds a mapped image of the file system. |
|
257 |
*/ |
|
258 |
class RImageFile : public TModule |
|
259 |
{ |
|
260 |
public: |
|
261 |
||
262 |
/** |
|
263 |
Constructor which sets the handle of the mapped image file to default handle. |
|
264 |
*/ |
|
265 |
inline RImageFile() |
|
266 |
: iMapping(0) |
|
267 |
{} |
|
268 |
||
269 |
IMPORT_C TInt Open(LPCTSTR aImageFile); |
|
270 |
IMPORT_C void Close(); |
|
271 |
private: |
|
272 |
||
273 |
/** |
|
274 |
A handle to the mapped image file. |
|
275 |
*/ |
|
276 |
HANDLE iMapping; |
|
277 |
}; |
|
278 |
}; |
|
279 |
||
280 |
||
281 |
#endif |