os/kernelhwsrv/kerneltest/e32test/cppexceptions/d_unmap.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\cppexceptions\d_unmap.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32std_private.h>
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <e32base_private.h>
sl@0
    22
#include "d_unmap.h"
sl@0
    23
sl@0
    24
class TAlwaysTrue
sl@0
    25
	{
sl@0
    26
public:
sl@0
    27
	TBool val;
sl@0
    28
	TAlwaysTrue() { val = ETrue; }
sl@0
    29
	~TAlwaysTrue() { val = EFalse; }
sl@0
    30
	};
sl@0
    31
sl@0
    32
#ifndef NO_STATIC_DATA
sl@0
    33
static TAlwaysTrue alwaysTrue;
sl@0
    34
#endif
sl@0
    35
sl@0
    36
// Test C++ stack unwinding
sl@0
    37
class TNeedsCxxCleanup
sl@0
    38
	{
sl@0
    39
public:
sl@0
    40
	TNeedsCxxCleanup() : iPtr(NULL) {}
sl@0
    41
	~TNeedsCxxCleanup() { delete iPtr; }
sl@0
    42
private:
sl@0
    43
	TInt* iPtr;
sl@0
    44
	};
sl@0
    45
sl@0
    46
void AnotherStackLevelL()
sl@0
    47
	{
sl@0
    48
	TNeedsCxxCleanup foo;
sl@0
    49
	User::Leave(KErrGeneral);
sl@0
    50
	}
sl@0
    51
sl@0
    52
EXPORT_C void Ordinal1L()
sl@0
    53
	{
sl@0
    54
	TNeedsCxxCleanup bar;
sl@0
    55
	AnotherStackLevelL();
sl@0
    56
	}
sl@0
    57
sl@0
    58
// Test DLL unloading
sl@0
    59
NONSHARABLE_CLASS( CDllUnloader ) : public CTimer
sl@0
    60
	{
sl@0
    61
public:
sl@0
    62
	static CDllUnloader* NewL();
sl@0
    63
sl@0
    64
private:
sl@0
    65
	CDllUnloader();
sl@0
    66
	void ConstructL();
sl@0
    67
sl@0
    68
private:
sl@0
    69
	void RunL();
sl@0
    70
sl@0
    71
private:
sl@0
    72
	RLibrary iLibrary;
sl@0
    73
	};
sl@0
    74
sl@0
    75
sl@0
    76
CDllUnloader::CDllUnloader()
sl@0
    77
	: CTimer(EPriorityNormal)
sl@0
    78
	{
sl@0
    79
	CActiveScheduler::Add(this);
sl@0
    80
	}
sl@0
    81
sl@0
    82
void CDllUnloader::ConstructL()
sl@0
    83
	{
sl@0
    84
	CTimer::ConstructL();
sl@0
    85
	User::LeaveIfError(iLibrary.Load(KLeavingDll));
sl@0
    86
	}
sl@0
    87
sl@0
    88
CDllUnloader* CDllUnloader::NewL()
sl@0
    89
	{
sl@0
    90
	CDllUnloader* self = new(ELeave) CDllUnloader();
sl@0
    91
	CleanupStack::PushL(self);
sl@0
    92
	self->ConstructL();
sl@0
    93
	CleanupStack::Pop(self);
sl@0
    94
	return self;
sl@0
    95
	}
sl@0
    96
sl@0
    97
void CDllUnloader::RunL()
sl@0
    98
	{
sl@0
    99
	// Temporary copy of handle
sl@0
   100
	RLibrary library(iLibrary);
sl@0
   101
sl@0
   102
	// Prevent the AS calling back into us later
sl@0
   103
	// - everything is poison now
sl@0
   104
	delete this;
sl@0
   105
sl@0
   106
	// Push the library handle onto the cleanupstack for euser to clean up
sl@0
   107
	CleanupClosePushL(library);
sl@0
   108
sl@0
   109
	// Prevent [Run]Error() from being called...
sl@0
   110
	// - effect thread diversion out of the DLL
sl@0
   111
	// - and breath a sigh of relief that you've been so cunning
sl@0
   112
	User::Leave(KErrNone);
sl@0
   113
	}
sl@0
   114
sl@0
   115
EXPORT_C TBool Ordinal2()
sl@0
   116
	{
sl@0
   117
	/*
sl@0
   118
	CDllUnloader* unloader = CDllUnloader::NewL();
sl@0
   119
	unloader->After(1000000);
sl@0
   120
	*/
sl@0
   121
#ifdef NO_STATIC_DATA
sl@0
   122
	return EFalse;
sl@0
   123
#else
sl@0
   124
	return alwaysTrue.val;
sl@0
   125
#endif
sl@0
   126
	}
sl@0
   127