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