diff -r 000000000000 -r a03f92240627 memspy/Driver/Kernel/Source/MemSpyDriverObjectIx.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memspy/Driver/Kernel/Source/MemSpyDriverObjectIx.cpp Tue Feb 02 01:57:15 2010 +0200 @@ -0,0 +1,293 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "MemSpyDriverObjectIx.h" + +// System includes +#include +//#include + +//const TInt KObjectIxGranularity=8; +const TInt KObjectIndexMask=0x7fff; +//const TInt KObjectMaxIndex=0x7fff; +const TInt KObjectInstanceShift=16; +const TInt KObjectInstanceMask=0x3fff; +//const TInt KObjectIxMaxHandles=0x8000; + +inline TInt index(TInt aHandle) + {return(aHandle&KObjectIndexMask);} +inline TInt instance(TInt aHandle) + {return((aHandle>>KObjectInstanceShift)&KObjectInstanceMask);} +inline TInt instanceLimit(TInt& aCount) + {return ((aCount&KObjectInstanceMask)==0) ? ((++aCount)&KObjectInstanceMask) : aCount&KObjectInstanceMask;} +inline TInt makeHandle(TInt aIndex, TInt aInstance) + {return((TInt)((aInstance<iCount) + { + limit = iCount; + } + while (posiUsed.iAttr); + break; + } + pos++; + } + if (h>0) + { + break; // found it, finish + } + iModList.iMonitor.iBoundary = pos; // will change if aObj is added to a slot already checked + ReleaseWriteLock(); // let other threads in + AcquireWriteLock(); + pos = iModList.iMonitor.iBoundary; // next position to check + } + iState = (TUint8)ENormal; + ReleaseWriteLock(); + return h; + } // RObjectIx::At + + + + + + +#elif MCL_DOBJECTIX_DUPLICATION + +void DMemSpyObjectIx::Wait( DMemSpyObjectIx* /*aObjectIndex*/ ) + { +// Kern::MutexWait(*aObjectIndex->HandleMutex); + } + +void DMemSpyObjectIx::Signal( DMemSpyObjectIx* /*aObjectIndex*/ ) + { +// Kern::MutexSignal(*aObjectIndex->HandleMutex); + } + + +/** Counts the number of times an object appears in this index. + + @param aObject Object whose occurrences are to be counted. + + @return Number of times aObject appears in the index. + + @pre Calling thread must be in a critical section. + @pre No fast mutex can be held. + @pre Call in a thread context. + @pre DObject::HandleMutex held + */ +TInt DMemSpyObjectIx::Count(DObject* aObject) + { + //Check preconditions(debug build only) + __ASSERT_CRITICAL; + __ASSERT_NO_FAST_MUTEX; + + TInt c=0; + if (iCount) + { + SDObjectIxRec* pS=iObjects; + SDObjectIxRec* pE=pS+iCount; + do + { + if (pS->obj==aObject) + c++; + } while (++pS=iCount) + return(NULL); + SDObjectIxRec *pS=iObjects+i; + if (pS->str.instance!=instance(aHandle) || pS->str.uniqueID!=aUniqueID) + return(NULL); + return(pS->obj); + } + + +/** Looks up an object in the index by handle. + + The object may be of any type. + + @param aHandle Handle to look up. + + @return Pointer to object or NULL if handle invalid. + + @pre Call in a thread context. + @pre System lock must be held. + */ +DObject* DMemSpyObjectIx::At(TInt aHandle) + { + __ASSERT_SYSTEM_LOCK; //Check preconditions (debug build only) + TInt i=index(aHandle); + if (i>=iCount) + return NULL; + SDObjectIxRec *pS=iObjects+i; + if (pS->str.instance!=instance(aHandle)) + return NULL; + return pS->obj; + } + + + +/** Looks up an object in the index by object pointer. + + Returns a handle to the object. + + @param aObj Pointer to the object to look up. + + @return Handle to object (always >0); + KErrNotFound, if object not present in index. + + @pre Calling thread must be in a critical section. + @pre No fast mutex can be held. + @pre Call in a thread context. + @pre DObject::HandleMutex held. + */ +TInt DMemSpyObjectIx::At(DObject* aObj) + { + //Check preconditions(debug build only) + __ASSERT_CRITICAL; + __ASSERT_NO_FAST_MUTEX; + + if (iCount) + { + SDObjectIxRec* pS=iObjects; + SDObjectIxRec* pE=pS+iCount; + TInt i=0; + while(pSobj!=aObj) + pS++, i++; + if (pSstr.instance)); + } + return KErrNotFound; + } + + +/** Finds the object at a specific position in the index array. + + @param aIndex Index into array. + + @return Pointer to the object at that position (could be NULL). + + @pre Call in a thread context. + @pre System lock must be held. + */ +DObject* DMemSpyObjectIx::operator[](TInt aIndex) + { + __ASSERT_SYSTEM_LOCK; //Check preconditions (debug build only) + __ASSERT_ALWAYS(aIndex>=0 && aIndex