Update contrib.
1 // Copyright (c) 2010 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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Test shutdown cleanup functions that should be called to destroy singletons
15 // before the heap is destroyed, in particular when using TEF steps.
16 // These methods are implemented and called from Window Server - WServ, CWsTop
17 // but this copy can be called by any low-level unit tests that bypass WServ
18 // but need to provide the same clean-up behaviour.
20 // @internalTechnology
22 // Currently, three things are cleaned up:
23 // 1) Singleton API mutex in OpenWF implementation
24 // 2) Singleton Find/Acquire mutext in Native Stream implementation
25 // 3) EGL thread status
27 // Note that while these cleanups are only required by OWF-C implementations,
28 // the methods called should be harmless if called
29 // when some other composition solution is in action.
31 #include <e32property.h>
34 // IDs of p&s properties that optionally contain onexit callbacks
35 // that may be used to release singletons owned by libraries at shutdown in order to make
36 // the memory leak tests work.
37 // By convention, the ID is the same as the UID3 of the libary.
38 static TBool gReleaseSingletonsOnExit = EFalse;
39 static const TUid KOpenWfcImplCleanupKey = {0x10286FC4};
40 static const TUid KOpenWfcInteropCleanupKey = {0x10286FC5};
43 static void DefineOwfSingletonKey(const TUid& aSingletonKey)
45 * Defines a new property for a singleton key. WServ must only process
46 * singleton keys that it created to prevent a malicious process with the
47 * WriteDeviceData capability causing arbitrary functions to be executed.
49 * @param aSingeltonKey The UID of the singleton key to define.
53 TUid category = { t.SecureId().iId };
56 // Write access is restricted to THIS process
57 TInt err = prop.Define( category, aSingletonKey.iUid,
58 RProperty::EByteArray, TSecurityPolicy( t.SecureId() ),
59 TSecurityPolicy( t.SecureId() ), sizeof( TCallBack ) );
61 if ( err == KErrNone || err == KErrAlreadyExists)
63 TCallBack cb( NULL, NULL );
64 TPckgC<TCallBack> cbPckg( cb );
66 // Any error should cause the properties to be ignored
67 err = prop.Set( category, aSingletonKey.iUid, cbPckg );
69 //We presume that if property already exists it was previously set by this test code.
70 if ( err != KErrNone )
72 // A problem occured / the property already existed so for safety
73 // the release code should be skipped.
74 gReleaseSingletonsOnExit = EFalse;
80 #define DefineOwfSingletonKeys DefineOwfSingletonKeys
81 /** Call this method before starting the compositor.
84 static void DefineOwfSingletonKeys()
86 // Define properties for singleton callbacks. This must only be done ONCE
87 // to ensure the properties can't be hijacked.
88 gReleaseSingletonsOnExit = ETrue;
89 DefineOwfSingletonKey(KOpenWfcInteropCleanupKey);
90 DefineOwfSingletonKey(KOpenWfcImplCleanupKey);
93 static void DeleteOwfSingleton( const TUid& aSingletonKey )
95 * Deletes a singleton object that was created on WServ's main heap.
97 * @pre The ws plugins have not been unloaded.
98 * @param aSingletonKey The UID of the singleton which correponds to an
99 * RProperty within WServ's category.
102 if ( gReleaseSingletonsOnExit )
105 TPckgBuf<TCallBack> cb;
107 TInt err = prop.Get(TUid::Uid(t.SecureId().iId), aSingletonKey.iUid, cb);
108 if (err == KErrNone && cb.Length() == sizeof(TCallBack) &&
109 cb().iFunction && cb().iPtr == &User::Heap())
111 // Callback is only invoked if the heap for the singleton was the
112 // WServ heap because the WServ memory leak tests only check this
116 // Errors are ignored because the purpose of this function is to free
117 // singletons in order top make memory leak checks pass.
122 /** Call this method to destroy OWF-C singletons on shut down
125 #define DeleteOwfSingletons DeleteOwfSingletons
126 static void DeleteOwfSingletons()
128 // Free singletons on WServ heap created by libraries. Must be called
129 // BEFORE iPluginManager is deleted otherwise the library code could have
131 DeleteOwfSingleton(KOpenWfcImplCleanupKey);
132 DeleteOwfSingleton(KOpenWfcInteropCleanupKey);
133 /* Release any use of EGL by this thread. */