sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\euser\epoc\win32\uc_exec.cpp sl@0: // sl@0: // sl@0: sl@0: #define __GEN_USER_EXEC_CODE__ sl@0: sl@0: #include "uc_std.h" sl@0: #include sl@0: #include sl@0: sl@0: typedef TInt (__fastcall *TDispatcher)(TInt, TInt*); sl@0: TInt __fastcall LazyDispatch(TInt aFunction, TInt* aArgs); sl@0: sl@0: #pragma data_seg(".data2") sl@0: #ifdef __VC32__ sl@0: #pragma bss_seg(".data2") sl@0: #endif sl@0: static TDispatcher TheDispatcher = &LazyDispatch; sl@0: #pragma data_seg() sl@0: #ifdef __VC32__ sl@0: #pragma bss_seg() sl@0: #endif sl@0: sl@0: TInt __fastcall LazyDispatch(TInt aFunction, TInt* aArgs) sl@0: { sl@0: //SL: sl@0: HINSTANCE kernel = GetModuleHandleA("ekern.dll"); sl@0: //HINSTANCE kernel = GetModuleHandleA("ekern.exe"); sl@0: if (kernel) sl@0: { sl@0: TDispatcher dispatcher = (TDispatcher)Emulator::GetProcAddress(kernel, (LPCSTR)1); sl@0: if (dispatcher) sl@0: { sl@0: TheDispatcher = dispatcher; sl@0: return dispatcher(aFunction, aArgs); sl@0: } sl@0: } sl@0: ExitProcess(101); sl@0: return 0; sl@0: } sl@0: sl@0: #include sl@0: sl@0: /****************************************************************************** sl@0: * Slow executive calls with preprocessing or extra arguments sl@0: ******************************************************************************/ sl@0: sl@0: __NAKED__ TInt Exec::SessionSend(TInt /*aHandle*/, TInt /*aFunction*/, TAny* /*aPtr*/, TRequestStatus* /*aStatus*/) sl@0: // sl@0: // Send a blind message to the server. sl@0: // sl@0: { sl@0: __DISPATCH(EExecSessionSend|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: __NAKED__ TInt Exec::SessionSendSync(TInt /*aHandle*/, TInt /*aFunction*/, TAny* /*aPtr*/, TRequestStatus* /*aStatus*/) sl@0: // sl@0: // Send a blind message to the server using thread's dedicated message slot. sl@0: // sl@0: { sl@0: __DISPATCH(EExecSessionSendSync|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: sl@0: __NAKED__ TInt Exec::MessageIpcCopy(TInt /*aHandle*/, TInt /*aParam*/, SIpcCopyInfo& /*aInfo*/, TInt /*anOffset*/) sl@0: // sl@0: // Perform a descriptor-to-descriptor IPC copy sl@0: // sl@0: { sl@0: sl@0: __DISPATCH(EExecMessageIpcCopy|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: __NAKED__ TInt Exec::BTraceOut(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/) sl@0: { sl@0: __DISPATCH(EExecBTraceOut|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: __NAKED__ TInt Exec::BTraceOutBig(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/) sl@0: { sl@0: __DISPATCH(EExecBTraceOutBig|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: __NAKED__ TInt Exec::UTraceOut(TUint32 /*a0*/, TUint32 /*a1*/, const BTrace::SExecExtension& /*aExtension*/, TInt /*aDataSize*/) sl@0: { sl@0: __DISPATCH(EExecUTraceOut|EXECUTIVE_SLOW) sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: ext.iA2 = a2; sl@0: ext.iA3 = a3; sl@0: ext.iPc = (&a0)[-1]; // return address on X86 sl@0: return Exec::BTraceOut(a0,a1,ext,0); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: ext.iA2 = a2; sl@0: ext.iA3 = a3; sl@0: ext.iPc = (&a0)[-1]; // return address on X86 sl@0: return Exec::BTraceOut(a0,a1,ext,0); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: ext.iA2 = a2; sl@0: ext.iA3 = (TUint32)aData; sl@0: ext.iPc = (&a0)[-1]; // return address on X86 sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: ext.iA2 = a2; sl@0: ext.iA3 = (TUint32)aData; sl@0: ext.iPc = (&a0)[-1]; // return address on X86 sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: ext.iA2 = 0; sl@0: ext.iA3 = (TUint32)aData; sl@0: ext.iPc = (&a0)[-1]; // return address on X86 sl@0: sl@0: if((TUint)aDataSize>8u) sl@0: { sl@0: if((TUint)aDataSize>KMaxBTraceDataArray+4u) sl@0: return Exec::BTraceOutBig(a0,a1,ext,aDataSize); sl@0: a0 += 4; sl@0: aDataSize -= 4; sl@0: ext.iA2 = *((TUint32*&)aData)++; sl@0: ext.iA3 = (TUint32)aData; sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: if((TUint)aDataSize>4u) sl@0: ext.iA3 = ((TUint32*)aData)[1]; sl@0: if(aDataSize) sl@0: ext.iA2 = ((TUint32*)aData)[0]; sl@0: a0 += aDataSize; sl@0: aDataSize = 0; sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: a0 |= EMissingRecord<8u) sl@0: { sl@0: if((TUint)aDataSize>KMaxBTraceDataArray+4u) sl@0: return Exec::BTraceOutBig(a0,a1,ext,aDataSize); sl@0: a0 += 4; sl@0: aDataSize -= 4; sl@0: ext.iA2 = *((TUint32*&)aData)++; sl@0: ext.iA3 = (TUint32)aData; sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: if((TUint)aDataSize>4u) sl@0: ext.iA3 = ((TUint32*)aData)[1]; sl@0: if(aDataSize) sl@0: ext.iA2 = ((TUint32*)aData)[0]; sl@0: a0 += aDataSize; sl@0: aDataSize = 0; sl@0: return Exec::BTraceOut(a0,a1,ext,aDataSize); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 aHeader, TUint32 aModuleUid, TUint32 aPc, TUint16 aFormatId, const TAny* aData, TInt aDataSize) sl@0: { sl@0: BTrace::SExecExtension ext; sl@0: aHeader |= EMissingRecord<KMaxBTraceDataArray) sl@0: return Exec::UTraceOut(aHeader,aModuleUid,ext,aDataSize); sl@0: aHeader += 4; sl@0: return Exec::BTraceOut(aHeader,aModuleUid,ext,aDataSize); sl@0: } sl@0: sl@0: __NAKED__ void ExecRequestComplete(TInt /*aHandle*/, TRequestStatus*& /*aStatus*/, TInt /*aReason*/) sl@0: { sl@0: _asm mov ecx, [esp+8] // ecx = TRequestStatus** sl@0: _asm xor eax, eax // sl@0: _asm lock xchg eax, [ecx] // eax=TRequestStatus*, zero TRequestStatus* sl@0: _asm cmp eax, 0 // sl@0: _asm je ExecRequestComplete_ret sl@0: _asm mov ecx, [esp+12] // ecx = aReason sl@0: _asm mov [eax], ecx // store aReason in request status sl@0: __DISPATCH(EExecThreadRequestSignal|EXECUTIVE_SLOW) sl@0: _asm ExecRequestComplete_ret: ret sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void RThread::RequestComplete(TRequestStatus*& aStatus, TInt aReason) const sl@0: /** sl@0: Signals this thread that an asynchronous request originating from this thread, sl@0: is complete. sl@0: sl@0: The request is associated with the specified request status object supplied sl@0: by this thread. sl@0: sl@0: Typically, the caller of this function is the service provider responsible sl@0: for satisfying the request made by this thread. sl@0: sl@0: The request is completed with the completion code passed in aReason. This sl@0: value is copied into this thread's request status, *aStatus, before signalling sl@0: this thread's request semaphore. sl@0: sl@0: The meaning of the completion code is a matter of convention to be decided sl@0: between the service provider and this thread. sl@0: sl@0: In a client-server situation, completion of a request takes place in the context sl@0: of the server thread, but the pointer is interpreted in the address space sl@0: of the client. sl@0: sl@0: It is often the case in client-server situations that the client and the server sl@0: are in the same address space (i.e. the same process). sl@0: sl@0: Setting the pointer to the request status to NULL is a convenience, not all sl@0: servers need it. sl@0: sl@0: @param aStatus A reference to a pointer to the request status originally sl@0: supplied by this thread. This is a pointer into this thread's sl@0: address space, which may be different to the thread currently sl@0: executing (this code). On return, the pointer to the request sl@0: status is set to NULL. sl@0: sl@0: @param aReason The completion code of this request. sl@0: */ sl@0: { sl@0: ExecRequestComplete(iHandle,aStatus,aReason); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Signal this threads request semaphore. sl@0: sl@0: This is similar to RThread::RequestComplete() except that no TRequestStatus object sl@0: is modified. sl@0: sl@0: May only be used to signal a thread in the same process as the callers. sl@0: sl@0: @panic KERN-EXEC 46 if the thread is not in the same process as the callers sl@0: */ sl@0: EXPORT_C void RThread::RequestSignal() const sl@0: { sl@0: Exec::ThreadRequestSignal(iHandle); sl@0: } sl@0: sl@0: sl@0: sl@0: void ExitCurrentThread(TExitType aType, TInt aReason, const TDesC8* aCategory) sl@0: { sl@0: Exec::ThreadKill(KCurrentThreadHandle, aType, aReason, aCategory); sl@0: } sl@0: