sl@0: // Copyright (c) 2004-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: // e32test\cppexceptions\t_romtable.cpp sl@0: // Overview: sl@0: // Check accessibility and integrity of ROM exception search table. sl@0: // API Information: sl@0: // TRomHeader, TRomExceptionSearchTable, TExceptionDescriptor sl@0: // Details: sl@0: // - Get the ROM exception search table, verify results are as expected. sl@0: // - Check that the correct exception descriptor is returned by sl@0: // GetExceptionDescriptor(). sl@0: // - Check that the correct index table entry can be found. sl@0: // - Initialize the unwinder cache of a UCB with an exception descriptor sl@0: // and check we get the right result. sl@0: // - Throw and catch a variety of exceptions and verify results are as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // Hardware (Automatic). sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: /* Environment: */ sl@0: #include "unwind_env.h" sl@0: /* Language-independent unwinder declarations: */ sl@0: #include "unwinder.h" sl@0: sl@0: #include "symbian_support.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: GLDEF_D RTest test(_L("T_ROMTABLE")); sl@0: sl@0: TRomHeader * pTheRomHeader; sl@0: char * GetExceptionDescriptor(void); sl@0: extern "C" { sl@0: IMPORT_C TRomExceptionSearchTable * GetROMExceptionSearchTable(void); sl@0: IMPORT_C TExceptionDescriptor * SearchEST(uint32_t addr, TRomExceptionSearchTable * aESTp); sl@0: TExceptionDescriptor * GetRAMLoadedExceptionDescriptor(uint32_t addr); sl@0: IMPORT_C const __EIT_entry *SearchEITV1(uint32_t return_address_offset, const __EIT_entry *base, unsigned int nelems); sl@0: IMPORT_C __EIT_entry* SearchEITV2(uint32_t return_address, const __EIT_entry* base, unsigned int nelems); sl@0: TExceptionDescriptor * ReLoadExceptionDescriptor(uint32_t addr, _Unwind_Control_Block * ucbp); sl@0: IMPORT_C void InitialiseSymbianSpecificUnwinderCache(uint32_t addr, _Unwind_Control_Block * ucbp); sl@0: sl@0: void *__cxa_allocate_exception(size_t size); sl@0: IMPORT_C __cxa_eh_globals * __cxa_get_globals(); sl@0: sl@0: #ifdef _DEBUG sl@0: IMPORT_C void DebugPrintf(const char * aFmt, ...); sl@0: #endif sl@0: } sl@0: sl@0: int catcher(int x); sl@0: int catcher2(int x); sl@0: int catcher3(int x); sl@0: int catcher4(int x); sl@0: int catcher5(int x); sl@0: void TestUncaught(void); sl@0: const __EIT_entry * DumbGetEITV1(TUint32 offset, const __EIT_entry * base, TUint32 n); sl@0: __EIT_entry * DumbGetEITV2(TUint32 addr, __EIT_entry * base, TUint32 n); sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Start(_L("Check accessibility and integrity of ROM exception search table")); sl@0: sl@0: TRomExceptionSearchTable * pEST = GetROMExceptionSearchTable(); sl@0: test.Printf(_L("ROM EST @ %08x\n"), pEST); sl@0: test(pEST != 0); sl@0: sl@0: test.Printf(_L("ROM EST contains %d entries\n"), pEST->iNumEntries); sl@0: sl@0: for (int i=0; iiNumEntries; i++) sl@0: { sl@0: TRomImageHeader * pE = (TRomImageHeader *)pEST->iEntries[i]; sl@0: TRomImageHeader * pH = pE -1; sl@0: TUint xd = pH->iExceptionDescriptor; sl@0: if ((xd&1)==0 || xd==0xffffffffu) sl@0: continue; sl@0: xd &= ~1; sl@0: TExceptionDescriptor * pED = (TExceptionDescriptor *) ((char *)pE + xd); sl@0: char * aExIdxBase = (char *)pED->iExIdxBase; sl@0: char * aExIdxLimit = (char *)pED->iExIdxLimit; sl@0: char * aROBase = (char *) pED->iROSegmentBase; sl@0: char * aROLimit = (char *)pED->iROSegmentLimit; sl@0: sl@0: test.Printf(_L("%d\n"),i); sl@0: sl@0: test(aExIdxBase <= aExIdxLimit); sl@0: sl@0: test(aROBase <= aROLimit); sl@0: sl@0: test(aROBase <= aExIdxBase); sl@0: test(aExIdxLimit <= aROLimit); sl@0: } sl@0: test.Printf(_L("\n")); sl@0: sl@0: #ifdef __SUPPORT_CPP_EXCEPTIONS__ sl@0: // Check we get the right Exception Descriptor sl@0: char * myExcpDesc = GetExceptionDescriptor(); sl@0: uint32_t addr = (uint32_t)GetExceptionDescriptor; sl@0: sl@0: test.Printf(_L("Checking &GetExceptionDescriptor [%08x] in EST range: %08x - %08x\n"), sl@0: addr, pEST->iEntries[0], GET_EST_FENCEPOST(pEST)); sl@0: test(addr >= pEST->iEntries[0] && addr < GET_EST_FENCEPOST(pEST)); sl@0: TExceptionDescriptor * aExcpDescP = SearchEST(addr, pEST); sl@0: test.Printf(_L("Found entry %08x in EST\n"), aExcpDescP); sl@0: test(aExcpDescP != NULL); sl@0: test.Printf(_L("Check myExcpDesc[%08x] == aExcpDescP[%08x]\n"), myExcpDesc, aExcpDescP); sl@0: test(myExcpDesc==(char*)aExcpDescP); sl@0: sl@0: // Now check we can find the right entry in the index table. sl@0: __EIT_entry * aExIdxBase1 = (__EIT_entry *)aExcpDescP->iExIdxBase; sl@0: __EIT_entry * aExIdxLimit1 = (__EIT_entry *)aExcpDescP->iExIdxLimit; sl@0: unsigned int nelems = aExIdxLimit1 - aExIdxBase1; sl@0: uint32_t aROBase1 = (uint32_t)aExcpDescP->iROSegmentBase; sl@0: int ehabiv2 = aROBase1 & 1; sl@0: aROBase1 = aROBase1 & EHABI_MASK; sl@0: uint32_t aRetOffest = addr - aROBase1; sl@0: test.Printf(_L("EHABI_V2= %d: Looking up %08x with base %08x in ExIdx @ %08x with %d entries\n"), sl@0: ehabiv2, addr, aROBase1, aExIdxBase1, nelems); sl@0: if (ehabiv2) { sl@0: __EIT_entry * aResult = SearchEITV2(addr, aExIdxBase1, nelems); sl@0: __EIT_entry * aResult1 = DumbGetEITV2(addr, aExIdxBase1, nelems); sl@0: test.Printf(_L("Check result %08x == %08x\n"), aResult, aResult1); sl@0: test(aResult == aResult1); sl@0: } else { sl@0: const __EIT_entry * aResult = SearchEITV1(aRetOffest, aExIdxBase1, nelems); sl@0: const __EIT_entry * aResult1 = DumbGetEITV1(aRetOffest, aExIdxBase1, nelems); sl@0: test.Printf(_L("Check result %08x == %08x\n"), aResult, aResult1); sl@0: test(aResult == aResult1); sl@0: } sl@0: #ifdef _DEBUG sl@0: DebugPrintf("Exception diagnostic print support is working if you can see this!!\n\r"); sl@0: #else sl@0: test.Printf(_L("Exception diagnostic print support only available in UDEB builds - not tested\n")); sl@0: #endif sl@0: sl@0: //check we've got some eh_globals sl@0: __cxa_eh_globals *g = __cxa_get_globals(); sl@0: test.Printf(_L("Exception Handling globals for this thread allocated @ %08x\n"), g); sl@0: test(g != NULL); sl@0: test.Printf(_L("Emergency Buffer @ %08x\n"), g->emergency_buffer); sl@0: sl@0: // now initialize a the unwinder cache of a ucbp with an exception descriptor sl@0: // and check we get the right result. sl@0: test.Printf(_L("Allocate an empty exception object\n")); sl@0: __cxa_exception *ep = ((__cxa_exception *)__cxa_allocate_exception(0)) - 1; sl@0: test.Printf(_L("Empty Exception Object @ %08x UCB @ %08x\n"), ep, &ep->ucb); sl@0: test.Printf(_L("Initialize the UCB with the EST and the current exception descriptor\n")); sl@0: InitialiseSymbianSpecificUnwinderCache(addr, &ep->ucb); sl@0: test.Printf(_L("Check the EST in the UCB [%08x] == %08x and the Exception Desc [%08x] == %08x\n"), sl@0: GET_ROM_EST(&ep->ucb), pEST, GET_EXCEPTION_DESCRIPTOR(&ep->ucb), myExcpDesc); sl@0: test(GET_ROM_EST(&ep->ucb)==pEST); sl@0: test((char*)GET_EXCEPTION_DESCRIPTOR(&ep->ucb)== myExcpDesc); sl@0: sl@0: test.Printf(_L("Throwing first exception.\n")); sl@0: int r = catcher(2); sl@0: test.Printf(_L("Returned %d expected 2\n"), r); sl@0: test(r==2); sl@0: sl@0: test.Printf(_L("Not throwing first exception.\n")); sl@0: r = catcher(0); sl@0: test.Printf(_L("Returned %d expected -1\n"), r); sl@0: test(r==-1); sl@0: sl@0: test.Printf(_L("Throwing second exception.\n")); sl@0: r = catcher2(3); sl@0: test.Printf(_L("Returned %d expected 3\n"), r); sl@0: test(r==3); sl@0: sl@0: test.Printf(_L("Not throwing second exception.\n")); sl@0: r = catcher2(0); sl@0: test.Printf(_L("Returned %d expected -1\n"), r); sl@0: test(r==-1); sl@0: sl@0: test.Printf(_L("Throwing third exception.\n")); sl@0: r = catcher3(4); sl@0: test.Printf(_L("Returned %d expected 4\n"), r); sl@0: test(r==4); sl@0: sl@0: test.Printf(_L("Not throwing third exception.\n")); sl@0: r = catcher3(0); sl@0: test.Printf(_L("Returned %d expected -1\n"), r); sl@0: test(r==-1); sl@0: sl@0: test.Printf(_L("Throwing fourth exception.\n")); sl@0: r = catcher4(5); sl@0: test.Printf(_L("Returned %d expected 5\n"), r); sl@0: test(r==5); sl@0: sl@0: test.Printf(_L("Not throwing fourth exception.\n")); sl@0: r = catcher4(0); sl@0: test.Printf(_L("Returned %d expected -1\n"), r); sl@0: test(r==-1); sl@0: sl@0: test.Printf(_L("Throwing fifth exception.\n")); sl@0: r = catcher5(6); sl@0: test.Printf(_L("Returned %d expected 6\n"), r); sl@0: test(r==6); sl@0: sl@0: test.Printf(_L("Not throwing fifth exception.\n")); sl@0: r = catcher5(0); sl@0: test.Printf(_L("Returned %d expected -1\n"), r); sl@0: test(r==-1); sl@0: sl@0: test.Printf(_L("Testing std::uncaught_exception.\n")); sl@0: TestUncaught(); sl@0: #endif sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: return 0; sl@0: } sl@0: sl@0: #ifdef __ARMCC__ sl@0: // We rely on this immediately following E32main. DONT MOVE IT sl@0: __asm char * GetExceptionDescriptor(void) { sl@0: extern |Symbian$$CPP$$Exception$$Descriptor| sl@0: ldr r0, theExceptionDesc sl@0: sl@0: #ifdef __SUPPORT_THUMB_INTERWORKING sl@0: bx lr sl@0: #else sl@0: mov pc, lr sl@0: #endif sl@0: sl@0: theExceptionDesc dcd |Symbian$$CPP$$Exception$$Descriptor| sl@0: } sl@0: #endif sl@0: sl@0: const __EIT_entry * DumbGetEITV1(TUint32 offset, const __EIT_entry * base, TUint32 n) { sl@0: if (n && offset < base[0].fnoffset) return 0; sl@0: for (int i=0; i> 1) + (int32_t)p); sl@0: } sl@0: sl@0: __EIT_entry * DumbGetEITV2(TUint32 addr, __EIT_entry * base, TUint32 n) { sl@0: if (n && (addr < __ARM_resolve_prel31(&base[0].fnoffset))) sl@0: return 0; sl@0: for (int i=0; i