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_unmap2.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_unmap.h" sl@0: sl@0: _LIT(KTestName, "t_unmap2"); sl@0: RTest test(KTestName); sl@0: RSemaphore WaitSemaphore; sl@0: RSemaphore SignalSemaphore; sl@0: sl@0: void TestLibraryCleanup(); sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Start(_L("Check code seg unmapping over User::Leave()/C++ exceptions.")); sl@0: sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: TInt r = KErrNoMemory; sl@0: if (cleanup) sl@0: { sl@0: test.Printf(_L("Opening semaphores for barrier with other process\n")); sl@0: test(WaitSemaphore.Open(1)==KErrNone); sl@0: test(SignalSemaphore.Open(2)==KErrNone); sl@0: TRAP(r, TestLibraryCleanup()); sl@0: test.Printf(_L("Returned %d, expected %d\n"), r, KErrGeneral); sl@0: test(r == KErrGeneral); sl@0: WaitSemaphore.Close(); sl@0: SignalSemaphore.Close(); sl@0: r = KErrNone; sl@0: } sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: test.End(); sl@0: return r; sl@0: } sl@0: sl@0: void Checkpoint(TAny*) sl@0: { sl@0: test.Printf(_L("Checkpointing...\n")); sl@0: SignalSemaphore.Signal(); sl@0: WaitSemaphore.Wait(); sl@0: } sl@0: sl@0: void TestLibraryCleanup() sl@0: { sl@0: test.Printf(_L("Loading DLL.\n")); sl@0: RLibrary library; sl@0: test(library.Load(KLeavingDll2) == KErrNone); sl@0: sl@0: test.Printf(_L("Pushing cleanup item to synchronise after closing library handle.\n")); sl@0: CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL)); sl@0: sl@0: test.Printf(_L("Pushing handle to dynamically loaded DLL onto the cleanup stack.\n")); sl@0: CleanupClosePushL(library); sl@0: sl@0: test.Printf(_L("Pushing cleanup item to synchronise during leave\n")); sl@0: CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL)); sl@0: sl@0: test.Printf(_L("Looking up leaving function.\n")); sl@0: TLibraryFunction leaving = library.Lookup(1); sl@0: test(leaving != NULL); sl@0: sl@0: test.Printf(_L("Check-point whilst holding the open library handle.\n")); sl@0: Checkpoint(NULL); sl@0: sl@0: test.Printf(_L("Calling leaving function.\n")); sl@0: (*leaving)(); sl@0: sl@0: test.Printf(_L("Cleaning up checkpoint operation.\n")); sl@0: CleanupStack::Pop(); // pause leave op sl@0: sl@0: test.Printf(_L("Cleaning up DLL handle.\n")); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: test.Printf(_L("Cleaning up checkpoint operation.\n")); sl@0: CleanupStack::Pop(); // pause leave op sl@0: }