perfsrv/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanContainers.cpp
author hgs
Tue, 26 Oct 2010 16:20:32 +0300
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
permissions -rw-r--r--
201043
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "MemSpyDriverLogChanContainers.h"
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// System includes
hgs
parents:
diff changeset
    21
#include <memspy/driver/memspydriverconstants.h>
hgs
parents:
diff changeset
    22
#include <memspy/driver/memspydriverobjectsshared.h>
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// Shared includes
hgs
parents:
diff changeset
    25
#include "MemSpyDriverOpCodes.h"
hgs
parents:
diff changeset
    26
#include "MemSpyDriverObjectsInternal.h"
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
// User includes
hgs
parents:
diff changeset
    29
#include "MemSpyDriverUtils.h"
hgs
parents:
diff changeset
    30
#include "MemSpyDriverUserEventMonitor.h"
hgs
parents:
diff changeset
    31
#include "MemSpyDriverSuspensionManager.h"
hgs
parents:
diff changeset
    32
#include "MemSpyDriverOSAdaption.h"
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
// Constants
hgs
parents:
diff changeset
    35
const TInt KMemSpyDriverLogChanContainersXferBufferSize = 1024 * 4;
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
DMemSpyDriverLogChanContainers::DMemSpyDriverLogChanContainers( DMemSpyDriverDevice& aDevice, DThread& aThread )
hgs
parents:
diff changeset
    39
:   DMemSpyDriverLogChanContainerBase( aDevice, aThread )
hgs
parents:
diff changeset
    40
    {
hgs
parents:
diff changeset
    41
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::DMemSpyDriverLogChanContainers() - this: 0x%08x", this ));
hgs
parents:
diff changeset
    42
    }
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
DMemSpyDriverLogChanContainers::~DMemSpyDriverLogChanContainers()
hgs
parents:
diff changeset
    46
	{
hgs
parents:
diff changeset
    47
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::~DMemSpyDriverLogChanContainers() - START - this: 0x%08x", this ));
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::~DMemSpyDriverLogChanContainers() - END - this: 0x%08x", this ));
hgs
parents:
diff changeset
    50
	}
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
TInt DMemSpyDriverLogChanContainers::Construct()
hgs
parents:
diff changeset
    54
	{
hgs
parents:
diff changeset
    55
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::Construct() - START - this: 0x%08x", this ));
hgs
parents:
diff changeset
    56
    
hgs
parents:
diff changeset
    57
    const TInt ret = BaseConstruct( KMemSpyDriverLogChanContainersXferBufferSize );
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::Construct() - END - this: 0x%08x, err: %d", this, ret ));
hgs
parents:
diff changeset
    60
    return ret;
hgs
parents:
diff changeset
    61
	}
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
TInt DMemSpyDriverLogChanContainers::Request( TInt aFunction, TAny* a1, TAny* a2 )
hgs
parents:
diff changeset
    65
	{
hgs
parents:
diff changeset
    66
	TInt r = DMemSpyDriverLogChanContainerBase::Request( aFunction, a1, a2 );
hgs
parents:
diff changeset
    67
    if  ( r == KErrNone )
hgs
parents:
diff changeset
    68
        {
hgs
parents:
diff changeset
    69
	    switch( aFunction )
hgs
parents:
diff changeset
    70
		    {
hgs
parents:
diff changeset
    71
	    case EMemSpyDriverOpCodeContainersGetHandles:
hgs
parents:
diff changeset
    72
            r = GetContainerHandles( (TMemSpyDriverInternalContainerHandleParams*) a1 );
hgs
parents:
diff changeset
    73
            break;
hgs
parents:
diff changeset
    74
	    case EMemSpyDriverOpCodeContainersGetHandleInfo:
hgs
parents:
diff changeset
    75
            r = GetGenericHandleInfo( (TInt) a1, (TMemSpyDriverHandleInfoGeneric*) a2 );
hgs
parents:
diff changeset
    76
            break;
hgs
parents:
diff changeset
    77
        case EMemSpyDriverOpCodeContainersGetApproxSize:
hgs
parents:
diff changeset
    78
            r = GetKernelObjectSizeApproximation( (TMemSpyDriverContainerType) ((TInt) a1), (TInt*) a2 );
hgs
parents:
diff changeset
    79
            break;
hgs
parents:
diff changeset
    80
        case EMemSpyDriverOpCodeContainersGetReferencesToMyThread:
hgs
parents:
diff changeset
    81
            r = GetReferencesToMyThread( (TUint) a1, (TDes8*) a2 );
hgs
parents:
diff changeset
    82
            break;
hgs
parents:
diff changeset
    83
        case EMemSpyDriverOpCodeContainersGetReferencesToMyProcess:
hgs
parents:
diff changeset
    84
            r = GetReferencesToMyProcess( (TUint) a1, (TDes8*) a2 );
hgs
parents:
diff changeset
    85
            break;
hgs
parents:
diff changeset
    86
        case EMemSpyDriverOpCodeContainersGetPAndSInfo:
hgs
parents:
diff changeset
    87
            r = GetPAndSInfo( (DObject*) a1, (TMemSpyDriverPAndSInfo*) a2 );
hgs
parents:
diff changeset
    88
            break;
hgs
parents:
diff changeset
    89
        case EMemSpyDriverOpCodeContainersGetCondVarSuspendedThreads:
hgs
parents:
diff changeset
    90
            r = GetCondVarSuspendedThreads( (TMemSpyDriverInternalCondVarSuspendedThreadParams*)a1 );
hgs
parents:
diff changeset
    91
            break;
hgs
parents:
diff changeset
    92
        case EMemSpyDriverOpCodeContainersGetCondVarSuspendedThreadInfo:
hgs
parents:
diff changeset
    93
            r = GetCondVarSuspendedThreadInfo( a1, (TMemSpyDriverCondVarSuspendedThreadInfo*)a2 );
hgs
parents:
diff changeset
    94
            break;
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
        default:
hgs
parents:
diff changeset
    97
            r = KErrNotSupported;
hgs
parents:
diff changeset
    98
		    break;
hgs
parents:
diff changeset
    99
		    }
hgs
parents:
diff changeset
   100
        }
hgs
parents:
diff changeset
   101
    //
hgs
parents:
diff changeset
   102
    return r;
hgs
parents:
diff changeset
   103
	}
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
TBool DMemSpyDriverLogChanContainers::IsHandler( TInt aFunction ) const
hgs
parents:
diff changeset
   107
    {
hgs
parents:
diff changeset
   108
    return ( aFunction > EMemSpyDriverOpCodeContainersBase && aFunction < EMemSpyDriverOpCodeContainersEnd );
hgs
parents:
diff changeset
   109
    }
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
TInt DMemSpyDriverLogChanContainers::GetContainerHandles( TMemSpyDriverInternalContainerHandleParams* aParams )
hgs
parents:
diff changeset
   122
	{
hgs
parents:
diff changeset
   123
    TMemSpyDriverInternalContainerHandleParams params;
hgs
parents:
diff changeset
   124
    TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverInternalContainerHandleParams) );
hgs
parents:
diff changeset
   125
    if  ( r != KErrNone )
hgs
parents:
diff changeset
   126
        {
hgs
parents:
diff changeset
   127
    	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles() - END - params read error: %d", r));
hgs
parents:
diff changeset
   128
        return r;
hgs
parents:
diff changeset
   129
        }
hgs
parents:
diff changeset
   130
hgs
parents:
diff changeset
   131
	const TInt maxCount = params.iMaxCount;
hgs
parents:
diff changeset
   132
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles() - START - tid or pid: %d, maxCount: %d, container: %d, handleSource: %d", params.iTidOrPid, maxCount, params.iContainer, params.iHandleSource ));
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
    DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
hgs
parents:
diff changeset
   135
    DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
    ResetTempHandles();
hgs
parents:
diff changeset
   138
hgs
parents:
diff changeset
   139
    if  ( params.iTidOrPid == KMemSpyDriverEnumerateContainerHandles )
hgs
parents:
diff changeset
   140
        {
hgs
parents:
diff changeset
   141
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - enumerating container handles... " ));
hgs
parents:
diff changeset
   142
	    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
        // We are enumerating an entire container - not a thread-specific request
hgs
parents:
diff changeset
   145
        const TObjectType type = ObjectTypeFromMemSpyContainerType( params.iContainer );
hgs
parents:
diff changeset
   146
hgs
parents:
diff changeset
   147
        DObjectCon* container = Kern::Containers()[type];
hgs
parents:
diff changeset
   148
        container->Wait();
hgs
parents:
diff changeset
   149
hgs
parents:
diff changeset
   150
        const TInt count = container->Count();
hgs
parents:
diff changeset
   151
        for(TInt i=0; i<count; i++)
hgs
parents:
diff changeset
   152
            {
hgs
parents:
diff changeset
   153
            DObject* object = (*container)[ i ];
hgs
parents:
diff changeset
   154
            if  ( object != NULL )
hgs
parents:
diff changeset
   155
                {
hgs
parents:
diff changeset
   156
                AddTempHandle( object );
hgs
parents:
diff changeset
   157
                }
hgs
parents:
diff changeset
   158
            }
hgs
parents:
diff changeset
   159
hgs
parents:
diff changeset
   160
        container->Signal();
hgs
parents:
diff changeset
   161
    	NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   162
        }
hgs
parents:
diff changeset
   163
    else
