Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "plat_priv.h"
22 #include <kernel/kernel.h>
26 DMutex* TheTraceMutex = NULL;
27 _LIT(KLitTraceMutexName, "FTRACE_MUTEX");
29 const TInt KMajorVersionNumber=1;
30 const TInt KMinorVersionNumber=0;
31 const TInt KBuildVersionNumber=0;
34 class DLddFactoryFTrace : public DLogicalDevice
38 virtual ~DLddFactoryFTrace();
39 virtual TInt Install();
40 virtual void GetCaps(TDes8 &aDes) const;
41 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
44 class DLddFTrace : public DLogicalChannelBase
50 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
52 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
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);
62 DECLARE_STANDARD_LDD()
64 TInt r = Kern::MutexCreate(TheTraceMutex, KLitTraceMutexName, KMutexOrdNone);
68 return new DLddFactoryFTrace;
71 DLddFactoryFTrace::DLddFactoryFTrace()
74 iParseMask=KDeviceAllowUnit; // Pass stack number as unit
75 iUnitsMask=0xffffffff;
76 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
79 TInt DLddFactoryFTrace::Create(DLogicalChannelBase*& aChannel)
81 aChannel=new DLddFTrace;
82 return aChannel ? KErrNone : KErrNoMemory;
85 TInt DLddFactoryFTrace::Install()
87 TPtrC name=_L("FTrace");
88 return(SetName(&name));
91 void DLddFactoryFTrace::GetCaps(TDes8& /*aDes*/) const
95 DLddFactoryFTrace::~DLddFactoryFTrace()
99 DLddFTrace::DLddFTrace()
103 DLddFTrace::~DLddFTrace()
107 TInt DLddFTrace::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
110 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
111 return(KErrNotSupported);
116 void DLddFTrace::DoCancel(TInt /*aReqNo*/)
120 TInt DLddFTrace::Request(TInt aReqNo, TAny* a1, TAny* a2)
122 NKern::ThreadEnterCS();
123 Kern::MutexWait(*TheTraceMutex);
124 TInt r = DoControl(aReqNo, a1, a2);
125 Kern::MutexSignal(*TheTraceMutex);
126 NKern::ThreadLeaveCS();
132 const TUint KTraceBufferSize = 4096;
133 TUint8 gTraceBuffer[KTraceBufferSize];
136 #define MIN(a,b) ((a) < (b) ? (a) : (b))
138 TInt DLddFTrace::DoControl(TInt aFunction, TAny* a1, TAny* a2)
140 // Mostly requests (but some kernel server async ones)
143 TInt r=KErrNotSupported;
146 case RFTrace::ETraceMultiple:
149 TClassification iCategory;
150 TUint8 iPadding1[sizeof(TUint) - sizeof(TClassification)];
153 TUint8 iPadding2[sizeof(TUint) - sizeof(TFormatId)];
156 TInt iDescriptorCount;
161 XTRAP(r, XT_DEFAULT, kumemget32(&args, a1, sizeof(args)));
165 // current descriptor - MUST be either a TPtr8 or a TBuf8<4>
166 TUint32 desc[2] = {0, 0};
167 TUint32& desLength = desc[0];
171 *((TUint*) (gTraceBuffer+offset)) = args.iFormatId;
172 offset+= sizeof(TUint);
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) )
179 XTRAP(r, XT_DEFAULT, kumemget32(desc, des, sizeof(desc)));
180 TUint32 desType = desLength >> KShiftDesType;
181 desLength &= (TUint) (KMaskDesLength);
182 if (desType == EPtrC)
184 *((TUint*) (gTraceBuffer+offset)) = desLength;
185 desLength = (desLength+3)&~3;
186 offset+= sizeof(TUint);
188 else if (desType == EBufC)
190 *((TUint*) (gTraceBuffer+offset)) = desc[1];
191 offset+= sizeof(TUint);
200 TUint len = MIN(KTraceBufferSize - offset, desLength);
201 XTRAP(r, XT_DEFAULT, kumemget(gTraceBuffer+offset, (const TUint8*) desc[1], len));
206 BTrace::OutFilteredBig
207 (BTRACE_HEADER_C(8,args.iCategory, 0), args.iUid, gTraceBuffer, offset);