Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\emulator.h
24 #ifndef __EMULATOR_H__
25 #define __EMULATOR_H__
28 #ifndef WIN32_LEAN_AND_MEAN
29 # define WIN32_LEAN_AND_MEAN
31 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
33 #pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
36 class TProcessCreateInfo;
38 static const BYTE KWin32SectionName_Symbian[IMAGE_SIZEOF_SHORT_NAME] = {'.','S','Y','M','B','I','A','N'};
39 static const BYTE KWin32SectionName_Import[IMAGE_SIZEOF_SHORT_NAME] = {'.','i','d','a','t','a','\0','\0'};
40 static const BYTE KWin32SectionName_EpocData[IMAGE_SIZEOF_SHORT_NAME] = {'.','d','a','t','a','\0','\0','\0'};
41 static const BYTE KWin32SectionName_EpocBss[IMAGE_SIZEOF_SHORT_NAME] = {'.','b','s','s','\0','\0','\0','\0'};
42 static const BYTE KWin32SectionName_Text[IMAGE_SIZEOF_SHORT_NAME] = {'.','t','e','x','t','\0','\0','\0'};
43 static const BYTE KWin32SectionName_RData[IMAGE_SIZEOF_SHORT_NAME] = {'.','r','d','a','t','a','\0','\0'};
44 static const BYTE KWin32SectionName_NmdExpData[IMAGE_SIZEOF_SHORT_NAME] = {'.','e','x','p','d','a','t','a'};
47 Emulator utility functions. These APIs should only be used for extensions to emulator
48 functionality and are unsupported on non-emulator platforms.
58 Declares a function pointer to TLock.
62 typedef void (*TLockFunc)();
65 Declares a function pointer to Win32SEHException.
67 @see Win32SEHException.
69 typedef DWORD (*TExceptionFunc)(EXCEPTION_RECORD* aException, CONTEXT* aContext);
72 A structure which packs parameters to be inintialized.
81 TExceptionFunc iException;
85 A structure which handles the global lock for host interaction.
91 Constructor which calls the Emulator::Lock() function.
93 @see Emulator::Lock().
99 Destructor which calls the Emulator::Unlock() function.
101 @see Emulator::Unlock().
104 {Emulator::Unlock();}
108 A structure which handles current thread by taking in or out of the emulator scheduling model.
114 Constructor which calls the Emulator::Escape() function.
116 @see Emulator::Escape().
119 {Emulator::Escape();}
122 Destructor which calls the Emulator::Reenter() function.
124 @see Emulator::Reenter().
127 {Emulator::Reenter();}
129 #define __LOCK_HOST Emulator::TLock __lock
130 #define __ESCAPE_HOST Emulator::TEscape __escape
133 IMPORT_C static void Init(const SInit& aInit);
135 IMPORT_C static void Lock();
136 IMPORT_C static void Unlock();
137 IMPORT_C static void Escape();
138 IMPORT_C static void Reenter();
140 IMPORT_C static DWORD Win32SEHException(EXCEPTION_RECORD* aException, CONTEXT* aContext);
142 IMPORT_C static TInt LastError();
143 IMPORT_C static BOOL CreateDirectory(LPCTSTR, LPSECURITY_ATTRIBUTES);
144 IMPORT_C static BOOL CreateAllDirectories(LPCSTR);
145 IMPORT_C static HANDLE CreateFile(LPCTSTR ,DWORD ,DWORD ,LPSECURITY_ATTRIBUTES ,DWORD ,DWORD ,HANDLE);
146 IMPORT_C static BOOL DeleteFile(LPCTSTR);
147 IMPORT_C static HANDLE FindFirstFile(LPCTSTR ,LPWIN32_FIND_DATA);
148 IMPORT_C static BOOL FindNextFile(HANDLE ,LPWIN32_FIND_DATA);
149 IMPORT_C static BOOL GetDiskFreeSpace(LPCTSTR ,LPDWORD ,LPDWORD ,LPDWORD ,LPDWORD);
150 IMPORT_C static DWORD GetFileAttributes(LPCTSTR);
151 IMPORT_C static HMODULE GetModuleHandle(LPCTSTR);
152 IMPORT_C static DWORD GetCurrentDirectory(DWORD ,LPTSTR);
153 IMPORT_C static DWORD GetTempPath(DWORD ,LPTSTR);
154 IMPORT_C static BOOL GetVolumeInformation(LPCTSTR ,LPTSTR ,DWORD ,LPDWORD ,LPDWORD ,LPDWORD ,LPTSTR,DWORD);
155 IMPORT_C static HMODULE LoadLibrary(LPCTSTR);
156 IMPORT_C static BOOL FreeLibrary(HMODULE);
157 IMPORT_C static BOOL MoveFile(LPCTSTR ,LPCTSTR);
158 IMPORT_C static BOOL CopyFile(LPCTSTR ,LPCTSTR, BOOL);
159 IMPORT_C static VOID OutputDebugString(LPCTSTR);
160 IMPORT_C static BOOL RemoveDirectory(LPCTSTR);
161 IMPORT_C static BOOL SetFileAttributes(LPCTSTR ,DWORD);
162 IMPORT_C static BOOL SetVolumeLabel(LPCTSTR ,LPCTSTR);
163 IMPORT_C static FARPROC GetProcAddress(HMODULE, LPCSTR);
164 IMPORT_C static DWORD GetModuleFileName(HMODULE hModule, LPWSTR lpFilename);
168 A class which holds a loaded module of the file system.
175 Constructor which sets the handles of loaded module to current instance of the application.
177 @param aModule A handle to the current instance of the application.
179 inline TModule(HINSTANCE aModule)
180 :iModule(aModule), iBase(aModule)
183 IMPORT_C TModule(LPCSTR aModuleName);
186 Checks the validity of the loaded module.
188 @return TRUE, if the function succeeds
189 FALSE, if the function fails
191 inline TBool IsValid() const
192 {return iBase!=NULL;}
195 Relocates the address of the loaded module by appending aRawVirtualAddress to the handle of loaded module.
197 @param aRawVirtualAddress Contains the address of the first byte of the section when loaded into
198 memory, relative to the image base. For object files, this is the
199 address of the first byte before relocation is applied.
201 @return Returns the actual address of the handle.
203 inline const TAny* Translate(TInt32 aRawVirtualAddress) const
204 {return (const TUint8*)iBase + aRawVirtualAddress;}
207 IMPORT_C void GetUids(TUidType& aType) const;
208 IMPORT_C void GetInfo(TProcessCreateInfo& aInfo) const;
212 Default constructor which sets the handles of loaded module or mapped file image to the default handle.
215 :iModule(0), iBase(0)
219 Checks whether the current module is a loaded module, or just a mapped file image.
221 @return TRUE, if the current module is a loaded module
222 FALSE, if the current module is a mapped image
224 TBool IsLoaded() const // Is this a loaded module, or just a mapped file image.
225 {return iModule != 0;}
227 IMPORT_C const IMAGE_NT_HEADERS32* NtHeader() const;
230 Passes the handle of a loaded module to the calling module.
232 @return Returns a handle of a loaded module.
234 const TAny* Base() const
237 IMPORT_C const IMAGE_SECTION_HEADER* SectionHeader(const BYTE aSection[]) const;
238 IMPORT_C const TAny* Section(const BYTE aSection[]) const;
239 IMPORT_C const IMAGE_IMPORT_DESCRIPTOR* Imports() const;
243 A handle to a loaded module.
248 A handle to a loaded module for the mapped view.
254 A class which holds a mapped image of the file system.
256 class RImageFile : public TModule
261 Constructor which sets the handle of the mapped image file to default handle.
267 IMPORT_C TInt Open(LPCTSTR aImageFile);
268 IMPORT_C void Close();
272 A handle to the mapped image file.