hgs
parents:
diff changeset
   164
        {
hgs
parents:
diff changeset
   165
        // Are we dealing with threads or processes?
hgs
parents:
diff changeset
   166
        const TObjectType sourceContainerType = (TObjectType) params.iHandleSource;
hgs
parents:
diff changeset
   167
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - sourceContainerType: %d", sourceContainerType ));
hgs
parents:
diff changeset
   168
hgs
parents:
diff changeset
   169
        // We need to open the process or thread in order to get its handle
hgs
parents:
diff changeset
   170
        r = OpenTempObject( params.iTidOrPid, sourceContainerType );
hgs
parents:
diff changeset
   171
        if  ( r == KErrNone )
hgs
parents:
diff changeset
   172
		    {
hgs
parents:
diff changeset
   173
            TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - handle source object: %O", TempObject() ));
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
            // This is the source for the handles we want to check. Its either the process or thread's handle index...
hgs
parents:
diff changeset
   176
            MemSpyObjectIx* handles = NULL;
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
            // Check that the process' thread's are suspended and get handle index
hgs
parents:
diff changeset
   179
            if  ( params.iHandleSource == EMemSpyDriverThreadOrProcessTypeThread )
hgs
parents:
diff changeset
   180
                {
hgs
parents:
diff changeset
   181
                DThread* thread = (DThread*) TempObject();
hgs
parents:
diff changeset
   182
                if  ( !SuspensionManager().IsSuspended( *thread ) )
hgs
parents:
diff changeset
   183
                    {
hgs
parents:
diff changeset
   184
                    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - parent process not suspended => KErrAccessDenied"));
hgs
parents:
diff changeset
   185
                    r = KErrAccessDenied;
hgs
parents:
diff changeset
   186
                    }
hgs
parents:
diff changeset
   187
                else
hgs
parents:
diff changeset
   188
                    {
hgs
parents:
diff changeset
   189
                    handles = threadAdaption.GetHandles( *thread );
hgs
parents:
diff changeset
   190
                    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - checking handles for thread: %O", thread ));
hgs
parents:
diff changeset
   191
                    }
hgs
parents:
diff changeset
   192
                }
hgs
parents:
diff changeset
   193
            else if ( params.iHandleSource == EMemSpyDriverThreadOrProcessTypeProcess )
hgs
parents:
diff changeset
   194
                {
hgs
parents:
diff changeset
   195
                DProcess* process = (DProcess*) TempObject();
hgs
parents:
diff changeset
   196
                if  ( !SuspensionManager().IsSuspended( *process ) )
hgs
parents:
diff changeset
   197
                    {
hgs
parents:
diff changeset
   198
                    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - process not suspended => KErrAccessDenied"));
hgs
parents:
diff changeset
   199
                    r =KErrAccessDenied;
hgs
parents:
diff changeset
   200
                    }
hgs
parents:
diff changeset
   201
                else
hgs
parents:
diff changeset
   202
                    {
hgs
parents:
diff changeset
   203
                    handles = processAdaption.GetHandles( *process );
hgs
parents:
diff changeset
   204
                    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - checking handles for process: %O", process ));
hgs
parents:
diff changeset
   205
                    }
hgs
parents:
diff changeset
   206
                }
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
            if  ( handles )
hgs
parents:
diff changeset
   209
                {
hgs
parents:
diff changeset
   210
	            NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   211
hgs
parents:
diff changeset
   212
                // Iterate through each handle in the thread/process and add it to the temp handles container if
hgs
parents:
diff changeset
   213
                // the handle is of the correct type.
hgs
parents:
diff changeset
   214
hgs
parents:
diff changeset
   215
				MemSpyObjectIx_HandleLookupLock();
hgs
parents:
diff changeset
   216
				const TInt handleCount = handles->Count();
hgs
parents:
diff changeset
   217
				MemSpyObjectIx_HandleLookupUnlock();
hgs
parents:
diff changeset
   218
                TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - %d handles in index...", handleCount ));
hgs
parents:
diff changeset
   219
hgs
parents:
diff changeset
   220
                for( TInt handleIndex=0; handleIndex<handleCount; handleIndex++ )
hgs
parents:
diff changeset
   221
    	            {
hgs
parents:
diff changeset
   222
    	            // Get a handle from the container...
hgs
parents:
diff changeset
   223
					MemSpyObjectIx_HandleLookupLock();
hgs
parents:
diff changeset
   224
					if (handleIndex >= handles->Count()) break; // Count may have changed in the meantime
hgs
parents:
diff changeset
   225
    				DObject* objectToSearchFor = (*handles)[ handleIndex ];
hgs
parents:
diff changeset
   226
					if (objectToSearchFor && objectToSearchFor->Open() != KErrNone) objectToSearchFor = NULL;
hgs
parents:
diff changeset
   227
					MemSpyObjectIx_HandleLookupUnlock();
hgs
parents:
diff changeset
   228
        
hgs
parents:
diff changeset
   229
                    if (objectToSearchFor && OSAdaption().DThread().GetObjectType(*objectToSearchFor) == ObjectTypeFromMemSpyContainerType(params.iContainer))
hgs
parents:
diff changeset
   230
                        {
hgs
parents:
diff changeset
   231
                        // Found a match in the specified container. Write the object's handle (aka the object address)
hgs
parents:
diff changeset
   232
                        // back to the client address space
hgs
parents:
diff changeset
   233
                        AddTempHandle( objectToSearchFor );
hgs
parents:
diff changeset
   234
                        }
hgs
parents:
diff changeset
   235
					if (objectToSearchFor) objectToSearchFor->Close(NULL);
hgs
parents:
diff changeset
   236
    	            }
hgs
parents:
diff changeset
   237
hgs
parents:
diff changeset
   238
                NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   239
                }
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
            // Done with this now.
hgs
parents:
diff changeset
   242
            CloseTempObject();
hgs
parents:
diff changeset
   243
            }
hgs
parents:
diff changeset
   244
        else
hgs
parents:
diff changeset
   245
		    {
hgs
parents:
diff changeset
   246
    	    Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - thread / process not found");
hgs
parents:
diff changeset
   247
		    }
hgs
parents:
diff changeset
   248
        }
hgs
parents:
diff changeset
   249
hgs
parents:
diff changeset
   250
    // Write back handles to client
hgs
parents:
diff changeset
   251
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles - trying to write %d handles to client...", TempHandleCount() ));
hgs
parents:
diff changeset
   252
    r = WriteToClient( params.iHandles, params.iCountPtr, maxCount );
hgs
parents:
diff changeset
   253
hgs
parents:
diff changeset
   254
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetContainerHandles() - END - r: %d", r));
hgs
parents:
diff changeset
   255
	return r;
hgs
parents:
diff changeset
   256
    }
hgs
parents:
diff changeset
   257
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
TInt DMemSpyDriverLogChanContainers::GetGenericHandleInfo( TInt aTid, TMemSpyDriverHandleInfoGeneric* aParams )
hgs
parents:
diff changeset
   260
    {
hgs
parents:
diff changeset
   261
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - START" ));
hgs
parents:
diff changeset
   262
hgs
parents:
diff changeset
   263
    TMemSpyDriverHandleInfoGeneric params;
hgs
parents:
diff changeset
   264
    TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverHandleInfoGeneric) );
hgs
parents:
diff changeset
   265
    if  ( r != KErrNone )
hgs
parents:
diff changeset
   266
        {
hgs
parents:
diff changeset
   267
    	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - END - params read error: %d", r));
hgs
parents:
diff changeset
   268
        return r;
hgs
parents:
diff changeset
   269
        }
hgs
parents:
diff changeset
   270
hgs
parents:
diff changeset
   271
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo  - tid: %d, handle: 0x%08x", aTid, params.iHandle ));
hgs
parents:
diff changeset
   272
    
hgs
parents:
diff changeset
   273
    if  ( aTid == KMemSpyDriverEnumerateContainerHandles )
hgs
parents:
diff changeset
   274
        {
hgs
parents:
diff changeset
   275
	    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo - getting info for non-thread specific handle..."));
hgs
parents:
diff changeset
   276
        }
hgs
parents:
diff changeset
   277
    else
hgs
parents:
diff changeset
   278
        {
hgs
parents:
diff changeset
   279
	    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo - thread-specific request..."));
hgs
parents:
diff changeset
   280
hgs
parents:
diff changeset
   281
        r = OpenTempObject( aTid, EThread );
hgs
parents:
diff changeset
   282
	    if (r != KErrNone)
hgs
parents:
diff changeset
   283
		    {
hgs
parents:
diff changeset
   284
    	    Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - END - thread not found");
hgs
parents:
diff changeset
   285
		    return r;
hgs
parents:
diff changeset
   286
		    }
hgs
parents:
diff changeset
   287
    
hgs
parents:
diff changeset
   288
        // Check that the process' thread's are suspended
hgs
parents:
diff changeset
   289
        DThread* thread = (DThread*) TempObject();
hgs
parents:
diff changeset
   290
	    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo - opened thread: %O", thread));
hgs
parents:
diff changeset
   291
        if  ( !SuspensionManager().IsSuspended( *thread ) )
hgs
parents:
diff changeset
   292
            {
hgs
parents:
diff changeset
   293
            TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - END - parent process not suspended => KErrAccessDenied"));
hgs
parents:
diff changeset
   294
            CloseTempObject();
hgs
parents:
diff changeset
   295
            return KErrAccessDenied;
hgs
parents:
diff changeset
   296
            }
hgs
parents:
diff changeset
   297
        }
hgs
parents:
diff changeset
   298
hgs
parents:
diff changeset
   299
	NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   300
hgs
parents:
diff changeset
   301
    // First, locate the specific DObject in question. Cast the handle, but don't use the object...
hgs
parents:
diff changeset
   302
    DObject* handleAsObject = (DObject*) params.iHandle;
