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_trp.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "uc_std.h" sl@0: sl@0: GLREF_C void Panic(TCdtPanic); sl@0: sl@0: #ifndef __LEAVE_EQUALS_THROW__ sl@0: sl@0: // __thiscall - parameter is expected to be removed by this function sl@0: EXPORT_C TInt TTrap::Trap(TInt &aResult) sl@0: // sl@0: // Save the enter frame state and return 0. sl@0: // sl@0: { sl@0: // compiler generates push ebp; mov ebp,esp here sl@0: // hence correct action for Leave() is to restore ebp then mov esp,ebp; pop ebp; ret 4 sl@0: aResult=KErrNone; sl@0: iResult=(&aResult); sl@0: _asm mov eax, this sl@0: _asm mov [eax], ebx sl@0: _asm mov [eax+4], esi sl@0: _asm mov [eax+8], edi sl@0: _asm mov [eax+12], ebp sl@0: _asm mov [eax+16], ds sl@0: _asm mov [eax+20], es sl@0: _asm mov [eax+24], fs sl@0: _asm mov [eax+28], gs sl@0: _asm mov edx, [ebp] sl@0: _asm mov [eax+32], edx sl@0: _asm mov edx, [ebp+4] sl@0: _asm mov [eax+36], edx sl@0: TTrapHandler* h = Exec::PushTrapFrame(this); sl@0: if (h != NULL) sl@0: h->Trap(); sl@0: return(0); sl@0: } sl@0: sl@0: sl@0: sl@0: // __cdecl - this function will leave parameter on the stack sl@0: // but it will return to the instruction after the call to TTrap::Trap() sl@0: // and this expects a parameter to be popped from the stack sl@0: // so we must return with a ret 4, rather than leaving the compiler to generate a ret 0 sl@0: EXPORT_C void User::Leave(TInt aReason) sl@0: /** sl@0: Leaves the currently executing function, unwinds the call stack, and returns sl@0: from the most recently entered trap harness. sl@0: sl@0: @param aReason The value returned from the most recent call to TRAP or TRAPD. sl@0: This is known as the reason code and, typically, it gives the sl@0: reason for the environment or user error causing this leave sl@0: to occur. sl@0: sl@0: @see TRAP sl@0: @see TRAPD sl@0: */ sl@0: { sl@0: sl@0: TTrap *pT=Exec::PopTrapFrame(); sl@0: if (!pT) sl@0: ::Panic(EUserLeaveWithoutTrap); sl@0: TTrapHandler *pH=pT->iHandler; sl@0: *pT->iResult=aReason; sl@0: if (pH!=NULL) sl@0: pH->Leave(aReason); sl@0: _asm mov eax, pT sl@0: _asm mov ebp, [eax+12] sl@0: _asm mov esp, ebp sl@0: _asm mov ebx, [eax] sl@0: _asm mov esi, [eax+4] sl@0: _asm mov edi, [eax+8] sl@0: _asm mov ds, [eax+16] sl@0: _asm mov es, [eax+20] sl@0: _asm mov fs, [eax+24] sl@0: _asm mov gs, [eax+28] sl@0: _asm mov edx, [eax+32] sl@0: _asm mov [ebp], edx sl@0: _asm mov edx, [eax+36] sl@0: _asm mov [ebp+4], edx sl@0: _asm mov eax, 1 sl@0: _asm pop ebp sl@0: _asm ret 4 sl@0: } sl@0: sl@0: #endif // !__LEAVE_EQUALS_THROW__