os/kernelhwsrv/kernel/eka/euser/epoc/win32/uc_exec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-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\euser\epoc\win32\uc_exec.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#define __GEN_USER_EXEC_CODE__
sl@0
    19
sl@0
    20
#include "uc_std.h"
sl@0
    21
#include <e32svr.h>
sl@0
    22
#include <emulator.h>
sl@0
    23
sl@0
    24
typedef TInt (__fastcall *TDispatcher)(TInt, TInt*);
sl@0
    25
TInt __fastcall LazyDispatch(TInt aFunction, TInt* aArgs);
sl@0
    26
sl@0
    27
#pragma data_seg(".data2")
sl@0
    28
#ifdef __VC32__
sl@0
    29
#pragma bss_seg(".data2")
sl@0
    30
#endif
sl@0
    31
static TDispatcher TheDispatcher = &LazyDispatch;
sl@0
    32
#pragma data_seg()
sl@0
    33
#ifdef __VC32__
sl@0
    34
#pragma bss_seg()
sl@0
    35
#endif
sl@0
    36
sl@0
    37
TInt __fastcall LazyDispatch(TInt aFunction, TInt* aArgs)
sl@0
    38
	{
sl@0
    39
	//SL:
sl@0
    40
	HINSTANCE kernel = GetModuleHandleA("ekern.dll");
sl@0
    41
	//HINSTANCE kernel = GetModuleHandleA("ekern.exe");
sl@0
    42
	if (kernel)
sl@0
    43
		{
sl@0
    44
		TDispatcher dispatcher = (TDispatcher)Emulator::GetProcAddress(kernel, (LPCSTR)1);
sl@0
    45
		if (dispatcher)
sl@0
    46
			{
sl@0
    47
			TheDispatcher = dispatcher;
sl@0
    48
			return dispatcher(aFunction, aArgs);
sl@0
    49
			}
sl@0
    50
		}
sl@0
    51
	ExitProcess(101);
sl@0
    52
	return 0;
sl@0
    53
	}
sl@0
    54
sl@0
    55
#include <u32exec.h>
sl@0
    56
sl@0
    57
/******************************************************************************
sl@0
    58
 * Slow executive calls with preprocessing or extra arguments
sl@0
    59
 ******************************************************************************/
sl@0
    60
sl@0
    61
__NAKED__ TInt Exec::SessionSend(TInt /*aHandle*/, TInt /*aFunction*/, TAny* /*aPtr*/, TRequestStatus* /*aStatus*/)
sl@0
    62
//
sl@0
    63
// Send a blind message to the server.
sl@0
    64
//
sl@0
    65
	{
sl@0
    66
	__DISPATCH(EExecSessionSend|EXECUTIVE_SLOW)
sl@0
    67
	}
sl@0
    68
sl@0
    69
__NAKED__ TInt Exec::SessionSendSync(TInt /*aHandle*/, TInt /*aFunction*/, TAny* /*aPtr*/, TRequestStatus* /*aStatus*/)
sl@0
    70
//
sl@0
    71
// Send a blind message to the server using thread's dedicated message slot.
sl@0
    72
//
sl@0
    73
	{
sl@0
    74
	__DISPATCH(EExecSessionSendSync|EXECUTIVE_SLOW)
sl@0
    75
	}
sl@0
    76
sl@0
    77
sl@0
    78
__NAKED__ TInt Exec::MessageIpcCopy(TInt /*aHandle*/, TInt /*aParam*/, SIpcCopyInfo& /*aInfo*/, TInt /*anOffset*/)
sl@0
    79
//
sl@0
    80
// Perform a descriptor-to-descriptor IPC copy
sl@0
    81
//
sl@0
    82
	{
sl@0
    83
sl@0
    84
	__DISPATCH(EExecMessageIpcCopy|EXECUTIVE_SLOW)
sl@0
    85
	}
sl@0
    86
sl@0
    87
__NAKED__ TInt Exec::BTraceOut(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/)
sl@0
    88
	{
sl@0
    89
	__DISPATCH(EExecBTraceOut|EXECUTIVE_SLOW)
sl@0
    90
	}
sl@0
    91
sl@0
    92
__NAKED__ TInt Exec::BTraceOutBig(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/)
sl@0
    93
	{
sl@0
    94
	__DISPATCH(EExecBTraceOutBig|EXECUTIVE_SLOW)
sl@0
    95
	}
sl@0
    96
sl@0
    97
__NAKED__ TInt Exec::UTraceOut(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/)
sl@0
    98
	{
sl@0
    99
	__DISPATCH(EExecUTraceOut|EXECUTIVE_SLOW)
sl@0
   100
	}
sl@0
   101
sl@0
   102
EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   103
	{
sl@0
   104
	BTrace::SExecExtension ext;
sl@0
   105
	ext.iA2 = a2;
sl@0
   106
	ext.iA3 = a3;
sl@0
   107
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   108
	return Exec::BTraceOut(a0,a1,ext,0);
sl@0
   109
	}
sl@0
   110
sl@0
   111
EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   112
	{
sl@0
   113
	BTrace::SExecExtension ext;
sl@0
   114
	ext.iA2 = a2;
sl@0
   115
	ext.iA3 = a3;
sl@0
   116
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   117
	return Exec::BTraceOut(a0,a1,ext,0);
sl@0
   118
	}
sl@0
   119
sl@0
   120
EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   121
	{
sl@0
   122
	BTrace::SExecExtension ext;
sl@0
   123
	ext.iA2 = a2;
sl@0
   124
	ext.iA3 = (TUint32)aData;
sl@0
   125
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   126
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   127
	}
sl@0
   128
sl@0
   129
EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   130
	{
sl@0
   131
	BTrace::SExecExtension ext;
sl@0
   132
	ext.iA2 = a2;
sl@0
   133
	ext.iA3 = (TUint32)aData;
sl@0
   134
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   135
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   136
	}
sl@0
   137
sl@0
   138
EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
sl@0
   139
	{
sl@0
   140
	BTrace::SExecExtension ext;
sl@0
   141
	ext.iA2 = 0;
sl@0
   142
	ext.iA3 = (TUint32)aData;
sl@0
   143
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   144
sl@0
   145
	if((TUint)aDataSize>8u)
sl@0
   146
		{
sl@0
   147
		if((TUint)aDataSize>KMaxBTraceDataArray+4u)
sl@0
   148
			return Exec::BTraceOutBig(a0,a1,ext,aDataSize);
sl@0
   149
		a0 += 4;
sl@0
   150
		aDataSize -= 4;
sl@0
   151
		ext.iA2 = *((TUint32*&)aData)++;
sl@0
   152
		ext.iA3 = (TUint32)aData;
sl@0
   153
		return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   154
		}
sl@0
   155
sl@0
   156
	if((TUint)aDataSize>4u)
sl@0
   157
		ext.iA3 = ((TUint32*)aData)[1];
sl@0
   158
	if(aDataSize)
sl@0
   159
		ext.iA2 = ((TUint32*)aData)[0];
sl@0
   160
	a0 += aDataSize;
sl@0
   161
	aDataSize = 0;
sl@0
   162
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   163
	}
sl@0
   164
sl@0
   165
EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   166
	{
sl@0
   167
	BTrace::SExecExtension ext;
sl@0
   168
	a0 |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   169
	ext.iA2 = a2;
sl@0
   170
	ext.iA3 = a3;
sl@0
   171
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   172
	return Exec::BTraceOut(a0,a1,ext,0);
sl@0
   173
	}
sl@0
   174
sl@0
   175
EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   176
	{
sl@0
   177
	BTrace::SExecExtension ext;
sl@0
   178
	a0 |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   179
	ext.iA2 = a2;
sl@0
   180
	ext.iA3 = a3;
sl@0
   181
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   182
	return Exec::BTraceOut(a0,a1,ext,0);
sl@0
   183
	}
sl@0
   184
sl@0
   185
EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   186
	{
sl@0
   187
	BTrace::SExecExtension ext;
sl@0
   188
	a0 |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   189
	ext.iA2 = a2;
sl@0
   190
	ext.iA3 = (TUint32)aData;
sl@0
   191
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   192
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   193
	}
sl@0
   194
sl@0
   195
EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   196
	{
sl@0
   197
	BTrace::SExecExtension ext;
sl@0
   198
	a0 |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   199
	ext.iA2 = a2;
sl@0
   200
	ext.iA3 = (TUint32)aData;
sl@0
   201
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   202
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   203
	}
sl@0
   204
sl@0
   205
EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
sl@0
   206
	{
sl@0
   207
	BTrace::SExecExtension ext;
sl@0
   208
	a0 |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   209
	ext.iA2 = 0;
sl@0
   210
	ext.iA3 = (TUint32)aData;
sl@0
   211
	ext.iPc = (&a0)[-1]; // return address on X86
sl@0
   212
sl@0
   213
	if((TUint)aDataSize>8u)
sl@0
   214
		{
sl@0
   215
		if((TUint)aDataSize>KMaxBTraceDataArray+4u)
sl@0
   216
			return Exec::BTraceOutBig(a0,a1,ext,aDataSize);
sl@0
   217
		a0 += 4;
sl@0
   218
		aDataSize -= 4;
sl@0
   219
		ext.iA2 = *((TUint32*&)aData)++;
sl@0
   220
		ext.iA3 = (TUint32)aData;
sl@0
   221
		return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   222
		}
sl@0
   223
sl@0
   224
	if((TUint)aDataSize>4u)
sl@0
   225
		ext.iA3 = ((TUint32*)aData)[1];
sl@0
   226
	if(aDataSize)
sl@0
   227
		ext.iA2 = ((TUint32*)aData)[0];
sl@0
   228
	a0 += aDataSize;
sl@0
   229
	aDataSize = 0;
sl@0
   230
	return Exec::BTraceOut(a0,a1,ext,aDataSize);
sl@0
   231
	}
sl@0
   232
sl@0
   233
EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 aHeader, TUint32 aModuleUid, TUint32 aPc, TUint16 aFormatId, const TAny* aData, TInt aDataSize)
sl@0
   234
	{
sl@0
   235
 	BTrace::SExecExtension ext;
sl@0
   236
	aHeader |= EMissingRecord<<BTrace::EFlagsIndex*8; // overload meaning of this flag to indicate filtered trace
sl@0
   237
	ext.iA2 = aFormatId;
sl@0
   238
	ext.iA3 = (TUint32)aData;
sl@0
   239
	ext.iPc = aPc;
sl@0
   240
sl@0
   241
	if((TUint)aDataSize>KMaxBTraceDataArray)
sl@0
   242
		return Exec::UTraceOut(aHeader,aModuleUid,ext,aDataSize);
sl@0
   243
	aHeader += 4;
sl@0
   244
	return Exec::BTraceOut(aHeader,aModuleUid,ext,aDataSize);
sl@0
   245
	}
sl@0
   246
sl@0
   247
__NAKED__ void ExecRequestComplete(TInt /*aHandle*/, TRequestStatus*& /*aStatus*/, TInt /*aReason*/)
sl@0
   248
	{
sl@0
   249
	_asm mov ecx, [esp+8]			// ecx = TRequestStatus**
sl@0
   250
	_asm xor eax, eax				//
sl@0
   251
	_asm lock xchg eax, [ecx]		// eax=TRequestStatus*, zero TRequestStatus*
sl@0
   252
	_asm cmp eax, 0					//
sl@0
   253
	_asm je ExecRequestComplete_ret
sl@0
   254
	_asm mov ecx, [esp+12]			// ecx = aReason
sl@0
   255
	_asm mov [eax], ecx				// store aReason in request status
sl@0
   256
	__DISPATCH(EExecThreadRequestSignal|EXECUTIVE_SLOW)
sl@0
   257
	_asm ExecRequestComplete_ret: ret
sl@0
   258
	}
sl@0
   259
sl@0
   260
sl@0
   261
sl@0
   262
sl@0
   263
EXPORT_C void RThread::RequestComplete(TRequestStatus*& aStatus, TInt aReason) const
sl@0
   264
/**
sl@0
   265
Signals this thread that an asynchronous request originating from this thread,
sl@0
   266
is complete.
sl@0
   267
sl@0
   268
The request is associated with the specified request status object supplied
sl@0
   269
by this thread.
sl@0
   270
sl@0
   271
Typically, the caller of this function is the service provider responsible
sl@0
   272
for satisfying the request made by this thread.
sl@0
   273
sl@0
   274
The request is completed with the completion code passed in aReason. This
sl@0
   275
value is copied into this thread's request status, *aStatus, before signalling
sl@0
   276
this thread's request semaphore.
sl@0
   277
sl@0
   278
The meaning of the completion code is a matter of convention to be decided
sl@0
   279
between the service provider and this thread.
sl@0
   280
sl@0
   281
In a client-server situation, completion of a request takes place in the context
sl@0
   282
of the server thread, but the pointer is interpreted in the address space
sl@0
   283
of the client.
sl@0
   284
sl@0
   285
It is often the case in client-server situations that the client and the server
sl@0
   286
are in the same address space (i.e. the same process).
sl@0
   287
sl@0
   288
Setting the pointer to the request status to NULL is a convenience, not all
sl@0
   289
servers need it.
sl@0
   290
sl@0
   291
@param aStatus A reference to a pointer to the request status originally
sl@0
   292
               supplied by this thread. This is a pointer into this thread's
sl@0
   293
               address space, which may be different to the thread currently
sl@0
   294
               executing (this code). On return, the pointer to the request
sl@0
   295
               status is set to NULL.
sl@0
   296
sl@0
   297
@param aReason The completion code of this request.
sl@0
   298
*/
sl@0
   299
	{
sl@0
   300
	ExecRequestComplete(iHandle,aStatus,aReason);
sl@0
   301
	}
sl@0
   302
sl@0
   303
sl@0
   304
sl@0
   305
/**
sl@0
   306
Signal this threads request semaphore.
sl@0
   307
sl@0
   308
This is similar to RThread::RequestComplete() except that no TRequestStatus object
sl@0
   309
is modified.
sl@0
   310
sl@0
   311
May only be used to signal a thread in the same process as the callers.
sl@0
   312
sl@0
   313
@panic KERN-EXEC 46 if the thread is not in the same process as the callers
sl@0
   314
*/
sl@0
   315
EXPORT_C void RThread::RequestSignal() const
sl@0
   316
	{
sl@0
   317
	Exec::ThreadRequestSignal(iHandle);
sl@0
   318
	}
sl@0
   319
sl@0
   320
sl@0
   321
sl@0
   322
void ExitCurrentThread(TExitType aType, TInt aReason, const TDesC8* aCategory)
sl@0
   323
	{
sl@0
   324
	Exec::ThreadKill(KCurrentThreadHandle, aType, aReason, aCategory);
sl@0
   325
	}
sl@0
   326