hgs
parents:
diff changeset
   303
    handleAsObject = CheckedOpen(params.iType, handleAsObject);
hgs
parents:
diff changeset
   304
    if  ( handleAsObject != NULL )
hgs
parents:
diff changeset
   305
        {
hgs
parents:
diff changeset
   306
        // We found the right object. First get generic info.
hgs
parents:
diff changeset
   307
        handleAsObject->FullName( params.iName );
hgs
parents:
diff changeset
   308
        handleAsObject->Name( params.iNameDetail );
hgs
parents:
diff changeset
   309
        
hgs
parents:
diff changeset
   310
        // Using threadAddaption to fetch generic info.
hgs
parents:
diff changeset
   311
        // Implementations of following get functions are actually in DMemSpyDriverOSAdaptionDObject
hgs
parents:
diff changeset
   312
        // so it does not matter what adaption to use for generic info.
hgs
parents:
diff changeset
   313
        DMemSpyDriverOSAdaptionDThread& threadAddaption = OSAdaption().DThread();
hgs
parents:
diff changeset
   314
        params.iAccessCount = threadAddaption.GetAccessCount( *handleAsObject );
hgs
parents:
diff changeset
   315
        params.iUniqueID = threadAddaption.GetUniqueID( *handleAsObject );
hgs
parents:
diff changeset
   316
        params.iProtection = threadAddaption.GetProtection( *handleAsObject );
hgs
parents:
diff changeset
   317
        params.iAddressOfKernelOwner = threadAddaption.GetAddressOfKernelOwner( *handleAsObject );
hgs
parents:
diff changeset
   318
        
hgs
parents:
diff changeset
   319
        // Get type-specific info.
hgs
parents:
diff changeset
   320
        if  ( params.iType == EMemSpyDriverContainerTypeThread )
hgs
parents:
diff changeset
   321
            {
hgs
parents:
diff changeset
   322
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeThread" ));
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
            DThread* object = (DThread*) handleAsObject;
hgs
parents:
diff changeset
   325
            DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
hgs
parents:
diff changeset
   326
            //
hgs
parents:
diff changeset
   327
            params.iId = threadAdaption.GetId( *object );
hgs
parents:
diff changeset
   328
            params.iPriority = threadAdaption.GetPriority( *object );
hgs
parents:
diff changeset
   329
            params.iAddressOfOwningProcess = threadAdaption.GetAddressOfOwningProcess( *object );
hgs
parents:
diff changeset
   330
            threadAdaption.GetNameOfOwningProcess( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   331
            }
hgs
parents:
diff changeset
   332
        else if ( params.iType == EMemSpyDriverContainerTypeProcess )
hgs
parents:
diff changeset
   333
            {
hgs
parents:
diff changeset
   334
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeProcess" ));
hgs
parents:
diff changeset
   335
hgs
parents:
diff changeset
   336
            DProcess* object = (DProcess*) handleAsObject;
hgs
parents:
diff changeset
   337
            DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
hgs
parents:
diff changeset
   338
            //
hgs
parents:
diff changeset
   339
            params.iId = processAdaption.GetId( *object );
hgs
parents:
diff changeset
   340
            //
hgs
parents:
diff changeset
   341
            params.iPriority = processAdaption.GetPriority( *object );
hgs
parents:
diff changeset
   342
            params.iAddressOfOwningProcess = processAdaption.GetAddressOfOwningProcess( *object );
hgs
parents:
diff changeset
   343
            params.iCreatorId = processAdaption.GetCreatorId( *object );
hgs
parents:
diff changeset
   344
            params.iSecurityZone = processAdaption.GetSecurityZone( *object );
hgs
parents:
diff changeset
   345
            params.iAttributes = processAdaption.GetAttributes( *object );
hgs
parents:
diff changeset
   346
            params.iAddressOfDataBssStackChunk = processAdaption.GetAddressOfDataBssStackChunk( *object );
hgs
parents:
diff changeset
   347
            }
hgs
parents:
diff changeset
   348
        else if ( params.iType == EMemSpyDriverContainerTypeChunk )
hgs
parents:
diff changeset
   349
            {
hgs
parents:
diff changeset
   350
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeChunk" ));
hgs
parents:
diff changeset
   351
hgs
parents:
diff changeset
   352
            DChunk* object = (DChunk*) handleAsObject;
hgs
parents:
diff changeset
   353
            DMemSpyDriverOSAdaptionDChunk& ca = OSAdaption().DChunk();
hgs
parents:
diff changeset
   354
            //
hgs
parents:
diff changeset
   355
            params.iSize = ca.GetSize( *object );
hgs
parents:
diff changeset
   356
            params.iId = ca.GetOwningProcessId( *object );
hgs
parents:
diff changeset
   357
            params.iAddressOfOwningProcess = ca.GetAddressOfOwningProcess( *object );
hgs
parents:
diff changeset
   358
            params.iMaxSize = ca.GetMaxSize( *object );
hgs
parents:
diff changeset
   359
            params.iBottom = ca.GetBottom( *object );
hgs
parents:
diff changeset
   360
            params.iTop = ca.GetTop( *object );
hgs
parents:
diff changeset
   361
            params.iAttributes = ca.GetAttributes( *object );
hgs
parents:
diff changeset
   362
            params.iStartPos = ca.GetStartPos( *object );
hgs
parents:
diff changeset
   363
            params.iControllingOwner = ca.GetControllingOwnerId( *object );
hgs
parents:
diff changeset
   364
            params.iRestrictions = ca.GetRestrictions( *object );
hgs
parents:
diff changeset
   365
            params.iMapAttr = ca.GetMapAttr( *object );
hgs
parents:
diff changeset
   366
            params.iChunkType = ca.GetType( *object );
hgs
parents:
diff changeset
   367
            ca.GetNameOfOwningProcess( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   368
            }
hgs
parents:
diff changeset
   369
        else if ( params.iType == EMemSpyDriverContainerTypeLibrary )
hgs
parents:
diff changeset
   370
            {
hgs
parents:
diff changeset
   371
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeLibrary" ));
hgs
parents:
diff changeset
   372
hgs
parents:
diff changeset
   373
	        Kern::AccessCode();
hgs
parents:
diff changeset
   374
            //
hgs
parents:
diff changeset
   375
            DLibrary* object = (DLibrary*) handleAsObject;
hgs
parents:
diff changeset
   376
            DMemSpyDriverOSAdaptionDCodeSeg& csa = OSAdaption().DCodeSeg();
hgs
parents:
diff changeset
   377
            DCodeSeg* codeSeg = csa.GetCodeSeg( *object );
hgs
parents:
diff changeset
   378
            params.iAddressOfCodeSeg = (TUint8*)codeSeg;
hgs
parents:
diff changeset
   379
            params.iMapCount = csa.GetMapCount( *object );
hgs
parents:
diff changeset
   380
            params.iState = csa.GetState( *object );
hgs
parents:
diff changeset
   381
            //
hgs
parents:
diff changeset
   382
            if  ( codeSeg )
hgs
parents:
diff changeset
   383
                {
hgs
parents:
diff changeset
   384
                params.iSize = csa.GetSize( *codeSeg );
hgs
parents:
diff changeset
   385
                }
hgs
parents:
diff changeset
   386
            else
hgs
parents:
diff changeset
   387
                {
hgs
parents:
diff changeset
   388
                r = KErrNotFound;
hgs
parents:
diff changeset
   389
                }
hgs
parents:
diff changeset
   390
            //
hgs
parents:
diff changeset
   391
	        Kern::EndAccessCode();
hgs
parents:
diff changeset
   392
            }
hgs
parents:
diff changeset
   393
        else if ( params.iType == EMemSpyDriverContainerTypeSemaphore )
hgs
parents:
diff changeset
   394
            {
hgs
parents:
diff changeset
   395
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeSemaphore" ));
hgs
parents:
diff changeset
   396
hgs
parents:
diff changeset
   397
            DSemaphore* object = (DSemaphore*) handleAsObject;
hgs
parents:
diff changeset
   398
            DMemSpyDriverOSAdaptionDSemaphore& sa = OSAdaption().DSemaphore();
hgs
parents:
diff changeset
   399
            params.iCount = sa.GetCount( *object );
hgs
parents:
diff changeset
   400
            params.iResetting = sa.GetResetting( *object );
hgs
parents:
diff changeset
   401
            }
hgs
parents:
diff changeset
   402
        else if ( params.iType == EMemSpyDriverContainerTypeMutex )
hgs
parents:
diff changeset
   403
            {
hgs
parents:
diff changeset
   404
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeMutex" ));
hgs
parents:
diff changeset
   405
hgs
parents:
diff changeset
   406
            DMutex* object = (DMutex*) handleAsObject;
hgs
parents:
diff changeset
   407
            DMemSpyDriverOSAdaptionDMutex& ma = OSAdaption().DMutex();
hgs
parents:
diff changeset
   408
            //
hgs
parents:
diff changeset
   409
            params.iCount = ma.GetHoldCount( *object );
hgs
parents:
diff changeset
   410
            params.iWaitCount = ma.GetWaitCount( *object );
hgs
parents:
diff changeset
   411
            params.iResetting = ma.GetResetting( *object );
hgs
parents:
diff changeset
   412
            params.iOrder = ma.GetOrder( *object );
hgs
parents:
diff changeset
   413
            }
hgs
parents:
diff changeset
   414
        else if ( params.iType == EMemSpyDriverContainerTypeTimer )
hgs
parents:
diff changeset
   415
            {
hgs
parents:
diff changeset
   416
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeTimer" ));
hgs
parents:
diff changeset
   417
hgs
parents:
diff changeset
   418
            // Get timer properties
hgs
parents:
diff changeset
   419
            DTimer* object = (DTimer*) handleAsObject;
hgs
parents:
diff changeset
   420
            DMemSpyDriverOSAdaptionDTimer& ta = OSAdaption().DTimer();
hgs
parents:
diff changeset
   421
            //
hgs
parents:
diff changeset
   422
            params.iTimerType = MapToMemSpyTimerType( ta.GetType( *object ) );
hgs
parents:
diff changeset
   423
            params.iTimerState = MapToMemSpyTimerState( ta.GetState( *object ) );
hgs
parents:
diff changeset
   424
            }
hgs
parents:
diff changeset
   425
        else if ( params.iType == EMemSpyDriverContainerTypeServer )
hgs
parents:
diff changeset
   426
            {
hgs
parents:
diff changeset
   427
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeServer" ));
hgs
parents:
diff changeset
   428
hgs
parents:
diff changeset
   429
            DServer* object = (DServer*) handleAsObject;
hgs
parents:
diff changeset
   430
            DMemSpyDriverOSAdaptionDServer& sa = OSAdaption().DServer();
hgs
parents:
diff changeset
   431
            //
hgs
parents:
diff changeset
   432
            params.iCount = sa.GetSessionCount( *object );
hgs
parents:
diff changeset
   433
            params.iId = sa.GetOwningThreadId( *object );
hgs
parents:
diff changeset
   434
            params.iSessionType = sa.GetSessionType( *object );
hgs
parents:
diff changeset
   435
            params.iAddressOfOwningThread = sa.GetAddressOfOwningThread( *object );
hgs
parents:
diff changeset
   436
            sa.GetNameOfOwningThread( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   437
            }
hgs
parents:
diff changeset
   438
        else if ( params.iType == EMemSpyDriverContainerTypeSession )
hgs
parents:
diff changeset
   439
            {
hgs
parents:
diff changeset
   440
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeSession" ));
hgs
parents:
diff changeset
   441
hgs
parents:
diff changeset
   442
            DSession* object = (DSession*) handleAsObject;
hgs
parents:
diff changeset
   443
            DMemSpyDriverOSAdaptionDServer& serverAdaption = OSAdaption().DServer();
hgs
parents:
diff changeset
   444
            DMemSpyDriverOSAdaptionDSession& sessionAdaption = OSAdaption().DSession();
hgs
parents:
diff changeset
   445
hgs
parents:
diff changeset
   446
            params.iName.Zero();
hgs
parents:
diff changeset
   447
hgs
parents:
diff changeset
   448
            TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - getting session type..." ));
hgs
parents:
diff changeset
   449
            params.iSessionType = sessionAdaption.GetSessionType( *object );
hgs
parents:
diff changeset
   450
            params.iAddressOfServer = sessionAdaption.GetAddressOfServer( *object );
hgs
parents:
diff changeset
   451
            params.iTotalAccessCount = sessionAdaption.GetTotalAccessCount( *object );
hgs
parents:
diff changeset
   452
            params.iSvrSessionType = sessionAdaption.GetSessionType( *object );
hgs
parents:
diff changeset
   453
            params.iMsgCount = sessionAdaption.GetMsgCount( *object );
hgs
parents:
diff changeset
   454
            params.iMsgLimit = sessionAdaption.GetMsgLimit( *object );
hgs
parents:
diff changeset
   455
            
hgs
parents:
diff changeset
   456
            // Its more useful in this instance, if the name object
hgs
parents:
diff changeset
   457
            // points to the server which the session is connected to
hgs
parents:
diff changeset
   458
            // (rather than displaying a process-local name).
hgs
parents:
diff changeset
   459
            DServer* server = (DServer*)CheckedOpen(EMemSpyDriverContainerTypeServer, sessionAdaption.GetServer( *object ));
hgs
parents:
diff changeset
   460
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - getting full name, server: 0x%08x", server ));
hgs
parents:
diff changeset
   461
            //
hgs
parents:
diff changeset
   462
            if  ( server )
hgs
parents:
diff changeset
   463
                {
hgs
parents:
diff changeset
   464
                server->FullName( params.iName );
hgs
parents:
diff changeset
   465
hgs
parents:
diff changeset
   466
                // Continue as normal for other items
hgs
parents:
diff changeset
   467
	            TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - server: 0x%08x, server->iOwningThread: 0x%08x", server, server->iOwningThread ));
hgs
parents:
diff changeset
   468
                DThread* owningThread = serverAdaption.GetOwningThread( *server );
hgs
parents:
diff changeset
   469
                if  ( owningThread )
hgs
parents:
diff changeset
   470
                    {
hgs
parents:
diff changeset
   471
	                TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - getting server thread id..." ));
hgs
parents:
diff changeset
   472
                    params.iId = serverAdaption.GetOwningThreadId( *server );
hgs
parents:
diff changeset
   473
                    }
hgs
parents:
diff changeset
   474
hgs
parents:
diff changeset
   475
                server->Close(NULL);
hgs
parents:
diff changeset
   476
                }
hgs
parents:
diff changeset
   477
            }
hgs
parents:
diff changeset
   478
        else if ( params.iType == EMemSpyDriverContainerTypeLogicalDevice )
hgs
parents:
diff changeset
   479
            {
hgs
parents:
diff changeset
   480
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeLogicalDevice" ));
hgs
parents:
diff changeset
   481
hgs
parents:
diff changeset
   482
            DLogicalDevice* object = (DLogicalDevice*) handleAsObject;
hgs
parents:
diff changeset
   483
            DMemSpyDriverOSAdaptionDLogicalDevice& lda = OSAdaption().DLogicalDevice();
hgs
parents:
diff changeset
   484
            params.iOpenChannels = lda.GetOpenChannels( *object );
hgs
parents:
diff changeset
   485
            params.iVersion = lda.GetVersion( *object );
hgs
parents:
diff changeset
   486
            params.iParseMask = lda.GetParseMask( *object );
hgs
parents:
diff changeset
   487
            params.iUnitsMask = lda.GetUnitsMask( *object );
hgs
parents:
diff changeset
   488
            }
hgs
parents:
diff changeset
   489
        else if ( params.iType == EMemSpyDriverContainerTypePhysicalDevice )
hgs
parents:
diff changeset
   490
            {
hgs
parents:
diff changeset
   491
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypePhysicalDevice" ));
hgs
parents:
diff changeset
   492
	        
hgs
parents:
diff changeset
   493
	        DPhysicalDevice* object = (DPhysicalDevice*) handleAsObject;
hgs
parents:
diff changeset
   494
            DMemSpyDriverOSAdaptionDPhysicalDevice& pda = OSAdaption().DPhysicalDevice();
hgs
parents:
diff changeset
   495
            params.iVersion = pda.GetVersion( *object );
hgs
parents:
diff changeset
   496
            params.iUnitsMask = pda.GetUnitsMask( *object );
hgs
parents:
diff changeset
   497
            params.iAddressOfCodeSeg = pda.GetAddressOfCodeSeg( *object );
hgs
parents:
diff changeset
   498
            }
hgs
parents:
diff changeset
   499
        else if ( params.iType == EMemSpyDriverContainerTypeLogicalChannel )
hgs
parents:
diff changeset
   500
            {
hgs
parents:
diff changeset
   501
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeLogicalChannel" ));
hgs
parents:
diff changeset
   502
            }
hgs
parents:
diff changeset
   503
        else if ( params.iType == EMemSpyDriverContainerTypeChangeNotifier )
hgs
parents:
diff changeset
   504
            {
hgs
parents:
diff changeset
   505
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeChangeNotifier" ));
hgs
parents:
diff changeset
   506
hgs
parents:
diff changeset
   507
	        DChangeNotifier* object = (DChangeNotifier*) handleAsObject;
hgs
parents:
diff changeset
   508
            DMemSpyDriverOSAdaptionDChangeNotifier& cna = OSAdaption().DChangeNotifier();
hgs
parents:
diff changeset
   509
            params.iChanges = cna.GetChanges( *object );
hgs
parents:
diff changeset
   510
            params.iAddressOfOwningThread = cna.GetAddressOfOwningThread( *object );
hgs
parents:
diff changeset
   511
            cna.GetNameOfOwningThread( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   512
            }
hgs
parents:
diff changeset
   513
        else if ( params.iType == EMemSpyDriverContainerTypeUndertaker )
hgs
parents:
diff changeset
   514
            {
hgs
parents:
diff changeset
   515
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeUndertaker" ));
hgs
parents:
diff changeset
   516
	        
hgs
parents:
diff changeset
   517
            DUndertaker* object = (DUndertaker*) handleAsObject;
hgs
parents:
diff changeset
   518
            DMemSpyDriverOSAdaptionDUndertaker& uta = OSAdaption().DUndertaker();
hgs
parents:
diff changeset
   519
            params.iAddressOfOwningThread = uta.GetAddressOfOwningThread( *object );
hgs
parents:
diff changeset
   520
            uta.GetNameOfOwningThread( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   521
            }
hgs
parents:
diff changeset
   522
        else if ( params.iType == EMemSpyDriverContainerTypeMsgQueue )
hgs
parents:
diff changeset
   523
            {
hgs
parents:
diff changeset
   524
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeMsgQueue" ));
hgs
parents:
diff changeset
   525
            }
hgs
parents:
diff changeset
   526
        else if ( params.iType == EMemSpyDriverContainerTypePropertyRef )
hgs
parents:
diff changeset
   527
            {
hgs
parents:
diff changeset
   528
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypePropertyRef" ));
hgs
parents:
diff changeset
   529
            }
hgs
parents:
diff changeset
   530
        else if ( params.iType == EMemSpyDriverContainerTypeCondVar )
hgs
parents:
diff changeset
   531
            {
hgs
parents:
diff changeset
   532
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - EMemSpyDriverContainerTypeCondVar" ));
hgs
parents:
diff changeset
   533
	        
hgs
parents:
diff changeset
   534
            DCondVar* object = (DCondVar*) handleAsObject;
hgs
parents:
diff changeset
   535
            DMemSpyDriverOSAdaptionDCondVar& cva = OSAdaption().DCondVar();
hgs
parents:
diff changeset
   536
            params.iResetting = cva.GetResetting( *object );
hgs
parents:
diff changeset
   537
            params.iAddressOfOwningThread = cva.GetAddressOfMutex( *object );
hgs
parents:
diff changeset
   538
            cva.GetNameOfMutex( *object, params.iNameOfOwner );
hgs
parents:
diff changeset
   539
            params.iWaitCount = cva.GetWaitCount( *object );
hgs
parents:
diff changeset
   540
            }
hgs
parents:
diff changeset
   541
        else
hgs
parents:
diff changeset
   542
            {
hgs
parents:
diff changeset
   543
	        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - KErrNotSupported" ));
hgs
parents:
diff changeset
   544
            r = KErrNotSupported;
hgs
parents:
diff changeset
   545
            }
hgs
parents:
diff changeset
   546
		handleAsObject->Close(NULL);
hgs
parents:
diff changeset
   547
        }
hgs
parents:
diff changeset
   548
    else
hgs
parents:
diff changeset
   549
        {
hgs
parents:
diff changeset
   550
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo - couldn not find object => KErrNotFound"));
hgs
parents:
diff changeset
   551
        r = KErrNotFound;
hgs
parents:
diff changeset
   552
        }
hgs
parents:
diff changeset
   553
hgs
parents:
diff changeset
   554
	NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   555
hgs
parents:
diff changeset
   556
    if  ( r == KErrNone )
hgs
parents:
diff changeset
   557
        {
hgs
parents:
diff changeset
   558
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo - writing back to client thread..."));
hgs
parents:
diff changeset
   559
        r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverHandleInfoGeneric) );
hgs
parents:
diff changeset
   560
        }
hgs
parents:
diff changeset
   561
    if  ( TempObject() != NULL )
hgs
parents:
diff changeset
   562
        {
hgs
parents:
diff changeset
   563
    	CloseTempObject();
hgs
parents:
diff changeset
   564
        }
hgs
parents:
diff changeset
   565
hgs
parents:
diff changeset
   566
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetGenericHandleInfo() - END - r: %d", r));
hgs
parents:
diff changeset
   567
	return r;
hgs
parents:
diff changeset
   568
    }
hgs
parents:
diff changeset
   569
hgs
parents:
diff changeset
   570
hgs
parents:
diff changeset
   571
TInt DMemSpyDriverLogChanContainers::GetKernelObjectSizeApproximation( TMemSpyDriverContainerType aType, TInt* aSize )
hgs
parents:
diff changeset
   572
    {
hgs
parents:
diff changeset
   573
    TInt r = KErrNone;
hgs
parents:
diff changeset
   574
    //
hgs
parents:
diff changeset
   575
	TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetKernelObjectSizeApproximation() - START - aType: %d", aType));
hgs
parents:
diff changeset
   576
    const TObjectType objectType = ObjectTypeFromMemSpyContainerType( aType );
hgs
parents:
diff changeset
   577
    //
hgs
parents:
diff changeset
   578
    TInt size = 0;
hgs
parents:
diff changeset
   579
    //
hgs
parents:
diff changeset
   580
    switch( objectType )
hgs
parents:
diff changeset
   581
        {
hgs
parents:
diff changeset
   582
    case EThread:
hgs
parents:
diff changeset
   583
        size = sizeof(DThread);
hgs
parents:
diff changeset
   584
        break;
hgs
parents:
diff changeset
   585
    case EProcess:
hgs
parents:
diff changeset
   586
        size = sizeof(DProcess);
hgs
parents:
diff changeset
   587
        break;
hgs
parents:
diff changeset
   588
    case EChunk:
hgs
parents:
diff changeset
   589
        size = sizeof(DChunk);
hgs
parents:
diff changeset
   590
        break;
hgs
parents:
diff changeset
   591
    case ELibrary:
hgs
parents:
diff changeset
   592
        size = sizeof(DLibrary);
hgs
parents:
diff changeset
   593
        break;
hgs
parents:
diff changeset
   594
    case ESemaphore:
hgs
parents:
diff changeset
   595
        size = sizeof(DSemaphore);
hgs
parents:
diff changeset
   596
        break;
hgs
parents:
diff changeset
   597
    case EMutex:
hgs
parents:
diff changeset
   598
        size = sizeof(DMutex);
hgs
parents:
diff changeset
   599
        break;
hgs
parents:
diff changeset
   600
    case ETimer:
hgs
parents:
diff changeset
   601
        size = sizeof(DTimer);
hgs
parents:
diff changeset
   602
        break;
hgs
parents:
diff changeset
   603
    case EServer:
hgs
parents:
diff changeset
   604
        size = sizeof(DServer);
hgs
parents:
diff changeset
   605
        break;
hgs
parents:
diff changeset
   606
    case ESession:
hgs
parents:
diff changeset
   607
        size = sizeof(DSession);
hgs
parents:
diff changeset
   608
        break;
hgs
parents:
diff changeset
   609
    case ELogicalDevice:
hgs
parents:
diff changeset
   610
        size = sizeof(DLogicalDevice);
hgs
parents:
diff changeset
   611
        break;
hgs
parents:
diff changeset
   612
    case EPhysicalDevice:
hgs
parents:
diff changeset
   613
        size = sizeof(DPhysicalDevice);
hgs
parents:
diff changeset
   614
        break;
hgs
parents:
diff changeset
   615
    case ELogicalChannel:
hgs
parents:
diff changeset
   616
        size = sizeof(DLogicalChannel);
hgs
parents:
diff changeset
   617
        break;
hgs
parents:
diff changeset
   618
    case EChangeNotifier:
hgs
parents:
diff changeset
   619
        size = sizeof(DChangeNotifier);
hgs
parents:
diff changeset
   620
        break;
hgs
parents:
diff changeset
   621
    case EUndertaker:
hgs
parents:
diff changeset
   622
        size = sizeof(DUndertaker);
hgs
parents:
diff changeset
   623
        break;
hgs
parents:
diff changeset
   624
    case EMsgQueue:
hgs
parents:
diff changeset
   625
        size = sizeof(DObject); // best we can do!
hgs
parents:
diff changeset
   626
        break;
hgs
parents:
diff changeset
   627
    case EPropertyRef:
hgs
parents:
diff changeset
   628
        size = sizeof(DObject); // best we can do!
hgs
parents:
diff changeset
   629
        break;
hgs
parents:
diff changeset
   630
    case ECondVar:
hgs
parents:
diff changeset
   631
        size = sizeof(DCondVar);
hgs
parents:
diff changeset
   632
        break;
hgs
parents:
diff changeset
   633
    default:
hgs
parents:
diff changeset
   634
        break;
hgs
parents:
diff changeset
   635
        }
hgs
parents:
diff changeset
   636
    //
hgs
parents:
diff changeset
   637
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   638
    r = Kern::ThreadRawWrite( &ClientThread(), aSize, &size, sizeof(TInt) );
hgs
parents:
diff changeset
   639
	NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   640
hgs
parents:
diff changeset
   641
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetKernelObjectSizeApproximation() - END - r: %d, size; %d", r, size));
hgs
parents:
diff changeset
   642
	return r;
hgs
parents:
diff changeset
   643
    }
hgs
parents:
diff changeset
   644
hgs
parents:
diff changeset
   645
hgs
parents:
diff changeset
   646
hgs
parents:
diff changeset
   647
hgs
parents:
diff changeset
   648
hgs
parents:
diff changeset
   649
hgs
parents:
diff changeset
   650
hgs
parents:
diff changeset
   651
hgs
parents:
diff changeset
   652
hgs
parents:
diff changeset
   653
hgs
parents:
diff changeset
   654
hgs
parents:
diff changeset
   655
hgs
parents:
diff changeset
   656
hgs
parents:
diff changeset
   657
hgs
parents:
diff changeset
   658
TInt DMemSpyDriverLogChanContainers::GetReferencesToMyThread( TUint aTid, TDes8* aBufferSink )
hgs
parents:
diff changeset
   659
    {
hgs
parents:
diff changeset
   660
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetReferencesToMyThread() - START - aTid: %d", aTid ));
hgs
parents:
diff changeset
   661
hgs
parents:
diff changeset
   662
    // We open the source thread or process, just to ensure it doesn't die underneath us...
hgs
parents:
diff changeset
   663
    TInt r = OpenTempObject( aTid, EThread );
hgs
parents:
diff changeset
   664
    if  ( r == KErrNone )
hgs
parents:
diff changeset
   665
		{
hgs
parents:
diff changeset
   666
		TInt count = 0;
hgs
parents:
diff changeset
   667
		
hgs
parents:
diff changeset
   668
        // Open stream
hgs
parents:
diff changeset
   669
        RMemSpyMemStreamWriter stream = OpenXferStream();
hgs
parents:
diff changeset
   670
hgs
parents:
diff changeset
   671
        // Get references to this thread by searching the handles of other threads
hgs
parents:
diff changeset
   672
        TInt32* pCountMarkerThread = stream.WriteInt32( 0 );
hgs
parents:
diff changeset
   673
        count = SearchThreadsFor( TempObject(), stream );
hgs
parents:
diff changeset
   674
        *pCountMarkerThread = count;
hgs
parents:
diff changeset
   675
hgs
parents:
diff changeset
   676
        // Get references to this thread by searching the handles of other processes
hgs
parents:
diff changeset
   677
        TInt32* pCountMarkerProcess = stream.WriteInt32( 0 );
hgs
parents:
diff changeset
   678
        count = SearchProcessFor( TempObject(), stream );
hgs
parents:
diff changeset
   679
        *pCountMarkerProcess = count;
hgs
parents:
diff changeset
   680
hgs
parents:
diff changeset
   681
        // Tidy up
hgs
parents:
diff changeset
   682
        r = stream.WriteAndClose( aBufferSink );
hgs
parents:
diff changeset
   683
hgs
parents:
diff changeset
   684
        CloseTempObject();
hgs
parents:
diff changeset
   685
        }
hgs
parents:
diff changeset
   686
                
hgs
parents:
diff changeset
   687
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetReferencesToMyThread() - END - r: %d", r));
hgs
parents:
diff changeset
   688
	return r;
hgs
parents:
diff changeset
   689
    }
hgs
parents:
diff changeset
   690
hgs
parents:
diff changeset
   691
hgs
parents:
diff changeset
   692
TInt DMemSpyDriverLogChanContainers::GetReferencesToMyProcess( TUint aPid, TDes8* aBufferSink )
hgs
parents:
diff changeset
   693
    {
hgs
parents:
diff changeset
   694
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetReferencesToMyProcess() - START - aPid: %d", aPid ));
hgs
parents:
diff changeset
   695
hgs
parents:
diff changeset
   696
    // We open the source thread or process, just to ensure it doesn't die underneath us...
hgs
parents:
diff changeset
   697
    TInt r = OpenTempObject( aPid, EProcess );
hgs
parents:
diff changeset
   698
    if  ( r == KErrNone )
hgs
parents:
diff changeset
   699
		{
hgs
parents:
diff changeset
   700
		TInt count = 0;
hgs
parents:
diff changeset
   701
		
hgs
parents:
diff changeset
   702
        // Open stream
hgs
parents:
diff changeset
   703
        RMemSpyMemStreamWriter stream = OpenXferStream();
hgs
parents:
diff changeset
   704
hgs
parents:
diff changeset
   705
        // Get references to this thread by searching the handles of other threads
hgs
parents:
diff changeset
   706
        TInt32* pCountMarkerThread = stream.WriteInt32( 0 );
hgs
parents:
diff changeset
   707
        count = SearchThreadsFor( TempObject(), stream );
hgs
parents:
diff changeset
   708
        *pCountMarkerThread = count;
hgs
parents:
diff changeset
   709
hgs
parents:
diff changeset
   710
        // Get references to this thread by searching the handles of other processes
hgs
parents:
diff changeset
   711
        TInt32* pCountMarkerProcess = stream.WriteInt32( 0 );
hgs
parents:
diff changeset
   712
        count = SearchProcessFor( TempObject(), stream );
hgs
parents:
diff changeset
   713
        *pCountMarkerProcess = count;
hgs
parents:
diff changeset
   714
hgs
parents:
diff changeset
   715
        // Tidy up
hgs
parents:
diff changeset
   716
        r = stream.WriteAndClose( aBufferSink );
hgs
parents:
diff changeset
   717
hgs
parents:
diff changeset
   718
        CloseTempObject();
hgs
parents:
diff changeset
   719
        }
hgs
parents:
diff changeset
   720
                
hgs
parents:
diff changeset
   721
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetReferencesToMyProcess() - END - r: %d", r));
hgs
parents:
diff changeset
   722
	return r;
hgs
parents:
diff changeset
   723
    }
hgs
parents:
diff changeset
   724
hgs
parents:
diff changeset
   725
hgs
parents:
diff changeset
   726
TInt DMemSpyDriverLogChanContainers::GetPAndSInfo( DObject* aHandle, TMemSpyDriverPAndSInfo* aInfo )
hgs
parents:
diff changeset
   727
    {
hgs
parents:
diff changeset
   728
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetPAndSInfo() - START - aHandle: 0x%08x", aHandle ));
hgs
parents:
diff changeset
   729
hgs
parents:
diff changeset
   730
    TInt r = KErrNotFound;
hgs
parents:
diff changeset
   731
	NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   732
hgs
parents:
diff changeset
   733
    // First, locate the specific DObject in question. Cast the handle, but don't use the object...
hgs
parents:
diff changeset
   734
    DObject* object = CheckedOpen(EMemSpyDriverContainerTypePropertyRef, aHandle);
hgs
parents:
diff changeset
   735
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetPAndSInfo() - handle search returned: 0x%08x", object ));
hgs
parents:
diff changeset
   736
hgs
parents:
diff changeset
   737
    if  ( object != NULL )
hgs
parents:
diff changeset
   738
        {
hgs
parents:
diff changeset
   739
        NKern::LockSystem(); // Keep this, the DPropertyRef APIs use it -TomS
hgs
parents:
diff changeset
   740
hgs
parents:
diff changeset
   741
        DMemSpyDriverOSAdaptionDPropertyRef& pra = OSAdaption().DPropertyRef();
hgs
parents:
diff changeset
   742
        const TBool isReady = pra.GetIsReady( *object );
hgs
parents:
diff changeset
   743
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetPAndSInfo() - isReady: %d", isReady ));
hgs
parents:
diff changeset
   744
62
hgs
parents: 51
diff changeset
   745
        TMemSpyDriverPAndSInfo params;
51
hgs
parents:
diff changeset
   746
        if  ( isReady )
hgs
parents:
diff changeset
   747
            {
62
hgs
parents: 51
diff changeset
   748
            //TMemSpyDriverPAndSInfo params;
51
hgs
parents:
diff changeset
   749
            //
hgs
parents:
diff changeset
   750
            params.iType = pra.GetType( *object );
hgs
parents:
diff changeset
   751
            params.iCategory = pra.GetCategory( *object );
hgs
parents:
diff changeset
   752
            params.iKey = pra.GetKey( *object );
hgs
parents:
diff changeset
   753
            params.iRefCount = pra.GetRefCount( *object );
hgs
parents:
diff changeset
   754
            params.iTid = pra.GetThreadId( *object );
hgs
parents:
diff changeset
   755
            params.iCreatorSID = pra.GetCreatorSID( *object );
hgs
parents:
diff changeset
   756
            //
hgs
parents:
diff changeset
   757
            TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetPAndSInfo - writing back to client thread..."));
62
hgs
parents: 51
diff changeset
   758
            //r = Kern::ThreadRawWrite( &ClientThread(), aInfo, &params, sizeof( TMemSpyDriverPAndSInfo ) );
hgs
parents: 51
diff changeset
   759
            r = KErrNone; //--
51
hgs
parents:
diff changeset
   760
            }
hgs
parents:
diff changeset
   761
        else
hgs
parents:
diff changeset
   762
            {
hgs
parents:
diff changeset
   763
            r = KErrNotReady;
hgs
parents:
diff changeset
   764
            }
hgs
parents:
diff changeset
   765
hgs
parents:
diff changeset
   766
        NKern::UnlockSystem();
62
hgs
parents: 51
diff changeset
   767
        //--
hgs
parents: 51
diff changeset
   768
        if( r == KErrNone )
hgs
parents: 51
diff changeset
   769
        	{
hgs
parents: 51
diff changeset
   770
			r = Kern::ThreadRawWrite( &ClientThread(), aInfo, &params, sizeof( TMemSpyDriverPAndSInfo ) );
hgs
parents: 51
diff changeset
   771
        	}
hgs
parents: 51
diff changeset
   772
        
hgs
parents: 51
diff changeset
   773
        //--
51
hgs
parents:
diff changeset
   774
		object->Close(NULL);
hgs
parents:
diff changeset
   775
        }
hgs
parents:
diff changeset
   776
hgs
parents:
diff changeset
   777
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   778
hgs
parents:
diff changeset
   779
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::GetPAndSInfo() - END - r: %d", r));
hgs
parents:
diff changeset
   780
    return r;
hgs
parents:
diff changeset
   781
    }
hgs
parents:
diff changeset
   782
hgs
parents:
diff changeset
   783
hgs
parents:
diff changeset
   784
TInt DMemSpyDriverLogChanContainers::GetCondVarSuspendedThreads( TMemSpyDriverInternalCondVarSuspendedThreadParams* aParams )
hgs
parents:
diff changeset
   785
    {
hgs
parents:
diff changeset
   786
    
hgs
parents:
diff changeset
   787
    TMemSpyDriverInternalCondVarSuspendedThreadParams params;
hgs
parents:
diff changeset
   788
    TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverInternalCondVarSuspendedThreadParams) );
hgs
parents:
diff changeset
   789
    if  ( r != KErrNone )
hgs
parents:
diff changeset
   790
        {
hgs
parents:
diff changeset
   791
        TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrs() - END - params read error: %d", r));
hgs
parents:
diff changeset
   792
        return r;
hgs
parents:
diff changeset
   793
        }
hgs
parents:
diff changeset
   794
    
hgs
parents:
diff changeset
   795
    DMemSpyDriverOSAdaptionDCondVar& condVarAdaption = OSAdaption().DCondVar();
hgs
parents:
diff changeset
   796
    
hgs
parents:
diff changeset
   797
    const TInt maxCount = params.iMaxCount;
hgs
parents:
diff changeset
   798
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   799
    
hgs
parents:
diff changeset
   800
    DObject* condVarHandle = (DObject*) params.iCondVarHandle;
hgs
parents:
diff changeset
   801
    condVarHandle = CheckedOpen(EMemSpyDriverContainerTypeCondVar, condVarHandle);
hgs
parents:
diff changeset
   802
    if  ( condVarHandle == NULL )
hgs
parents:
diff changeset
   803
        {
hgs
parents:
diff changeset
   804
        Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrs() - END - condVar not found");
hgs
parents:
diff changeset
   805
        NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   806
        return KErrNotFound;
hgs
parents:
diff changeset
   807
        }
hgs
parents:
diff changeset
   808
    
hgs
parents:
diff changeset
   809
    ResetTempHandles();
hgs
parents:
diff changeset
   810
        
hgs
parents:
diff changeset
   811
    DCondVar* condVar = (DCondVar*) condVarHandle;
hgs
parents:
diff changeset
   812
    
hgs
parents:
diff changeset
   813
    NKern::LockSystem(); // Keep this, needed for iterating suspended queue -TomS
hgs
parents:
diff changeset
   814
hgs
parents:
diff changeset
   815
    // Iterate through suspended threads, writing back thread pointer (handle)
hgs
parents:
diff changeset
   816
    // to client
hgs
parents:
diff changeset
   817
    SDblQue& suspQueue = condVarAdaption.GetSuspendedQ( *condVar );
hgs
parents:
diff changeset
   818
    SDblQueLink* anchor = &suspQueue.iA;
hgs
parents:
diff changeset
   819
    SDblQueLink* link = suspQueue.First();
hgs
parents:
diff changeset
   820
    while( link != anchor )
hgs
parents:
diff changeset
   821
        {
hgs
parents:
diff changeset
   822
        DThread* thread = condVarAdaption.GetThread( link );
hgs
parents:
diff changeset
   823
hgs
parents:
diff changeset
   824
        // Found a match in the specified container. Write the object's handle (aka the object address)
hgs
parents:
diff changeset
   825
        // back to the client address space
hgs
parents:
diff changeset
   826
        if  ( thread )
hgs
parents:
diff changeset
   827
            {
hgs
parents:
diff changeset
   828
            AddTempHandle( thread );
hgs
parents:
diff changeset
   829
            }
hgs
parents:
diff changeset
   830
hgs
parents:
diff changeset
   831
        // Get next item
hgs
parents:
diff changeset
   832
        link = link->iNext;
hgs
parents:
diff changeset
   833
        }
hgs
parents:
diff changeset
   834
hgs
parents:
diff changeset
   835
    NKern::UnlockSystem();
hgs
parents:
diff changeset
   836
hgs
parents:
diff changeset
   837
    // This variable holds the number of handles that we have already
hgs
parents:
diff changeset
   838
    // written to the client-side.
hgs
parents:
diff changeset
   839
    TInt currentWriteIndex = 0;
hgs
parents:
diff changeset
   840
    const TInt handleCount = TempHandleCount();
hgs
parents:
diff changeset
   841
    TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrs - writing %d handles to client...", handleCount ) );
hgs
parents:
diff changeset
   842
    for( ; currentWriteIndex<handleCount && r == KErrNone && currentWriteIndex < maxCount; )
hgs
parents:
diff changeset
   843
        {
hgs
parents:
diff changeset
   844
        TAny* handle = TempHandleAt( currentWriteIndex );
hgs
parents:
diff changeset
   845
        r = Kern::ThreadRawWrite( &ClientThread(), params.iThrHandles + currentWriteIndex, &handle, sizeof(TAny*) );
hgs
parents:
diff changeset
   846
        if  (r == KErrNone)
hgs
parents:
diff changeset
   847
            {
hgs
parents:
diff changeset
   848
            ++currentWriteIndex;
hgs
parents:
diff changeset
   849
            }
hgs
parents:
diff changeset
   850
        }
hgs
parents:
diff changeset
   851
hgs
parents:
diff changeset
   852
    if  ( r == KErrBadDescriptor )
hgs
parents:
diff changeset
   853
        {
hgs
parents:
diff changeset
   854
        MemSpyDriverUtils::PanicThread( ClientThread(), EPanicBadDescriptor );
hgs
parents:
diff changeset
   855
        }
hgs
parents:
diff changeset
   856
    else
hgs
parents:
diff changeset
   857
        {
hgs
parents:
diff changeset
   858
        const TInt finalWrite = Kern::ThreadRawWrite( &ClientThread(), params.iThrCountPtr, &currentWriteIndex, sizeof(TInt) );
hgs
parents:
diff changeset
   859
        if  ( r == KErrNone )
hgs
parents:
diff changeset
   860
            {
hgs
parents:
diff changeset
   861
            r = finalWrite;
hgs
parents:
diff changeset
   862
            }
hgs
parents:
diff changeset
   863
        }
hgs
parents:
diff changeset
   864
hgs
parents:
diff changeset
   865
	condVarHandle->Close(NULL);
hgs
parents:
diff changeset
   866
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   867
hgs
parents:
diff changeset
   868
    TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrs() - END - r: %d", r));
hgs
parents:
diff changeset
   869
    return r;
hgs
parents:
diff changeset
   870
    }
