Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\loader\d_ldrtst.cpp
15 // LDD for testing loader
19 #include <kernel/kern_priv.h>
22 const TInt KMajorVersionNumber=0;
23 const TInt KMinorVersionNumber=1;
24 const TInt KBuildVersionNumber=1;
27 class DLdrTestFactory : public DLogicalDevice
34 virtual TInt Install();
35 virtual void GetCaps(TDes8& aDes) const;
36 virtual TInt Create(DLogicalChannelBase*& aChannel);
39 class DLdrTest : public DLogicalChannelBase
41 // Test logical channel
47 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
48 virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
50 TInt GetCodeSegInfo(TAny* aHandle, TAny* aDest);
51 TAny* ModuleCodeSeg(TModuleHandle aModuleHandle);
52 TAny* ProcessCodeSeg(TInt aProcessHandle);
53 TAny* LibraryCodeSeg(TInt aLibraryHandle);
54 TInt GetCodeSegList(RLdrTest::SEntry* aList, TInt aMax);
55 TAny* CodeSegFromAddr(TLinAddr aAddr);
56 TModuleHandle ModuleHandleFromAddr(TLinAddr aAddr);
57 TInt ProcessSMPUnsafeCount(TInt aProcessHandle);
59 SDblQueLink* FindCodeSegQueueAnchor();
62 DECLARE_STANDARD_LDD()
64 return new DLdrTestFactory;
67 DLdrTestFactory::DLdrTestFactory()
72 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
75 TInt DLdrTestFactory::Create(DLogicalChannelBase*& aChannel)
77 // Create a new DLdrTest on this logical device
80 aChannel=new DLdrTest;
81 return aChannel?KErrNone:KErrNoMemory;
84 TInt DLdrTestFactory::Install()
86 // Install the LDD - overriding pure virtual
89 return SetName(&KLdrTestLddName);
92 void DLdrTestFactory::GetCaps(TDes8& aDes) const
94 // Get capabilities - overriding pure virtual
98 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
99 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
102 TInt DLdrTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
108 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
109 return KErrNotSupported;
113 DLdrTest::~DLdrTest()
120 TInt DLdrTest::GetCodeSegInfo(TAny* aHandle, TAny* aDest)
122 TCodeSegCreateInfo info;
123 DCodeSeg* pS=DCodeSeg::VerifyHandle(aHandle);
128 Kern::EndAccessCode();
129 kumemput32(aDest, &info, sizeof(info));
135 TAny* DLdrTest::ModuleCodeSeg(TModuleHandle aModuleHandle)
137 DCodeSeg* pS=DCodeSeg::VerifyHandle(aModuleHandle);
141 DCodeSeg::CodeSegFromEntryPoint((TLinAddr)aModuleHandle); // ignore returned DCodeSeg*
142 Kern::EndAccessCode();
147 TAny* DLdrTest::CodeSegFromAddr(TLinAddr aAddr)
150 DCodeSeg* s = Kern::CodeSegFromAddress(aAddr, Kern::CurrentThread().iOwningProcess);
151 Kern::EndAccessCode();
155 TModuleHandle DLdrTest::ModuleHandleFromAddr(TLinAddr aAddr)
157 TModuleHandle h = (TModuleHandle)CodeSegFromAddr(aAddr);
159 h = (TModuleHandle)aAddr;
163 TAny* DLdrTest::ProcessCodeSeg(TInt aProcessHandle)
166 DThread& t=Kern::CurrentThread();
168 DProcess* pP=(DProcess*)t.ObjectFromHandle(aProcessHandle, EProcess);
175 NKern::UnlockSystem();
179 TAny* DLdrTest::LibraryCodeSeg(TInt aLibraryHandle)
182 DThread& t=Kern::CurrentThread();
184 DLibrary* pL=(DLibrary*)t.ObjectFromHandle(aLibraryHandle, ELibrary);
187 NKern::UnlockSystem();
191 SDblQueLink* DLdrTest::FindCodeSegQueueAnchor()
193 SDblQueLink* p=&iDevice->iCodeSeg->iLink; // this device driver's code segment
197 DCodeSeg* s=_LOFF(p, DCodeSeg, iLink);
198 if (s->iExeCodeSeg==s && (s->iAttr & ECodeSegAttKernel))
200 // s is the kernel's code segment, which is the first one to be created
201 return s->iLink.iPrev;
206 TInt DLdrTest::GetCodeSegList(RLdrTest::SEntry* aList, TInt aMax)
210 RLdrTest::SEntry list[128];
212 SDblQueLink* anchor=FindCodeSegQueueAnchor();
213 SDblQueLink* p=anchor->iNext;
217 for(; p!=anchor && n<aMax; p=p->iNext, ++n)
219 DCodeSeg* s=_LOFF(p, DCodeSeg, iLink);
221 list[n].iUid3=(TUint32)s->iUids.iUid[2].iUid;
223 Kern::EndAccessCode();
225 kumemput32(aList, list, n*sizeof(RLdrTest::SEntry));
229 TInt DLdrTest::ProcessSMPUnsafeCount(TInt aProcessHandle)
231 TInt count=KErrNotFound;
232 DThread& t=Kern::CurrentThread();
234 DProcess* pP=(DProcess*)t.ObjectFromHandle(aProcessHandle, EProcess);
236 count=pP->iSMPUnsafeCount;
237 NKern::UnlockSystem();
241 TInt DLdrTest::Request(TInt aFunction, TAny* a1, TAny* a2)
246 case RLdrTest::EControlGetCodeSegInfo:
247 r=GetCodeSegInfo(a1,a2);
249 case RLdrTest::EControlProcessCodeSeg:
250 r=(TInt)ProcessCodeSeg((TInt)a1);
252 case RLdrTest::EControlLibraryCodeSeg:
253 r=(TInt)LibraryCodeSeg((TInt)a1);
255 case RLdrTest::EControlModuleCodeSeg:
256 r=(TInt)ModuleCodeSeg((TModuleHandle)a1);
258 case RLdrTest::EControlGetCodeSegList:
259 r=GetCodeSegList( (RLdrTest::SEntry*)a1, (TInt)a2 );
261 case RLdrTest::EControlCodeSegFromAddr:
262 r=(TInt)CodeSegFromAddr((TLinAddr)a1);
264 case RLdrTest::EControlModuleHandleFromAddr:
265 r=(TInt)ModuleHandleFromAddr((TLinAddr)a1);
267 case RLdrTest::EControlProcessSMPUnsafeCount:
268 r=ProcessSMPUnsafeCount((TInt)a1);