117 TInt GetObjectInfoByName(TObjectType aObjectType, const TDesC8& aObjectName, TDes8* aKernelInfoBuf); |
121 TInt GetObjectInfoByName(TObjectType aObjectType, const TDesC8& aObjectName, TDes8* aKernelInfoBuf); |
118 TInt GetObjectInfoByHandle(TObjectType aObjectType, TInt aThreadId, TInt aObjectHandle, TDes8* aKernelInfoBuf); |
122 TInt GetObjectInfoByHandle(TObjectType aObjectType, TInt aThreadId, TInt aObjectHandle, TDes8* aKernelInfoBuf); |
119 TInt GetObjectAddresses(TObjectType aObjectType, const TDesC8& aOwningProcess, TDes8* aKernelInfoBuf); |
123 TInt GetObjectAddresses(TObjectType aObjectType, const TDesC8& aOwningProcess, TDes8* aKernelInfoBuf); |
120 TInt GetChunkAddresses(TUint aControllingProcessId, TDes8* aKernelInfoBuf); |
124 TInt GetChunkAddresses(TUint aControllingProcessId, TDes8* aKernelInfoBuf); |
121 TInt AcquireCodeSegMutex(); |
125 TInt AcquireCodeSegMutex(); |
|
126 TInt AcquireCodeSegMutexAndFilterCodesegsForProcess(TUint aProcessId); |
122 TInt ReleaseCodeSegMutex(); |
127 TInt ReleaseCodeSegMutex(); |
123 TInt GetNextCodeSegInfo(TDes8* aCodeSegInfoBuf); |
128 TInt GetNextCodeSegInfo(TDes8* aCodeSegInfoBuf); |
124 TInt ObjectDie(TObjectKillParamsBuf& aObjectKillParamsBuf); |
129 TInt ObjectDie(TObjectKillParamsBuf& aObjectKillParamsBuf); |
125 TInt FindPtrInCodeSegments(TAny* aDllNamePtr, TAny* aPtr); |
130 TInt FindPtrInCodeSegments(TAny* aDllNamePtr, TAny* aPtr); |
126 TInt GetHandleOwners(TAny* aObj, TAny* aOwnersBuf); |
131 TInt GetHandleOwners(TAny* aObj, TAny* aOwnersBuf); |
171 void BreakpointHit(TDes& aPkg); |
176 void BreakpointHit(TDes& aPkg); |
172 |
177 |
173 private: |
178 private: |
174 DThread* iClient; |
179 DThread* iClient; |
175 TBool iLocks[ENumObjectTypes]; |
180 TBool iLocks[ENumObjectTypes]; |
176 TBool iCodeSegLock; |
181 enum TCodesegLogStatus |
177 DCodeSeg* iCurrentCodeSeg; |
182 { |
|
183 ENotHeld, |
|
184 EHeld, |
|
185 EHeldAndTraversing, |
|
186 } iCodeSegLock; |
|
187 SDblQueLink* iCurrentCodeSegLink; |
178 DThreadChangeHandler* iEventHandler; |
188 DThreadChangeHandler* iEventHandler; |
179 DPropertyAccess* iPropertyAccess; |
189 DPropertyAccess* iPropertyAccess; |
180 TAny* iClientBreakpointNotifyPkg; |
190 TAny* iClientBreakpointNotifyPkg; |
181 TRequestStatus* iClientBreakpointNotifyStatus; |
191 TRequestStatus* iClientBreakpointNotifyStatus; |
|
192 |
|
193 SDblQue iFilteredCodesegQue; |
182 }; |
194 }; |
183 |
195 |
184 |
196 |
185 NONSHARABLE_CLASS(DThreadChangeHandler) : public DKernelEventHandler |
197 NONSHARABLE_CLASS(DThreadChangeHandler) : public DKernelEventHandler |
186 { |
198 { |
1199 if (!err) |
1213 if (!err) |
1200 { |
1214 { |
1201 if (codeSegLock) |
1215 if (codeSegLock) |
1202 { |
1216 { |
1203 Kern::MutexWait(*codeSegLock); |
1217 Kern::MutexWait(*codeSegLock); |
1204 iCodeSegLock = ETrue; |
1218 iCodeSegLock = EHeld; |
1205 } |
1219 } |
1206 else |
1220 else |
1207 { |
1221 { |
1208 err = KErrNotFound; |
1222 err = KErrNotFound; |
1209 } |
1223 } |
1210 } |
1224 } |
1211 // Kern::Printf("[DMemoryAccess] ::AcquireCodeSegMutex returning %d", err); |
1225 // Kern::Printf("[DMemoryAccess] ::AcquireCodeSegMutex returning %d", err); |
1212 return err; |
1226 return err; |
|
1227 } |
|
1228 |
|
1229 TInt DMemoryAccess::AcquireCodeSegMutexAndFilterCodesegsForProcess(TUint aProcessId) |
|
1230 { |
|
1231 TInt err = KErrNone; |
|
1232 NKern::ThreadEnterCS(); |
|
1233 Kern::Containers()[EProcess]->Wait(); |
|
1234 DProcess* process = Kern::ProcessFromId(aProcessId); |
|
1235 if (process == NULL || process->Open() != KErrNone) |
|
1236 { |
|
1237 err = KErrNotFound; |
|
1238 } |
|
1239 Kern::Containers()[EProcess]->Signal(); |
|
1240 |
|
1241 if (!err) |
|
1242 { |
|
1243 err = AcquireCodeSegMutex(); |
|
1244 } |
|
1245 if (!err) |
|
1246 { |
|
1247 iCodeSegLock = EHeldAndTraversing; |
|
1248 TInt numTraversed = process->TraverseCodeSegs(&iFilteredCodesegQue, NULL, DCodeSeg::EMarkDebug, DProcess::ETraverseFlagAdd); |
|
1249 err = numTraversed; |
|
1250 } |
|
1251 |
|
1252 if (process) process->Close(NULL); |
|
1253 NKern::ThreadLeaveCS(); |
|
1254 return err; |
1213 } |
1255 } |
1214 |
1256 |
1215 TInt DMemoryAccess::GetObjectAddresses(TObjectType aObjectType, const TDesC8& aOwningProcess, TDes8* aKernelInfoBuf) |
1257 TInt DMemoryAccess::GetObjectAddresses(TObjectType aObjectType, const TDesC8& aOwningProcess, TDes8* aKernelInfoBuf) |
1216 { |
1258 { |
1217 DObjectCon* const * cons = Kern::Containers(); |
1259 DObjectCon* const * cons = Kern::Containers(); |
1323 // DMemoryAccess::ReleaseCodeSegMutex |
1365 // DMemoryAccess::ReleaseCodeSegMutex |
1324 // Releases the code segment mutex |
1366 // Releases the code segment mutex |
1325 TInt DMemoryAccess::ReleaseCodeSegMutex() |
1367 TInt DMemoryAccess::ReleaseCodeSegMutex() |
1326 { |
1368 { |
1327 // Kern::Printf("[DMemoryAccess] ::ReleaseCodeSegMutex"); |
1369 // Kern::Printf("[DMemoryAccess] ::ReleaseCodeSegMutex"); |
1328 TInt err=KErrNone; |
1370 if (iCodeSegLock == ENotHeld) |
1329 |
1371 { |
1330 if (!iCodeSegLock) |
1372 return KErrNotReady; |
1331 { //Check the lock on code segs is not currently held |
1373 } |
1332 Kern::ThreadKill(iClient, EExitPanic, EMemAccessMutexNotHeld, KMemAccessPanicCategory); |
1374 |
1333 err = KErrAbort; |
1375 if (iCodeSegLock == EHeldAndTraversing) |
1334 } |
1376 { |
1335 |
1377 DCodeSeg::EmptyQueue(iFilteredCodesegQue, DCodeSeg::EMarkDebug); |
1336 DMutex* const codeSegLock = Kern::CodeSegLock(); |
1378 } |
1337 |
1379 |
1338 if (!err) |
1380 Kern::MutexSignal(*Kern::CodeSegLock()); |
1339 { |
1381 iCodeSegLock = ENotHeld; |
1340 if (codeSegLock) |
|
1341 { |
|
1342 Kern::MutexSignal(*codeSegLock); |
|
1343 iCodeSegLock = EFalse; |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 err = KErrNotFound; |
|
1348 } |
|
1349 } |
|
1350 // Kern::Printf("[DMemoryAccess] ::ReleaseCodeSegMutex returning %d", err); |
1382 // Kern::Printf("[DMemoryAccess] ::ReleaseCodeSegMutex returning %d", err); |
1351 return err; |
1383 return KErrNone; |
1352 } |
1384 } |
1353 |
1385 |
1354 |
1386 |
1355 TInt DMemoryAccess::GetNextCodeSegInfo(TDes8* aCodeSegInfoBuf) |
1387 TInt DMemoryAccess::GetNextCodeSegInfo(TDes8* aCodeSegInfoBuf) |
1356 { |
1388 { |
1357 // Kern::Printf("[DMemoryAccess] ::GetNextCodeSegInfo"); |
1389 // Kern::Printf("[DMemoryAccess] ::GetNextCodeSegInfo"); |
1358 TInt err = KErrNone; |
1390 TInt err = KErrNone; |
1359 |
1391 |
1360 SDblQue* p = Kern::CodeSegList(); |
1392 SDblQue* p; |
|
1393 if (iCodeSegLock == EHeldAndTraversing) |
|
1394 { |
|
1395 p = &iFilteredCodesegQue; |
|
1396 } |
|
1397 else |
|
1398 { |
|
1399 p = Kern::CodeSegList(); |
|
1400 } |
1361 SDblQueLink* anchor=&p->iA; |
1401 SDblQueLink* anchor=&p->iA; |
1362 |
1402 |
1363 if (!iCurrentCodeSeg) |
1403 if (!iCurrentCodeSegLink) |
1364 { |
1404 { |
1365 iCurrentCodeSeg = _LOFF(anchor->iNext, DCodeSeg, iLink); |
1405 iCurrentCodeSegLink = anchor; |
1366 } |
1406 } |
1367 |
1407 |
1368 if (iCurrentCodeSeg->iLink.iNext != anchor) |
1408 if (iCurrentCodeSegLink->iNext != anchor) |
1369 { |
1409 { |
1370 iCurrentCodeSeg = _LOFF(iCurrentCodeSeg->iLink.iNext, DCodeSeg, iLink); |
1410 iCurrentCodeSegLink = iCurrentCodeSegLink->iNext; |
1371 } |
1411 } |
1372 else |
1412 else |
1373 { |
1413 { |
1374 iCurrentCodeSeg = NULL; |
1414 iCurrentCodeSegLink = NULL; |
1375 err = KErrNotFound; |
1415 err = KErrNotFound; |
1376 } |
1416 } |
1377 |
1417 |
1378 if (!err) |
1418 if (!err) |
1379 { |
1419 { |
1380 //TCodeSegKernelInfoBuf* localInfoBuf = new TCodeSegKernelInfoBuf; |
1420 //TCodeSegKernelInfoBuf* localInfoBuf = new TCodeSegKernelInfoBuf; |
1381 TPckgBuf<TTomsciCodeSegKernelInfo>* localInfoBuf = new TPckgBuf<TTomsciCodeSegKernelInfo>; |
1421 DCodeSeg* currentCodeseg = (iCodeSegLock == EHeldAndTraversing) ? _LOFF(iCurrentCodeSegLink, DCodeSeg, iTempLink) : _LOFF(iCurrentCodeSegLink, DCodeSeg, iLink); |
|
1422 TPckgBuf<TCodeSegKernelInfo>* localInfoBuf = new TPckgBuf<TCodeSegKernelInfo>; |
1382 if (!localInfoBuf) |
1423 if (!localInfoBuf) |
1383 { |
1424 { |
1384 err = KErrNoMemory; |
1425 err = KErrNoMemory; |
1385 } |
1426 } |
1386 else |
1427 else |
1387 { |
1428 { |
1388 //Get the code seg info |
1429 //Get the code seg info |
1389 (*localInfoBuf)().iRunAddress = iCurrentCodeSeg->iRunAddress; |
1430 (*localInfoBuf)().iRunAddress = currentCodeseg->iRunAddress; |
1390 (*localInfoBuf)().iSize = iCurrentCodeSeg->iSize; |
1431 (*localInfoBuf)().iSize = currentCodeseg->iSize; |
1391 (*localInfoBuf)().iFileName = iCurrentCodeSeg->iFileName->Right((*localInfoBuf)().iFileName.MaxLength()); |
1432 if (currentCodeseg->iFileName) |
1392 (*localInfoBuf)().iAccessCount = iCurrentCodeSeg->iAccessCount; |
1433 { |
1393 (*localInfoBuf)().iAddressOfKernelObject = (TUint8*)iCurrentCodeSeg; |
1434 (*localInfoBuf)().iFileName = currentCodeseg->iFileName->Right((*localInfoBuf)().iFileName.MaxLength()); |
1394 (*localInfoBuf)().iName = iCurrentCodeSeg->iRootName; |
1435 } |
1395 (*localInfoBuf)().iDepCount = iCurrentCodeSeg->iDepCount; |
1436 (*localInfoBuf)().iAccessCount = currentCodeseg->iAccessCount; |
1396 |
1437 (*localInfoBuf)().iAddressOfKernelObject = (TUint8*)currentCodeseg; |
|
1438 (*localInfoBuf)().iName = currentCodeseg->iRootName; |
|
1439 (*localInfoBuf)().iDepCount = currentCodeseg->iDepCount; |
|
1440 #ifdef __EPOC32__ |
|
1441 (*localInfoBuf)().iXip = ((DEpocCodeSeg*)currentCodeseg)->iXIP; |
|
1442 #else |
|
1443 (*localInfoBuf)().iXip = EFalse; |
|
1444 #endif |
1397 //Copy the local info buffer into the client's address space |
1445 //Copy the local info buffer into the client's address space |
1398 err = Kern::ThreadDesWrite(iClient, aCodeSegInfoBuf, *localInfoBuf, 0, KTruncateToMaxLength, NULL); |
1446 err = Kern::ThreadDesWrite(iClient, aCodeSegInfoBuf, *localInfoBuf, 0, KTruncateToMaxLength, NULL); |
1399 delete localInfoBuf; |
1447 delete localInfoBuf; |
1400 } |
1448 } |
1401 } |
1449 } |