hgs
parents:
diff changeset
   871
hgs
parents:
diff changeset
   872
hgs
parents:
diff changeset
   873
TInt DMemSpyDriverLogChanContainers::GetCondVarSuspendedThreadInfo( TAny* aThreadHandle, TMemSpyDriverCondVarSuspendedThreadInfo* aParams )
hgs
parents:
diff changeset
   874
    {
hgs
parents:
diff changeset
   875
    TMemSpyDriverCondVarSuspendedThreadInfo params;
hgs
parents:
diff changeset
   876
    
hgs
parents:
diff changeset
   877
    TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverCondVarSuspendedThreadInfo) );
hgs
parents:
diff changeset
   878
    if  ( r != KErrNone )
hgs
parents:
diff changeset
   879
        {
hgs
parents:
diff changeset
   880
        TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrInfo() - END - params read error: %d", r));
hgs
parents:
diff changeset
   881
        return r;
62
hgs
parents: 51
diff changeset
   882
        }        
51
hgs
parents:
diff changeset
   883
hgs
parents:
diff changeset
   884
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   885
hgs
parents:
diff changeset
   886
    DObject* threadHandle = (DObject*) aThreadHandle;
hgs
parents:
diff changeset
   887
    threadHandle = CheckedOpen(EMemSpyDriverContainerTypeThread, threadHandle);
