os/kernelhwsrv/kernel/eka/debug/crashMonitor/src/scmthreaddata.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-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
// e32\debug\crashMonitor\src\scmthreaddata.cpp
sl@0
    15
// Core dump server - Thread Data for System Crash
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalTechnology
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include <scmdatatypes.h>
sl@0
    25
sl@0
    26
namespace Debug
sl@0
    27
	{
sl@0
    28
	/**
sl@0
    29
	 * TThreadData implementation
sl@0
    30
	 * @internal technology
sl@0
    31
	 */
sl@0
    32
	
sl@0
    33
	/**
sl@0
    34
	 * TThreadData constructor
sl@0
    35
	 */
sl@0
    36
	TThreadData::TThreadData()
sl@0
    37
	: iId(ESCMThreadData)
sl@0
    38
		,iVersion(EThreadData1)
sl@0
    39
		,iPriority(0)
sl@0
    40
		,iTid(0)
sl@0
    41
		,iOwnerId(0)
sl@0
    42
		,iSvcSP(0)
sl@0
    43
		,iSvcStack(0)
sl@0
    44
		,iSvcStacksize(0)
sl@0
    45
		,iUsrSP(0)
sl@0
    46
		,iUsrStack(0)
sl@0
    47
		,iUsrStacksize(0)
sl@0
    48
		,iNamesize(0)
sl@0
    49
		,iLastCpu(0)
sl@0
    50
		,iSvcHeap(0)
sl@0
    51
		,iSvcHeapSize(0)
sl@0
    52
		{			
sl@0
    53
		}
sl@0
    54
	
sl@0
    55
	/**
sl@0
    56
	 * Writes this classes data to the specified byte stream
sl@0
    57
	 * @param aWriter byte stream to use
sl@0
    58
	 * @return void
sl@0
    59
	 */	
sl@0
    60
	TInt TThreadData::Serialize(TByteStreamWriter& aWriter)
sl@0
    61
		{
sl@0
    62
		TInt startPos = aWriter.CurrentPosition();
sl@0
    63
		
sl@0
    64
		if(iId != ESCMThreadData)
sl@0
    65
			{
sl@0
    66
			CLTRACE("TThreadData::Serialize Corrupt ID");
sl@0
    67
			return KErrCorrupt;
sl@0
    68
			}
sl@0
    69
sl@0
    70
		// ID saved first 
sl@0
    71
		aWriter.WriteInt(iId);		 				    // 4		
sl@0
    72
		
sl@0
    73
		aWriter.WriteShort((TUint16) iVersion);			// 2
sl@0
    74
sl@0
    75
		if(iVersion == EThreadData1)
sl@0
    76
			{
sl@0
    77
			// write data v1 format					
sl@0
    78
			aWriter.WriteInt(iPriority); 			 	// 4
sl@0
    79
			aWriter.WriteInt64(iTid);  					// 8
sl@0
    80
			aWriter.WriteInt64(iOwnerId);				// 8
sl@0
    81
			aWriter.WriteInt(iSvcSP); 			 		// 4
sl@0
    82
			aWriter.WriteInt(iSvcStack); 			 	// 4
sl@0
    83
			aWriter.WriteInt(iSvcStacksize); 			 	// 4
sl@0
    84
			aWriter.WriteInt(iUsrSP); 			 		// 4
sl@0
    85
			aWriter.WriteInt(iUsrStack); 			 	// 4
sl@0
    86
			aWriter.WriteInt(iUsrStacksize); 			 	// 4			
sl@0
    87
			aWriter.WriteInt(iLastCpu); 			 	// 4
sl@0
    88
			aWriter.WriteInt(iSvcHeap); 			 		// 4
sl@0
    89
			aWriter.WriteInt(iSvcHeapSize); 			 	// 4
sl@0
    90
			if(iName.Ptr())
sl@0
    91
				{
sl@0
    92
				aWriter.WriteInt(iName.Length());		// 4		
sl@0
    93
				for(TInt cnt = 0; cnt < iName.Length(); cnt++)
sl@0
    94
					{
sl@0
    95
					aWriter.WriteByte(iName[cnt]);
sl@0
    96
					}
sl@0
    97
				}
sl@0
    98
			else
sl@0
    99
				{
sl@0
   100
				aWriter.WriteInt(0);
sl@0
   101
				}
sl@0
   102
			}
sl@0
   103
		else
sl@0
   104
			{
sl@0
   105
			CLTRACE("TThreadData::Serialize Unsupported version");
sl@0
   106
			return KErrCorrupt;
sl@0
   107
			}
sl@0
   108
		
sl@0
   109
		TInt endPos = aWriter.CurrentPosition();
sl@0
   110
		if( endPos - startPos != GetSize())
sl@0
   111
			{
sl@0
   112
			// error between actual size & real size in data
sl@0
   113
			CLTRACE("TThreadData::Serialize serialization size error");	
sl@0
   114
			return KErrCorrupt;
sl@0
   115
			}
sl@0
   116
		
sl@0
   117
		return KErrNone;
sl@0
   118
		}
sl@0
   119
	
sl@0
   120
	/**
sl@0
   121
	 * Reads the classes data from the specified byte stream
sl@0
   122
	 * @param aReader Byte stream to use
sl@0
   123
	 * @return void
sl@0
   124
	 */
sl@0
   125
	TInt TThreadData::Deserialize(TByteStreamReader& aReader)
sl@0
   126
		{
sl@0
   127
		TInt startPos = aReader.CurrentPosition();
sl@0
   128
		
sl@0
   129
		iId = (SCMStructId)aReader.ReadInt();					// 4
sl@0
   130
		if(iId != ESCMThreadData)
sl@0
   131
			{
sl@0
   132
			CLTRACE("TThreadData::Deserialize Corrupt ID read");
sl@0
   133
			return KErrCorrupt;
sl@0
   134
			}
sl@0
   135
		
sl@0
   136
		iVersion = (TThreadDataVersion)aReader.ReadShort();			// 2
sl@0
   137
sl@0
   138
		if(iVersion == EThreadData1)
sl@0
   139
			{
sl@0
   140
			// read data v1 format	
sl@0
   141
			iPriority = aReader.ReadInt();		 				// 4		
sl@0
   142
			iTid = aReader.ReadInt64(); 			 	    	// 8		
sl@0
   143
			iOwnerId = aReader.ReadInt64();						// 8
sl@0
   144
			iSvcSP = aReader.ReadInt();							// 4
sl@0
   145
			iSvcStack = aReader.ReadInt();						// 4
sl@0
   146
			iSvcStacksize = aReader.ReadInt();					// 4
sl@0
   147
			iUsrSP = aReader.ReadInt();							// 4
sl@0
   148
			iUsrStack = aReader.ReadInt();						// 4
sl@0
   149
			iUsrStacksize = aReader.ReadInt();					// 4
sl@0
   150
			iLastCpu = aReader.ReadInt();						// 4
sl@0
   151
			iSvcHeap = aReader.ReadInt();	 			 		// 4
sl@0
   152
			iSvcHeapSize = aReader.ReadInt();	 			 		// 4
sl@0
   153
			
sl@0
   154
			iNamesize = aReader.ReadInt();						// 4
sl@0
   155
						
sl@0
   156
			if(iName.Ptr() && iName.MaxLength() >= (TInt)iNamesize)
sl@0
   157
				{
sl@0
   158
				iName.SetLength(0);
sl@0
   159
				
sl@0
   160
				for(TUint cnt = 0; cnt < iNamesize; cnt++)
sl@0
   161
					{
sl@0
   162
					iName.Append(aReader.ReadByte());		//iNamesize bytes
sl@0
   163
					} 
sl@0
   164
				}	
sl@0
   165
			}
sl@0
   166
		else
sl@0
   167
			{
sl@0
   168
			iId = ESCMLast;	//unrecognised header
sl@0
   169
			CLTRACE("TThreadData::Deserialize Unsupported version");
sl@0
   170
			return KErrCorrupt;
sl@0
   171
			}
sl@0
   172
		
sl@0
   173
		TInt endPos = aReader.CurrentPosition();
sl@0
   174
		if( endPos - startPos != GetSize())
sl@0
   175
			{
sl@0
   176
			iId = ESCMLast;	//unrecognised header
sl@0
   177
			
sl@0
   178
			// error between actual size & real size in data
sl@0
   179
			CLTRACE("TThreadData::Deserialize serialization size error");	
sl@0
   180
			return KErrCorrupt;
sl@0
   181
			}
sl@0
   182
		return KErrNone;
sl@0
   183
		}
sl@0
   184
	
sl@0
   185
	/**
sl@0
   186
	 * Returns the externalised size of this class
sl@0
   187
	 * @return TInt size
sl@0
   188
	 */
sl@0
   189
	TInt TThreadData::GetSize() const
sl@0
   190
		{
sl@0
   191
		if(iVersion == EThreadData1)
sl@0
   192
			{
sl@0
   193
			return 66 + iName.Length();
sl@0
   194
			}
sl@0
   195
		else
sl@0
   196
			{
sl@0
   197
			CLTRACE("TThreadData::GetSize Unsupported version");			
sl@0
   198
			return KErrNotSupported;		
sl@0
   199
			}
sl@0
   200
		}
sl@0
   201
	
sl@0
   202
	}