|
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 "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 |
|
18 #include "MemSpyDriverLogChanMisc.h" |
|
19 |
|
20 // System includes |
|
21 #include <memspy/driver/memspydriverconstants.h> |
|
22 #include <memspy/driver/memspydriverconstants.h> |
|
23 #include <memspy/driver/memspydriverobjectsshared.h> |
|
24 |
|
25 // Shared includes |
|
26 #include "MemSpyDriverOpCodes.h" |
|
27 #include "MemSpyDriverObjectsInternal.h" |
|
28 |
|
29 // User includes |
|
30 #include "MemSpyDriverHeap.h" |
|
31 #include "MemSpyDriverUtils.h" |
|
32 #include "MemSpyDriverDevice.h" |
|
33 #include "MemSpyDriverOSAdaption.h" |
|
34 |
|
35 |
|
36 |
|
37 DMemSpyDriverLogChanMisc::DMemSpyDriverLogChanMisc( DMemSpyDriverDevice& aDevice, DThread& aThread ) |
|
38 : DMemSpyDriverLogChanBase( aDevice, aThread ) |
|
39 { |
|
40 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::DMemSpyDriverLogChanMisc() - START - this: 0x%08x", this )); |
|
41 |
|
42 DProcess* process = OSAdaption().DThread().GetOwningProcess( aThread ); |
|
43 if ( process ) |
|
44 { |
|
45 DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess(); |
|
46 // |
|
47 iSID = processAdaption.GetSID( *process ); |
|
48 iSecurityZone = processAdaption.GetSecurityZone( *process ); |
|
49 // |
|
50 iClientIsMemSpy = ( iSID == KMemSpyUiSID || iSID == KMemSpyConsoleUiSID ); |
|
51 } |
|
52 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::DMemSpyDriverLogChanMisc() - END - sid: 0x%08x, sz: 0x%08x, isMemSpy: %d", iSID, iSecurityZone, iClientIsMemSpy )); |
|
53 } |
|
54 |
|
55 |
|
56 DMemSpyDriverLogChanMisc::~DMemSpyDriverLogChanMisc() |
|
57 { |
|
58 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::~DMemSpyDriverLogChanMisc() - START - this: 0x%08x", this )); |
|
59 |
|
60 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::~DMemSpyDriverLogChanMisc() - END - this: 0x%08x", this )); |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 TInt DMemSpyDriverLogChanMisc::Request( TInt aFunction, TAny* a1, TAny* a2 ) |
|
66 { |
|
67 TInt r = DMemSpyDriverLogChanBase::Request( aFunction, a1, a2 ); |
|
68 if ( r == KErrNone ) |
|
69 { |
|
70 switch( aFunction ) |
|
71 { |
|
72 case EMemSpyDriverOpCodeMiscSetRHeapVTable: |
|
73 r = SetRHeapVTable( a1 ); |
|
74 break; |
|
75 case EMemSpyDriverOpCodeMiscGetMemoryModelType: |
|
76 r = GetMemoryModelType(); |
|
77 break; |
|
78 case EMemSpyDriverOpCodeMiscGetRoundToPageSize: |
|
79 r = GetRoundToPageSize( (TUint32*) a1 ); |
|
80 break; |
|
81 case EMemSpyDriverOpCodeMiscImpersonate: |
|
82 r = Impersonate( (TUint32) a1 ); |
|
83 break; |
|
84 |
|
85 default: |
|
86 r = KErrNotSupported; |
|
87 break; |
|
88 } |
|
89 } |
|
90 // |
|
91 return r; |
|
92 } |
|
93 |
|
94 |
|
95 TBool DMemSpyDriverLogChanMisc::IsHandler( TInt aFunction ) const |
|
96 { |
|
97 return ( aFunction > EMemSpyDriverOpCodeMiscBase && aFunction < EMemSpyDriverOpCodeMiscEnd ); |
|
98 } |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 TInt DMemSpyDriverLogChanMisc::SetRHeapVTable( TAny* aRHeapVTable ) |
|
107 { |
|
108 const TUint32 vTable = (TUint32) aRHeapVTable; |
|
109 MemSpyDevice().SetRHeapVTable( vTable ); |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 TInt DMemSpyDriverLogChanMisc::GetMemoryModelType() |
|
118 { |
|
119 TInt ret = EMemSpyMemoryModelTypeUnknown; |
|
120 // |
|
121 const TUint32 memModelAttrib = (TUint32) Kern::HalFunction( EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL ); |
|
122 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::GetMemoryModelType() - memModelAttrib: 0x%08x", memModelAttrib)); |
|
123 // |
|
124 if ( (memModelAttrib & EMemModelTypeMask ) == EMemModelTypeMultiple ) |
|
125 { |
|
126 ret = EMemSpyMemoryModelTypeMultiple; |
|
127 } |
|
128 else if ( (memModelAttrib & EMemModelTypeMask ) == EMemModelTypeMoving ) |
|
129 { |
|
130 ret = EMemSpyMemoryModelTypeMoving; |
|
131 } |
|
132 else if ( (memModelAttrib & EMemModelTypeMask ) == EMemModelTypeEmul ) |
|
133 { |
|
134 ret = EMemSpyMemoryModelTypeEmulator; |
|
135 } |
|
136 // |
|
137 return ret; |
|
138 } |
|
139 |
|
140 |
|
141 TInt DMemSpyDriverLogChanMisc::GetRoundToPageSize( TUint32* aValue ) |
|
142 { |
|
143 // We should probably do this user side... I think the HAL contains the page size. |
|
144 TUint32 value = 0; |
|
145 TInt r = Kern::ThreadRawRead( &ClientThread(), aValue, &value, sizeof(TUint32) ); |
|
146 // |
|
147 if ( r == KErrNone ) |
|
148 { |
|
149 value = Kern::RoundToPageSize( value ); |
|
150 r = Kern::ThreadRawWrite( &ClientThread(), aValue, &value, sizeof(TUint32) ); |
|
151 } |
|
152 // |
|
153 return r; |
|
154 } |
|
155 |
|
156 |
|
157 TInt DMemSpyDriverLogChanMisc::Impersonate( TUint32 aValue ) |
|
158 { |
|
159 DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread(); |
|
160 DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess(); |
|
161 // |
|
162 TInt r = KErrNotFound; |
|
163 // |
|
164 TUint32 sid = iSID; |
|
165 TUint32 sz = iSecurityZone; |
|
166 // |
|
167 if ( aValue != 0 ) |
|
168 { |
|
169 // Must impersonate a SID: |
|
170 NKern::ThreadEnterCS(); |
|
171 |
|
172 DObjectCon* container = Kern::Containers()[ EProcess ]; |
|
173 container->Wait(); |
|
174 NKern::LockSystem(); |
|
175 |
|
176 const TInt count = container->Count(); |
|
177 for(TInt i=0; i<count; i++) |
|
178 { |
|
179 DObject* object = (*container)[ i ]; |
|
180 if ( object != NULL ) |
|
181 { |
|
182 DProcess* proc = (DProcess*) object; |
|
183 |
|
184 const TUint32 processSID = processAdaption.GetSID( *proc ); |
|
185 if ( processSID == aValue ) |
|
186 { |
|
187 sid = processSID; |
|
188 sz = processAdaption.GetSecurityZone( *proc ); |
|
189 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::Impersonate() - MemSpy impersonates - pid: %d, sid: 0x%08x, sz: %d", proc->iId, sid, sz )); |
|
190 break; |
|
191 } |
|
192 |
|
193 } |
|
194 } |
|
195 |
|
196 NKern::UnlockSystem(); |
|
197 container->Signal(); |
|
198 |
|
199 NKern::ThreadLeaveCS(); |
|
200 } |
|
201 |
|
202 DThread& thread = ClientThread(); |
|
203 DProcess* myOwningProcess = threadAdaption.GetOwningProcess( thread ); |
|
204 // |
|
205 if ( myOwningProcess ) |
|
206 { |
|
207 if ( iClientIsMemSpy ) |
|
208 { |
|
209 processAdaption.SetSID( *myOwningProcess, sid ); |
|
210 processAdaption.SetSecurityZone( *myOwningProcess, sz); |
|
211 // |
|
212 r = KErrNone; |
|
213 } |
|
214 else |
|
215 { |
|
216 r = KErrAccessDenied; |
|
217 } |
|
218 } |
|
219 // |
|
220 TRACE( Kern::Printf("DMemSpyDriverLogChanMisc::Impersonate() - MemSpy is now: 0x%08x", sid )); |
|
221 return r; |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 |