hgs
parents:
diff changeset
   888
    if  ( threadHandle == NULL )
hgs
parents:
diff changeset
   889
        {
hgs
parents:
diff changeset
   890
        Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrInfo() - END - thread not found");
hgs
parents:
diff changeset
   891
        NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   892
        return KErrNotFound;
hgs
parents:
diff changeset
   893
        }
hgs
parents:
diff changeset
   894
hgs
parents:
diff changeset
   895
    DThread* thread = (DThread*) threadHandle;
hgs
parents:
diff changeset
   896
    thread->FullName( params.iName );
hgs
parents:
diff changeset
   897
    params.iAddress = (TUint8*)thread;
hgs
parents:
diff changeset
   898
hgs
parents:
diff changeset
   899
    if  ( r == KErrNone )
hgs
parents:
diff changeset
   900
        {
hgs
parents:
diff changeset
   901
        r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverCondVarSuspendedThreadInfo) );
hgs
parents:
diff changeset
   902
        }
hgs
parents:
diff changeset
   903
    
hgs
parents:
diff changeset
   904
	threadHandle->Close(NULL);
hgs
parents:
diff changeset
   905
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   906
    
hgs
parents:
diff changeset
   907
    TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetCondVarSuspThrInfo() - END - r: %d", r));
hgs
parents:
diff changeset
   908
    return r;
