os/kernelhwsrv/kernel/eka/include/emulator.h
changeset 0 bde4ae8d615e
child 1 260cb5ec6c19
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/emulator.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,277 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\emulator.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @publishedPartner
    1.24 + @released
    1.25 +*/
    1.26 +
    1.27 +#ifndef __EMULATOR_H__
    1.28 +#define __EMULATOR_H__
    1.29 +
    1.30 +#include <e32def.h>
    1.31 +#define WIN32_LEAN_AND_MEAN
    1.32 +#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
    1.33 +#include <windows.h>
    1.34 +#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
    1.35 +
    1.36 +class TUidType;
    1.37 +class TProcessCreateInfo;
    1.38 +
    1.39 +static const BYTE KWin32SectionName_Symbian[IMAGE_SIZEOF_SHORT_NAME]	= {'.','S','Y','M','B','I','A','N'};
    1.40 +static const BYTE KWin32SectionName_Import[IMAGE_SIZEOF_SHORT_NAME]		= {'.','i','d','a','t','a','\0','\0'};
    1.41 +static const BYTE KWin32SectionName_EpocData[IMAGE_SIZEOF_SHORT_NAME]	= {'.','d','a','t','a','\0','\0','\0'};
    1.42 +static const BYTE KWin32SectionName_EpocBss[IMAGE_SIZEOF_SHORT_NAME]	= {'.','b','s','s','\0','\0','\0','\0'};
    1.43 +static const BYTE KWin32SectionName_Text[IMAGE_SIZEOF_SHORT_NAME]		= {'.','t','e','x','t','\0','\0','\0'};
    1.44 +static const BYTE KWin32SectionName_RData[IMAGE_SIZEOF_SHORT_NAME]		= {'.','r','d','a','t','a','\0','\0'};
    1.45 +static const BYTE KWin32SectionName_NmdExpData[IMAGE_SIZEOF_SHORT_NAME]	= {'.','e','x','p','d','a','t','a'};
    1.46 +
    1.47 +/**
    1.48 +Emulator utility functions. These APIs should only be used for extensions to emulator 
    1.49 +functionality and are unsupported on non-emulator platforms.
    1.50 +
    1.51 +@publishedPartner
    1.52 +@released
    1.53 +*/
    1.54 +struct Emulator
    1.55 +	{
    1.56 +public:
    1.57 +
    1.58 +	/**
    1.59 +	Declares a function pointer to TLock.
    1.60 +	
    1.61 +	@see TLock.
    1.62 +	*/
    1.63 +	typedef void (*TLockFunc)();
    1.64 +	
    1.65 +	/**
    1.66 +	Declares a function pointer to Win32SEHException.
    1.67 +	
    1.68 +	@see Win32SEHException.		
    1.69 +	*/
    1.70 +	typedef DWORD (*TExceptionFunc)(EXCEPTION_RECORD* aException, CONTEXT* aContext);
    1.71 +	
    1.72 +	/**
    1.73 +	A structure which packs parameters to be inintialized. 
    1.74 +	*/
    1.75 +	struct SInit
    1.76 +		{
    1.77 +		TUint iCodePage;
    1.78 +		TLockFunc iLock;
    1.79 +		TLockFunc iUnlock;
    1.80 +		TLockFunc iEscape;
    1.81 +		TLockFunc iReenter;
    1.82 +		TExceptionFunc iException;
    1.83 +		};
    1.84 +	
    1.85 +	/**
    1.86 +	A structure which handles the global lock for host interaction.
    1.87 +	*/
    1.88 +	struct TLock
    1.89 +		{
    1.90 +		
    1.91 +		/**
    1.92 +		Constructor which calls the Emulator::Lock() function.
    1.93 +		
    1.94 +		@see Emulator::Lock().
    1.95 +		*/
    1.96 +		inline TLock()
    1.97 +			{Emulator::Lock();}
    1.98 +		
    1.99 +		/**
   1.100 +		Destructor which calls the Emulator::Unlock() function.
   1.101 +		
   1.102 +		@see Emulator::Unlock().
   1.103 +		*/
   1.104 +		inline ~TLock()
   1.105 +			{Emulator::Unlock();}
   1.106 +		};
   1.107 +		
   1.108 +	/**
   1.109 +	A structure which handles current thread by taking in or out of the emulator scheduling model.
   1.110 +	*/
   1.111 +	struct TEscape
   1.112 +		{
   1.113 +		
   1.114 +		/**
   1.115 +		Constructor which calls the Emulator::Escape() function.
   1.116 +		
   1.117 +		@see Emulator::Escape().
   1.118 +		*/
   1.119 +		inline TEscape()
   1.120 +			{Emulator::Escape();}
   1.121 +		
   1.122 +		/**
   1.123 +		Destructor which calls the Emulator::Reenter() function.
   1.124 +		
   1.125 +		@see Emulator::Reenter().
   1.126 +		*/
   1.127 +		inline ~TEscape()
   1.128 +			{Emulator::Reenter();}
   1.129 +		};
   1.130 +#define __LOCK_HOST Emulator::TLock __lock
   1.131 +#define __ESCAPE_HOST Emulator::TEscape __escape
   1.132 +public:
   1.133 +
   1.134 +	IMPORT_C static void Init(const SInit& aInit);
   1.135 +//
   1.136 +	IMPORT_C static void Lock();
   1.137 +	IMPORT_C static void Unlock();
   1.138 +	IMPORT_C static void Escape();
   1.139 +	IMPORT_C static void Reenter();
   1.140 +//
   1.141 +	IMPORT_C static DWORD Win32SEHException(EXCEPTION_RECORD* aException, CONTEXT* aContext);
   1.142 +//
   1.143 +	IMPORT_C static TInt LastError();
   1.144 +	IMPORT_C static BOOL CreateDirectory(LPCTSTR, LPSECURITY_ATTRIBUTES);
   1.145 +	IMPORT_C static BOOL CreateAllDirectories(LPCSTR);
   1.146 +	IMPORT_C static HANDLE CreateFile(LPCTSTR ,DWORD ,DWORD ,LPSECURITY_ATTRIBUTES ,DWORD ,DWORD ,HANDLE);
   1.147 +	IMPORT_C static BOOL DeleteFile(LPCTSTR);
   1.148 +	IMPORT_C static HANDLE FindFirstFile(LPCTSTR ,LPWIN32_FIND_DATA);	
   1.149 +	IMPORT_C static BOOL FindNextFile(HANDLE ,LPWIN32_FIND_DATA);
   1.150 +	IMPORT_C static BOOL GetDiskFreeSpace(LPCTSTR ,LPDWORD ,LPDWORD ,LPDWORD ,LPDWORD);
   1.151 +	IMPORT_C static DWORD GetFileAttributes(LPCTSTR);
   1.152 +	IMPORT_C static HMODULE GetModuleHandle(LPCTSTR);
   1.153 +	IMPORT_C static DWORD GetCurrentDirectory(DWORD ,LPTSTR);
   1.154 +	IMPORT_C static DWORD GetTempPath(DWORD ,LPTSTR);
   1.155 +	IMPORT_C static BOOL GetVolumeInformation(LPCTSTR ,LPTSTR ,DWORD ,LPDWORD ,LPDWORD ,LPDWORD ,LPTSTR,DWORD);
   1.156 +	IMPORT_C static HMODULE LoadLibrary(LPCTSTR);	
   1.157 +	IMPORT_C static BOOL FreeLibrary(HMODULE);	 
   1.158 +	IMPORT_C static BOOL MoveFile(LPCTSTR ,LPCTSTR);
   1.159 +	IMPORT_C static BOOL CopyFile(LPCTSTR ,LPCTSTR, BOOL);
   1.160 +	IMPORT_C static VOID OutputDebugString(LPCTSTR);	
   1.161 +	IMPORT_C static BOOL RemoveDirectory(LPCTSTR);
   1.162 +	IMPORT_C static BOOL SetFileAttributes(LPCTSTR ,DWORD);	
   1.163 +	IMPORT_C static BOOL SetVolumeLabel(LPCTSTR ,LPCTSTR);	
   1.164 +	IMPORT_C static FARPROC GetProcAddress(HMODULE, LPCSTR);
   1.165 +	IMPORT_C static DWORD GetModuleFileName(HMODULE hModule, LPWSTR lpFilename);
   1.166 +public:
   1.167 +
   1.168 +	/**
   1.169 +	A class which holds a loaded module of the file system. 
   1.170 +	*/
   1.171 +	class TModule
   1.172 +		{
   1.173 +	public:
   1.174 +	
   1.175 +		/**
   1.176 +		Constructor which sets the handles of loaded module	to current instance of the application.
   1.177 +		
   1.178 +		@param aModule		A handle to the current instance of the application.
   1.179 +		*/
   1.180 +		inline TModule(HINSTANCE aModule)
   1.181 +			:iModule(aModule), iBase(aModule)
   1.182 +			{}
   1.183 +			
   1.184 +		IMPORT_C TModule(LPCSTR aModuleName);
   1.185 +		
   1.186 +		/**
   1.187 +		Checks the validity of the loaded module.
   1.188 +		
   1.189 +		@return		TRUE, if the function succeeds
   1.190 +					FALSE, if the function fails		 
   1.191 +		*/
   1.192 +		inline TBool IsValid() const
   1.193 +			{return iBase!=NULL;}
   1.194 +			
   1.195 +		/**
   1.196 +		Relocates the address of the loaded module by appending aRawVirtualAddress to the handle of loaded module.
   1.197 +		
   1.198 +		@param aRawVirtualAddress	Contains the address of the first byte of the section when loaded into 
   1.199 +									memory, relative to the image base. For object files, this is the 
   1.200 +									address of the first byte before relocation is applied.
   1.201 +		
   1.202 +		@return 	Returns the actual address of the handle.
   1.203 +		*/
   1.204 +		inline const TAny* Translate(TInt32 aRawVirtualAddress) const
   1.205 +			{return (const TUint8*)iBase + aRawVirtualAddress;}
   1.206 +	
   1.207 +		
   1.208 +		IMPORT_C void GetUids(TUidType& aType) const;
   1.209 +		IMPORT_C void GetInfo(TProcessCreateInfo& aInfo) const;
   1.210 +	public:
   1.211 +	
   1.212 +		/**
   1.213 +		Default constructor which sets the handles of loaded module or mapped file image to the default handle.	
   1.214 +		*/
   1.215 +		inline TModule()
   1.216 +			:iModule(0), iBase(0)
   1.217 +			{}
   1.218 +	
   1.219 +		/**
   1.220 +		Checks whether the current module is a loaded module, or just a mapped file image.
   1.221 +		
   1.222 +		@return		TRUE, if the current module is a loaded module 
   1.223 +					FALSE, if the current module is a mapped image 
   1.224 +		*/
   1.225 +		TBool IsLoaded() const		// Is this a loaded module, or just a mapped file image.
   1.226 +			{return iModule != 0;}
   1.227 +			
   1.228 +		IMPORT_C const IMAGE_NT_HEADERS32* NtHeader() const;
   1.229 +		
   1.230 +		/**
   1.231 +		Passes the handle of a loaded module to the calling module.
   1.232 +		
   1.233 +		@return 	Returns a handle of a loaded module.
   1.234 +	    */
   1.235 +		const TAny* Base() const
   1.236 +			{return iBase;}
   1.237 +
   1.238 +		IMPORT_C const IMAGE_SECTION_HEADER* SectionHeader(const BYTE aSection[]) const;
   1.239 +		IMPORT_C const TAny* Section(const BYTE aSection[]) const;	
   1.240 +		IMPORT_C const IMAGE_IMPORT_DESCRIPTOR* Imports() const;
   1.241 +	public:
   1.242 +	
   1.243 +		/**
   1.244 +		A handle to a loaded module.
   1.245 +		*/
   1.246 +		HMODULE iModule;
   1.247 +		
   1.248 +		/**
   1.249 +		A handle to a loaded module for the mapped view.
   1.250 +		*/
   1.251 +		const TAny* iBase;
   1.252 +		};
   1.253 +		
   1.254 +	/**
   1.255 +	A class which holds a mapped image of the file system.
   1.256 +	*/
   1.257 +	class RImageFile : public TModule
   1.258 +		{
   1.259 +	public:
   1.260 +	
   1.261 +		/**
   1.262 +		Constructor which sets the handle of the mapped image file to default handle.	
   1.263 +		*/
   1.264 +		inline RImageFile()
   1.265 +			: iMapping(0)
   1.266 +			{}
   1.267 +			
   1.268 +		IMPORT_C TInt Open(LPCTSTR aImageFile);
   1.269 +		IMPORT_C void Close();
   1.270 +	private:
   1.271 +	
   1.272 +		/**
   1.273 +		A handle to the mapped image file.
   1.274 +		*/
   1.275 +		HANDLE iMapping;
   1.276 +		};
   1.277 +	};
   1.278 +
   1.279 +
   1.280 +#endif