os/kernelhwsrv/userlibandfileserver/fileserver/ftrace/d_ftrace.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 // D_FTRACE.CPP
    18 //
    19 //
    20 //
    21 #include "plat_priv.h"
    22 #include <kernel/kernel.h>
    23 
    24 #include "f32trace.h"
    25 
    26 DMutex* TheTraceMutex = NULL;
    27 _LIT(KLitTraceMutexName, "FTRACE_MUTEX");
    28 
    29 const TInt KMajorVersionNumber=1;
    30 const TInt KMinorVersionNumber=0;
    31 const TInt KBuildVersionNumber=0;
    32 
    33 
    34 class DLddFactoryFTrace : public DLogicalDevice
    35 	{
    36 public:
    37 	DLddFactoryFTrace();
    38 	virtual ~DLddFactoryFTrace();
    39 	virtual TInt Install();
    40 	virtual void GetCaps(TDes8 &aDes) const;
    41 	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
    42 	};
    43 
    44 class DLddFTrace : public DLogicalChannelBase
    45 	{
    46 public:
    47 	DLddFTrace();
    48 	~DLddFTrace();
    49 protected:
    50 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    51 
    52 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
    53 
    54 private:
    55 	void DoCancel(TInt aReqNo);
    56 	TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
    57 	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
    58 
    59 private:
    60     };
    61 
    62 DECLARE_STANDARD_LDD()
    63 	{
    64 	TInt r = Kern::MutexCreate(TheTraceMutex,  KLitTraceMutexName, KMutexOrdNone);
    65 	if (r != KErrNone)
    66 		return NULL;
    67 
    68 	return new DLddFactoryFTrace;
    69 	}
    70 
    71 DLddFactoryFTrace::DLddFactoryFTrace()
    72 	{
    73 
    74     iParseMask=KDeviceAllowUnit;  // Pass stack number as unit
    75 	iUnitsMask=0xffffffff;
    76 	iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
    77 	}
    78 
    79 TInt DLddFactoryFTrace::Create(DLogicalChannelBase*& aChannel)
    80 	{
    81 	aChannel=new DLddFTrace;
    82 	return aChannel ? KErrNone : KErrNoMemory;
    83 	}
    84 
    85 TInt DLddFactoryFTrace::Install()
    86 	{
    87     TPtrC name=_L("FTrace");
    88 	return(SetName(&name));
    89 	}
    90 
    91 void DLddFactoryFTrace::GetCaps(TDes8& /*aDes*/) const
    92 	{
    93 	}
    94 
    95 DLddFactoryFTrace::~DLddFactoryFTrace()
    96 	{
    97 	}
    98 
    99 DLddFTrace::DLddFTrace()
   100 	{
   101     }
   102 
   103 DLddFTrace::~DLddFTrace()
   104 	{
   105     }
   106 
   107 TInt DLddFTrace::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
   108 	{
   109 
   110 	if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
   111 		return(KErrNotSupported);
   112 
   113     return(KErrNone);
   114 	}
   115 
   116 void DLddFTrace::DoCancel(TInt /*aReqNo*/)
   117 	{
   118 	}
   119 
   120 TInt DLddFTrace::Request(TInt aReqNo, TAny* a1, TAny* a2)
   121 	{
   122 	NKern::ThreadEnterCS();
   123 	Kern::MutexWait(*TheTraceMutex);
   124 	TInt r = DoControl(aReqNo, a1, a2);
   125 	Kern::MutexSignal(*TheTraceMutex);
   126 	NKern::ThreadLeaveCS();
   127 
   128 	return r;
   129 	}
   130 
   131 
   132 const TUint KTraceBufferSize = 4096;
   133 TUint8 gTraceBuffer[KTraceBufferSize];
   134 
   135 
   136 #define MIN(a,b)			((a) < (b) ? (a) : (b))
   137 
   138 TInt DLddFTrace::DoControl(TInt aFunction, TAny* a1, TAny* a2)
   139 //
   140 // Mostly requests (but some kernel server async ones)
   141 //
   142 	{
   143 	TInt r=KErrNotSupported;
   144 	switch (aFunction)
   145 		{
   146         case RFTrace::ETraceMultiple:
   147             {
   148 			typedef struct {
   149 				TClassification iCategory;
   150 				TUint8 iPadding1[sizeof(TUint) - sizeof(TClassification)];
   151 
   152 				TFormatId iFormatId;
   153 				TUint8 iPadding2[sizeof(TUint) - sizeof(TFormatId)];
   154 
   155 				TUint32 iUid;
   156 				TInt iDescriptorCount;
   157 				} TraceArgs;
   158 
   159 			TraceArgs args={0};
   160 
   161 			XTRAP(r, XT_DEFAULT, kumemget32(&args, a1, sizeof(args)));
   162 			if (r != KErrNone)
   163 				return r;
   164 
   165 			// current descriptor - MUST be either a TPtr8 or a TBuf8<4>
   166 			TUint32 desc[2] = {0, 0};
   167 			TUint32& desLength = desc[0];
   168 
   169 			TUint offset = 0;
   170 
   171 			*((TUint*) (gTraceBuffer+offset)) = args.iFormatId;
   172 			offset+= sizeof(TUint);
   173 
   174 			TDesC8* des = (TDesC8*) ((TUint8*) a2);
   175 			const TInt desSize = sizeof(TPtrC8);
   176 			for (TInt n=0; n< args.iDescriptorCount; n++, des = (TDesC8*) (((TUint8*) des) + desSize) )
   177 				{
   178 
   179 				XTRAP(r, XT_DEFAULT, kumemget32(desc, des, sizeof(desc)));
   180 				TUint32 desType = desLength >> KShiftDesType;
   181 				desLength &= (TUint) (KMaskDesLength);
   182 				if (desType == EPtrC)
   183 					{
   184 					*((TUint*) (gTraceBuffer+offset)) = desLength;
   185 					desLength = (desLength+3)&~3;
   186 					offset+= sizeof(TUint);
   187 					}
   188 				else if (desType == EBufC)
   189 					{
   190 					*((TUint*) (gTraceBuffer+offset)) = desc[1];
   191 					offset+= sizeof(TUint);
   192 					if (desLength > 4)
   193 						return KErrArgument;
   194 					desLength = 0;
   195 					continue;
   196 					}
   197 				else
   198 					return KErrArgument;
   199 
   200 				TUint len = MIN(KTraceBufferSize - offset, desLength);
   201 				XTRAP(r, XT_DEFAULT, kumemget(gTraceBuffer+offset, (const TUint8*) desc[1], len));
   202 				offset+= len;
   203 
   204 				}
   205 
   206 			BTrace::OutFilteredBig
   207 				(BTRACE_HEADER_C(8,args.iCategory, 0), args.iUid, gTraceBuffer, offset);
   208 
   209 			r=KErrNone;
   210 			break;
   211             }
   212 		}
   213 	return(r);
   214 	}
   215