hgs
parents:
diff changeset
   909
    }
hgs
parents:
diff changeset
   910
hgs
parents:
diff changeset
   911
hgs
parents:
diff changeset
   912
hgs
parents:
diff changeset
   913
hgs
parents:
diff changeset
   914
hgs
parents:
diff changeset
   915
hgs
parents:
diff changeset
   916
hgs
parents:
diff changeset
   917
hgs
parents:
diff changeset
   918
hgs
parents:
diff changeset
   919
hgs
parents:
diff changeset
   920
hgs
parents:
diff changeset
   921
hgs
parents:
diff changeset
   922
hgs
parents:
diff changeset
   923
hgs
parents:
diff changeset
   924
hgs
parents:
diff changeset
   925
hgs
parents:
diff changeset
   926
hgs
parents:
diff changeset
   927
hgs
parents:
diff changeset
   928
hgs
parents:
diff changeset
   929
hgs
parents:
diff changeset
   930
hgs
parents:
diff changeset
   931
hgs
parents:
diff changeset
   932
hgs
parents:
diff changeset
   933
hgs
parents:
diff changeset
   934
hgs
parents:
diff changeset
   935
hgs
parents:
diff changeset
   936
hgs
parents:
diff changeset
   937
hgs
parents:
diff changeset
   938
