kernel/eka/euser/epoc/win32/uc_trp.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\euser\epoc\win32\uc_trp.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <u32exec.h>
       
    19 #include <e32panic.h>
       
    20 #include "uc_std.h"
       
    21 
       
    22 GLREF_C void Panic(TCdtPanic);
       
    23 
       
    24 #ifndef __LEAVE_EQUALS_THROW__
       
    25 
       
    26 // __thiscall - parameter is expected to be removed by this function
       
    27 EXPORT_C TInt TTrap::Trap(TInt &aResult)
       
    28 //
       
    29 // Save the enter frame state and return 0.
       
    30 //
       
    31 	{
       
    32 	// compiler generates push ebp; mov ebp,esp here
       
    33 	// hence correct action for Leave() is to restore ebp then mov esp,ebp; pop ebp; ret 4
       
    34 	aResult=KErrNone;
       
    35 	iResult=(&aResult);
       
    36 	_asm mov eax, this
       
    37 	_asm mov [eax], ebx
       
    38 	_asm mov [eax+4], esi
       
    39 	_asm mov [eax+8], edi
       
    40 	_asm mov [eax+12], ebp
       
    41 	_asm mov [eax+16], ds
       
    42 	_asm mov [eax+20], es
       
    43 	_asm mov [eax+24], fs
       
    44 	_asm mov [eax+28], gs
       
    45 	_asm mov edx, [ebp]
       
    46 	_asm mov [eax+32], edx
       
    47 	_asm mov edx, [ebp+4]
       
    48 	_asm mov [eax+36], edx
       
    49 	TTrapHandler* h = Exec::PushTrapFrame(this);
       
    50 	if (h != NULL)
       
    51 		h->Trap();
       
    52 	return(0);
       
    53 	}
       
    54 
       
    55 
       
    56 
       
    57 // __cdecl - this function will leave parameter on the stack
       
    58 // but it will return to the instruction after the call to TTrap::Trap()
       
    59 // and this expects a parameter to be popped from the stack
       
    60 // so we must return with a ret 4, rather than leaving the compiler to generate a ret 0
       
    61 EXPORT_C void User::Leave(TInt aReason)
       
    62 /**
       
    63 Leaves the currently executing function, unwinds the call stack, and returns
       
    64 from the most recently entered trap harness.
       
    65 
       
    66 @param aReason The value returned from the most recent call to TRAP or TRAPD.
       
    67                This is known as the reason code and, typically, it gives the
       
    68                reason for the environment or user error causing this leave
       
    69                to occur.
       
    70               
       
    71 @see TRAP
       
    72 @see TRAPD              
       
    73 */
       
    74 	{
       
    75 
       
    76 	TTrap *pT=Exec::PopTrapFrame();
       
    77     if (!pT)
       
    78         ::Panic(EUserLeaveWithoutTrap);
       
    79 	TTrapHandler *pH=pT->iHandler;
       
    80 	*pT->iResult=aReason;
       
    81 	if (pH!=NULL)
       
    82 		pH->Leave(aReason);
       
    83 	_asm mov eax, pT
       
    84 	_asm mov ebp, [eax+12]
       
    85 	_asm mov esp, ebp
       
    86 	_asm mov ebx, [eax]
       
    87 	_asm mov esi, [eax+4]
       
    88 	_asm mov edi, [eax+8]
       
    89 	_asm mov ds, [eax+16]
       
    90 	_asm mov es, [eax+20]
       
    91 	_asm mov fs, [eax+24]
       
    92 	_asm mov gs, [eax+28]
       
    93 	_asm mov edx, [eax+32]
       
    94 	_asm mov [ebp], edx
       
    95 	_asm mov edx, [eax+36]
       
    96 	_asm mov [ebp+4], edx
       
    97 	_asm mov eax, 1
       
    98 	_asm pop ebp
       
    99 	_asm ret 4
       
   100 	}
       
   101 
       
   102 #endif // !__LEAVE_EQUALS_THROW__