hgs
parents:
diff changeset
   939
hgs
parents:
diff changeset
   940
hgs
parents:
diff changeset
   941
hgs
parents:
diff changeset
   942
hgs
parents:
diff changeset
   943
hgs
parents:
diff changeset
   944
hgs
parents:
diff changeset
   945
hgs
parents:
diff changeset
   946
TInt DMemSpyDriverLogChanContainers::SearchThreadsFor( DObject* aHandleToLookFor, RMemSpyMemStreamWriter& aStream )
hgs
parents:
diff changeset
   947
    {
hgs
parents:
diff changeset
   948
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchThreadsFor() - START" ) );
hgs
parents:
diff changeset
   949
hgs
parents:
diff changeset
   950
    TInt matches = 0;
hgs
parents:
diff changeset
   951
    DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
hgs
parents:
diff changeset
   952
   
hgs
parents:
diff changeset
   953
    DObjectCon* container = Kern::Containers()[ EThread ];
hgs
parents:
diff changeset
   954
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   955
    container->Wait();
hgs
parents:
diff changeset
   956
hgs
parents:
diff changeset
   957
    const TInt containerEntryCount = container->Count();
hgs
parents:
diff changeset
   958
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchThreadsFor - containerEntryCount: %d", containerEntryCount ));
hgs
parents:
diff changeset
   959
hgs
parents:
diff changeset
   960
    for( TInt i=0; i<containerEntryCount && !aStream.IsFull(); i++ )
hgs
parents:
diff changeset
   961
        {
hgs
parents:
diff changeset
   962
        DThread* thread = (DThread*) (*container)[ i ];
hgs
parents:
diff changeset
   963
        MemSpyObjectIx* handles = threadAdaption.GetHandles( *thread );
hgs
parents:
diff changeset
   964
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchThreadsFor - handles: 0x%08x", handles ));
hgs
parents:
diff changeset
   965
hgs
parents:
diff changeset
   966
        if  ( handles != NULL )
hgs
parents:
diff changeset
   967
            {
hgs
parents:
diff changeset
   968
            TBool found = handles->Find( aHandleToLookFor );
hgs
parents:
diff changeset
   969
	        if (found)
hgs
parents:
diff changeset
   970
		        {
hgs
parents:
diff changeset
   971
                TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchThreadsFor - found handle match in [%O]", thread ));
hgs
parents:
diff changeset
   972
                aStream.WriteUint32( (TUint32) thread );
hgs
parents:
diff changeset
   973
                ++matches;
hgs
parents:
diff changeset
   974
		        }
hgs
parents:
diff changeset
   975
            }
hgs
parents:
diff changeset
   976
        }
hgs
parents:
diff changeset
   977
hgs
parents:
diff changeset
   978
    // Finished with thread/process container.
hgs
parents:
diff changeset
   979
    container->Signal();
hgs
parents:
diff changeset
   980
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   981
hgs
parents:
diff changeset
   982
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchThreadsFor() - END" ) );
hgs
parents:
diff changeset
   983
    return matches;
hgs
parents:
diff changeset
   984
    }
hgs
parents:
diff changeset
   985
hgs
parents:
diff changeset
   986
hgs
parents:
diff changeset
   987
TInt DMemSpyDriverLogChanContainers::SearchProcessFor( DObject* aHandleToLookFor, RMemSpyMemStreamWriter& aStream )
hgs
parents:
diff changeset
   988
    {
hgs
parents:
diff changeset
   989
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchProcessFor() - START" ) );
hgs
parents:
diff changeset
   990
hgs
parents:
diff changeset
   991
    TInt matches = 0;
hgs
parents:
diff changeset
   992
    DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
hgs
parents:
diff changeset
   993
  
hgs
parents:
diff changeset
   994
    DObjectCon* container = Kern::Containers()[ EProcess ];
hgs
parents:
diff changeset
   995
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   996
    container->Wait();
hgs
parents:
diff changeset
   997
hgs
parents:
diff changeset
   998
    const TInt containerEntryCount = container->Count();
hgs
parents:
diff changeset
   999
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchProcessFor - containerEntryCount: %d", containerEntryCount ));
hgs
parents:
diff changeset
  1000
hgs
parents:
diff changeset
  1001
    for( TInt i=0; i<containerEntryCount && !aStream.IsFull(); i++ )
hgs
parents:
diff changeset
  1002
        {
hgs
parents:
diff changeset
  1003
        DProcess* process = (DProcess*) (*container)[ i ];
hgs
parents:
diff changeset
  1004
        MemSpyObjectIx* handles = processAdaption.GetHandles( *process );
hgs
parents:
diff changeset
  1005
        TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchProcessFor - handles: 0x%08x", handles ));
hgs
parents:
diff changeset
  1006
hgs
parents:
diff changeset
  1007
        if  ( handles != NULL )
hgs
parents:
diff changeset
  1008
            {
hgs
parents:
diff changeset
  1009
            TBool found = handles->Find( aHandleToLookFor );
hgs
parents:
diff changeset
  1010
	        if  ( found )
hgs
parents:
diff changeset
  1011
		        {
hgs
parents:
diff changeset
  1012
                TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchProcessFor - found handle match in [%O]", process ));
hgs
parents:
diff changeset
  1013
                aStream.WriteUint32( (TUint32) process );
hgs
parents:
diff changeset
  1014
                ++matches;
hgs
parents:
diff changeset
  1015
		        }
hgs
parents:
diff changeset
  1016
            }
hgs
parents:
diff changeset
  1017
        }
hgs
parents:
diff changeset
  1018
hgs
parents:
diff changeset
  1019
    // Finished with thread/process container.
hgs
parents:
diff changeset
  1020
    container->Signal();
hgs
parents:
diff changeset
  1021
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
  1022
hgs
parents:
diff changeset
  1023
    TRACE( Kern::Printf("DMemSpyDriverLogChanContainers::SearchProcessFor() - END" ) );
hgs
parents:
diff changeset
  1024
    return matches;
hgs
parents:
diff changeset
  1025
    }    
hgs
parents:
diff changeset
  1026
hgs
parents:
diff changeset
  1027
hgs
parents:
diff changeset
  1028
TMemSpyDriverTimerState DMemSpyDriverLogChanContainers::MapToMemSpyTimerState( TTimer::TTimerState aState )
hgs
parents:
diff changeset
  1029
    {
hgs
parents:
diff changeset
  1030
    TMemSpyDriverTimerState ret = EMemSpyDriverTimerStateUnknown;
hgs
parents:
diff changeset
  1031
    //
hgs
parents:
diff changeset
  1032
    switch( aState )
hgs
parents:
diff changeset
  1033
        {
hgs
parents:
diff changeset
  1034
    case TTimer::EIdle:
hgs
parents:
diff changeset
  1035
        ret = EMemSpyDriverTimerStateIdle;
hgs
parents:
diff changeset
  1036
        break;
hgs
parents:
diff changeset
  1037
    case TTimer::EWaiting:
hgs
parents:
diff changeset
  1038
        ret = EMemSpyDriverTimerStateWaiting;
hgs
parents:
diff changeset
  1039
        break;
hgs
parents:
diff changeset
  1040
    case TTimer::EWaitHighRes:
hgs
parents:
diff changeset
  1041
        ret = EMemSpyDriverTimerStateWaitHighRes;
hgs
parents:
diff changeset
  1042
        break;
hgs
parents:
diff changeset
  1043
    default:
hgs
parents:
diff changeset
  1044
        break;
hgs
parents:
diff changeset
  1045
        }
hgs
parents:
diff changeset
  1046
    //
hgs
parents:
diff changeset
  1047
    return ret;
hgs
parents:
diff changeset
  1048
    }
hgs
parents:
diff changeset
  1049
hgs
parents:
diff changeset
  1050
 
hgs
parents:
diff changeset
  1051
TMemSpyDriverTimerType DMemSpyDriverLogChanContainers::MapToMemSpyTimerType( TTimer::TTimerType aType )
hgs
parents:
diff changeset
  1052
    {
hgs
parents:
diff changeset
  1053
    TMemSpyDriverTimerType ret = EMemSpyDriverTimerTypeUnknown;
hgs
parents:
diff changeset
  1054
    //
hgs
parents:
diff changeset
  1055
    switch( aType )
hgs
parents:
diff changeset
  1056
        {
hgs
parents:
diff changeset
  1057
    case TTimer::ERelative:
hgs
parents:
diff changeset
  1058
    case TTimer::ELocked:
hgs
parents:
diff changeset
  1059
        ret = EMemSpyDriverTimerTypeRelative;
hgs
parents:
diff changeset
  1060
        break;
hgs
parents:
diff changeset
  1061
    case TTimer::EAbsolute:
hgs
parents:
diff changeset
  1062
        ret = EMemSpyDriverTimerTypeAbsolute;
hgs
parents:
diff changeset
  1063
        break;
hgs
parents:
diff changeset
  1064
    case TTimer::EHighRes:
hgs
parents:
diff changeset
  1065
        ret = EMemSpyDriverTimerTypeHighRes;
hgs
parents:
diff changeset
  1066
        break;
hgs
parents:
diff changeset
  1067
    case TTimer::EInactivity:
hgs
parents:
diff changeset
  1068
        ret = EMemSpyDriverTimerTypeInactivity;
hgs
parents:
diff changeset
  1069
        break;
hgs
parents:
diff changeset
  1070
    default:
hgs
parents:
diff changeset
  1071
        break;
hgs
parents:
diff changeset
  1072
        }
hgs
parents:
diff changeset
  1073
    //
hgs
parents:
diff changeset
  1074
    return ret;
hgs
parents:
diff changeset
  1075
    }
hgs
parents:
diff changeset
  1076
hgs
parents:
diff changeset
  1077
hgs
parents:
diff changeset
  1078
hgs
parents:
diff changeset
  1079
hgs
parents:
diff changeset
  1080
hgs
parents:
diff changeset
  1081
hgs
parents:
diff changeset
  1082
hgs
parents:
diff changeset
  1083