size_t PropagateMark() { DObject *obj = Gray; assert(obj->IsGray()); obj->Gray2Black(); Gray = obj->GCNext; return !(obj->ObjectFlags & OF_EuthanizeMe) ? obj->PropagateMark() : obj->GetClass()->GetSize(); }
size_t DObject::StaticPointerSubstitution (DObject *old, DObject *notOld) { DObject *probe; size_t changed = 0; //int i; // Go through all objects. for (probe = GC::Root; probe != NULL; probe = probe->ObjNext) { changed += probe->PointerSubstitution(old, notOld); } #if 0 // Go through the bodyque. for (i = 0; i < BODYQUESIZE; ++i) { if (bodyque[i] == old) { bodyque[i] = static_cast<AActor *>(notOld); changed++; } } // Go through players. for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) changed += players[i].FixPointers (old, notOld); } // Go through sectors. if (sectors != NULL) { for (i = 0; i < numsectors; ++i) { #define SECTOR_CHECK(f,t) \ if (sectors[i].f.p == static_cast<t *>(old)) { sectors[i].f = static_cast<t *>(notOld); changed++; } SECTOR_CHECK( SoundTarget, AActor ); SECTOR_CHECK( CeilingSkyBox, ASkyViewpoint ); SECTOR_CHECK( FloorSkyBox, ASkyViewpoint ); SECTOR_CHECK( SecActTarget, ASectorAction ); SECTOR_CHECK( floordata, DSectorEffect ); SECTOR_CHECK( ceilingdata, DSectorEffect ); SECTOR_CHECK( lightingdata, DSectorEffect ); #undef SECTOR_CHECK } } // Go through bot stuff. if (bglobal.firstthing.p == (AActor *)old) bglobal.firstthing = (AActor *)notOld, ++changed; if (bglobal.body1.p == (AActor *)old) bglobal.body1 = (AActor *)notOld, ++changed; if (bglobal.body2.p == (AActor *)old) bglobal.body2 = (AActor *)notOld, ++changed; #endif return changed; }
void DObject::PointerSubstitution (DObject *old, DObject *notOld) { unsigned int i, highest; highest = Objects.Size (); for (i = 0; i <= highest; i++) { DObject *current = i < highest ? Objects[i] : NULL; // DObject *current = i < highest ? Objects[i] : &bglobal; if (current) { const PClass *info = current->GetClass(); const size_t *offsets = info->FlatPointers; if (offsets == NULL) { const_cast<PClass *>(info)->BuildFlatPointers(); offsets = info->FlatPointers; } while (*offsets != ~(size_t)0) { if (*(DObject **)((BYTE *)current + *offsets) == old) { *(DObject **)((BYTE *)current + *offsets) = notOld; } offsets++; } } } for (i = 0; i < BODYQUESIZE; ++i) { if (bodyque[i] == old) { bodyque[i] = static_cast<AActor *>(notOld); } } // This is an ugly hack, but it's the best I can do for now. for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) players[i].FixPointers (old, notOld); } if (sectors != NULL) { for (i = 0; i < (unsigned int)numsectors; ++i) { if (sectors[i].SoundTarget == old) { sectors[i].SoundTarget = static_cast<AActor *>(notOld); } } } }
QPointF RelationItem::calcEndPoint(const Uid &end, const Uid &otherEnd, int nearestIntermediatePointIndex) { QPointF otherEndPos; if (nearestIntermediatePointIndex >= 0 && nearestIntermediatePointIndex < m_relation->intermediatePoints().size()) { // otherEndPos will not be used } else { DObject *endOtherObject = m_diagramSceneModel->diagramController()->findElement<DObject>(otherEnd, m_diagramSceneModel->diagram()); QMT_CHECK(endOtherObject); otherEndPos = endOtherObject->pos(); } return calcEndPoint(end, otherEndPos, nearestIntermediatePointIndex); }
QPointF RelationItem::calcEndPoint(const Uid &end, const QPointF &otherEndPos, int nearestIntermediatePointIndex) { QGraphicsItem *endItem = m_diagramSceneModel->graphicsItem(end); QMT_CHECK(endItem); IIntersectionable *endObjectItem = dynamic_cast<IIntersectionable *>(endItem); QPointF endPos; if (endObjectItem) { DObject *endObject = m_diagramSceneModel->diagramController()->findElement<DObject>(end, m_diagramSceneModel->diagram()); QMT_CHECK(endObject); bool preferAxis = false; QPointF otherPos; if (nearestIntermediatePointIndex >= 0 && nearestIntermediatePointIndex < m_relation->intermediatePoints().size()) { otherPos = m_relation->intermediatePoints().at(nearestIntermediatePointIndex).pos(); preferAxis = true; } else { otherPos = otherEndPos; } bool ok = false; QLineF directLine(endObject->pos(), otherPos); if (preferAxis) { { QPointF axisDirection = GeometryUtilities::calcPrimaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } if (!ok) { QPointF axisDirection = GeometryUtilities::calcSecondaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } } if (!ok) { ok = endObjectItem->intersectShapeWithLine(directLine, &endPos); } if (!ok) { endPos = endItem->pos(); } } else { endPos = endItem->pos(); } return endPos; }
void DKdaChannel::CloseTempObject() { __ASSERT_DEBUG(iTempObj, Kern::Fault(KFault, __LINE__)); NKern::ThreadEnterCS(); iTempObj->Close(NULL); iTempObj = NULL; NKern::ThreadLeaveCS(); }
void Mark(DObject **obj) { DObject *lobj = *obj; if (lobj != NULL) { if (lobj->ObjectFlags & OF_EuthanizeMe) { *obj = (DObject *)NULL; } else if (lobj->IsWhite()) { lobj->White2Gray(); lobj->GCNext = Gray; Gray = lobj; } } }
// functions for backward compatibility to old visual role static DObject::VisualPrimaryRole visualRole(const DObject &object) { DObject::VisualPrimaryRole visualRole = object.visualPrimaryRole(); if (visualRole == DObject::DeprecatedPrimaryRoleDarker || visualRole == DObject::DeprecatedPrimaryRoleLighter || visualRole == DObject::DeprecatedPrimaryRoleOutline || visualRole == DObject::DeprecatedPrimaryRoleSoften) { QMT_CHECK(false); visualRole = DObject::PrimaryRoleNormal; } return visualRole; }
static void setVisualRole(DObject &object, DObject::VisualPrimaryRole visualRole) { if (visualRole == DObject::DeprecatedPrimaryRoleDarker) { object.setVisualPrimaryRole(DObject::PrimaryRoleNormal); object.setVisualSecondaryRole(DObject::SecondaryRoleDarker); } else if (visualRole == DObject::DeprecatedPrimaryRoleLighter) { object.setVisualPrimaryRole(DObject::PrimaryRoleNormal); object.setVisualSecondaryRole(DObject::SecondaryRoleLighter); } else if (visualRole == DObject::DeprecatedPrimaryRoleOutline) { object.setVisualPrimaryRole(DObject::PrimaryRoleNormal); object.setVisualSecondaryRole(DObject::SecondaryRoleOutline); } else if (visualRole == DObject::DeprecatedPrimaryRoleSoften) { object.setVisualPrimaryRole(DObject::PrimaryRoleNormal); object.setVisualSecondaryRole(DObject::SecondaryRoleSoften); } else { object.setVisualPrimaryRole(visualRole); } }
TInt DKdaChannel::OpenTempObject(TUint aId, TObjectType aType) { __ASSERT_DEBUG(aType == EProcess || aType == EThread, Kern::Fault(KFault, __LINE__)); __ASSERT_DEBUG(! iTempObj, Kern::Fault(KFault, __LINE__)); DObjectCon* pC = Kern::Containers()[aType]; NKern::ThreadEnterCS(); pC->Wait(); DObject* tempObj = (aType == EProcess) ? (DObject*)Kern::ProcessFromId(aId) : (DObject*)Kern::ThreadFromId(aId); NKern::LockSystem(); iTempObj = tempObj; TInt r = KErrNotFound; if (iTempObj) r = iTempObj->Open(); NKern::UnlockSystem(); pC->Signal(); NKern::ThreadLeaveCS(); return r; }
void DFlatAssignmentVisitor::visitDObject(const DObject *object) { visitDElement(object); DObject *target = dynamic_cast<DObject *>(_target); QMT_CHECK(target); target->setStereotypes(object->getStereotypes()); target->setName(object->getName()); target->setPos(object->getPos()); target->setRect(object->getRect()); target->setAutoSize(object->hasAutoSize()); target->setDepth(object->getDepth()); target->setVisualPrimaryRole(object->getVisualPrimaryRole()); target->setVisualSecondaryRole(object->getVisualSecondaryRole()); target->setVisualEmphasized(object->isVisualEmphasized()); target->setStereotypeDisplay(object->getStereotypeDisplay()); }
// Search for references to all objects scheduled for // destruction and NULL them. void DObject::DestroyScan () { unsigned int i, highest; int j, destroycount; DObject **destroybase; destroycount = (int)ToDestroy.Size (); if (destroycount == 0) return; destroybase = &ToDestroy[0] + destroycount; destroycount = -destroycount; highest = Objects.Size (); for (i = 0; i <= highest; i++) { DObject *current = i < highest ? Objects[i] : NULL; // DObject *current = i < highest ? Objects[i] : &bglobal; if (current) { const PClass *info = current->GetClass(); const size_t *offsets = info->FlatPointers; if (offsets == NULL) { const_cast<PClass *>(info)->BuildFlatPointers(); offsets = info->FlatPointers; } while (*offsets != ~(size_t)0) { j = destroycount; do { if (*(DObject **)((BYTE *)current + *offsets) == *(destroybase + j)) { *(DObject **)((BYTE *)current + *offsets) = NULL; } } while (++j); offsets++; } } } j = destroycount; do { for (i = 0; i < BODYQUESIZE; ++i) { if (bodyque[i] == *(destroybase + j)) { bodyque[i] = NULL; } } } while (++j); // This is an ugly hack, but it's the best I can do for now. for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) { j = destroycount; do { players[i].FixPointers (*(destroybase + j), NULL); } while (++j); } } for (i = 0; i < (unsigned int)numsectors; ++i) { j = destroycount; do { if (sectors[i].SoundTarget == *(destroybase + j)) { sectors[i].SoundTarget = NULL; } } while (++j); } }
void PClass::InitializeDefaults() { if (IsDescendantOf(RUNTIME_CLASS(AActor))) { assert(Defaults == nullptr); Defaults = (uint8_t *)M_Malloc(Size); // run the constructor on the defaults to set the vtbl pointer which is needed to run class-aware functions on them. // Temporarily setting bSerialOverride prevents linking into the thinker chains. auto s = DThinker::bSerialOverride; DThinker::bSerialOverride = true; ConstructNative(Defaults); DThinker::bSerialOverride = s; // We must unlink the defaults from the class list because it's just a static block of data to the engine. DObject *optr = (DObject*)Defaults; GC::Root = optr->ObjNext; optr->ObjNext = nullptr; optr->SetClass(this); // Copy the defaults from the parent but leave the DObject part alone because it contains important data. if (ParentClass->Defaults != nullptr) { memcpy(Defaults + sizeof(DObject), ParentClass->Defaults + sizeof(DObject), ParentClass->Size - sizeof(DObject)); if (Size > ParentClass->Size) { memset(Defaults + ParentClass->Size, 0, Size - ParentClass->Size); } } else { memset(Defaults + sizeof(DObject), 0, Size - sizeof(DObject)); } assert(MetaSize >= ParentClass->MetaSize); if (MetaSize != 0) { Meta = (uint8_t*)M_Malloc(MetaSize); // Copy the defaults from the parent but leave the DObject part alone because it contains important data. if (ParentClass->Meta != nullptr) { memcpy(Meta, ParentClass->Meta, ParentClass->MetaSize); if (MetaSize > ParentClass->MetaSize) { memset(Meta + ParentClass->MetaSize, 0, MetaSize - ParentClass->MetaSize); } } else { memset(Meta, 0, MetaSize); } if (MetaSize > 0) memcpy(Meta, ParentClass->Meta, ParentClass->MetaSize); else memset(Meta, 0, MetaSize); } } if (VMType != nullptr) // purely internal classes have no symbol table { if (bRuntimeClass) { // Copy parent values from the parent defaults. assert(ParentClass != nullptr); if (Defaults != nullptr) ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults, &PClass::SpecialInits); for (const PField *field : Fields) { if (!(field->Flags & VARF_Native) && !(field->Flags & VARF_Meta)) { field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); } } } if (Meta != nullptr) ParentClass->InitializeSpecials(Meta, ParentClass->Meta, &PClass::MetaInits); for (const PField *field : Fields) { if (!(field->Flags & VARF_Native) && (field->Flags & VARF_Meta)) { field->Type->SetDefaultValue(Meta, unsigned(field->Offset), &MetaInits); } } } }
TInt DMemSpyDriverLogChanChunks::GetChunkHandles( TMemSpyDriverInternalChunkHandleParams* aParams ) { TMemSpyDriverInternalChunkHandleParams params; TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverInternalChunkHandleParams) ); if ( r != KErrNone ) { TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkHandles() - END - params read error: %d", r)); return r; } const TInt maxCount = params.iMaxCount; TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkHandles() - START - id: %d, maxCount: %d, type: %d", params.iId, maxCount, params.iType)); DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread(); DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess(); // This variable holds the number of handles that we have already // written to the client-side. TInt currentWriteIndex = 0; if ( params.iType == EMemSpyDriverPrivateObjectTypeProcess || params.iType == EMemSpyDriverPrivateObjectTypeThread ) { if ( params.iType == EMemSpyDriverPrivateObjectTypeThread ) { r = OpenTempObject( params.iId, EThread ); if ( r == KErrNone ) { // Open the owning process instead, so that we can see which chunks are mapped // into the thread. DThread* thread = (DThread*) TempObject(); DProcess* process = threadAdaption.GetOwningProcess( *thread ); if ( process ) { const TUint parentProcessId = processAdaption.GetId( *process ); CloseTempObject(); r = OpenTempObject( parentProcessId, EProcess ); } else { CloseTempObject(); r = KErrNotFound; } } } else { r = OpenTempObject( params.iId, EProcess ); } // Handle error opening correct process if (r != KErrNone) { Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkHandles() - END - parent process not found"); return r; } DProcess* process = (DProcess*) TempObject(); NKern::ThreadEnterCS(); // Iterate through each handle in the process MemSpyObjectIx* processHandles = processAdaption.GetHandles( *process ); MemSpyObjectIx_HandleLookupLock(); const TInt processHandleCount = processHandles->Count(); MemSpyObjectIx_HandleLookupUnlock(); for( TInt processHandleIndex = 0; processHandleIndex<processHandleCount && r == KErrNone && currentWriteIndex < maxCount; processHandleIndex++ ) { // Get a handle from the process container... MemSpyObjectIx_HandleLookupLock(); if (processHandleIndex >= processHandles->Count()) break; // Count may have changed in the meantime DObject* object = (*processHandles)[ processHandleIndex ]; if (object && object->Open() != KErrNone) object = NULL; MemSpyObjectIx_HandleLookupUnlock(); if ( object ) { const TObjectType objectType = processAdaption.GetObjectType( *object ); if ( objectType == EChunk ) { DChunk* chunk = (DChunk*) object; TAny* handle = (TAny*) chunk; r = Kern::ThreadRawWrite( &ClientThread(), params.iHandles + currentWriteIndex, &handle, sizeof(TAny*) ); if ( r == KErrNone ) { ++currentWriteIndex; } } object->Close(NULL); } } // If we were asked for process-related chunks, also check the chunk container // for entries which we don't have handles to, but do refer to our process // Need a listing of all chunks in the system. Let client filter duplicates. DObjectCon* container = Kern::Containers()[ EChunk ]; container->Wait(); // const TInt count = container->Count(); for( TInt i=0; i<count && r == KErrNone && currentWriteIndex < maxCount; i++ ) { DChunk* chunk= (DChunk*) (*container)[ i ]; // const TBool isRelated = DoesChunkRelateToProcess( *chunk, TempObjectAsProcess() ); if ( isRelated ) { r = Kern::ThreadRawWrite( &ClientThread(), params.iHandles + currentWriteIndex, &chunk, sizeof(TAny*) ); if ( r == KErrNone ) { ++currentWriteIndex; } } } // container->Signal(); NKern::ThreadLeaveCS(); CloseTempObject(); } else { // Need a listing of all chunks in the system. Let client filter duplicates. DObjectCon* container = Kern::Containers()[ EChunk ]; NKern::ThreadEnterCS(); container->Wait(); // const TInt count = container->Count(); for( TInt i=0; i<count && r == KErrNone && currentWriteIndex < maxCount; i++ ) { DChunk* chunk= (DChunk*) (*container)[ i ]; // r = Kern::ThreadRawWrite( &ClientThread(), params.iHandles + currentWriteIndex, &chunk, sizeof(TAny*) ); if (r == KErrNone) { ++currentWriteIndex; } } // container->Signal(); NKern::ThreadLeaveCS(); } if ( r == KErrBadDescriptor ) { MemSpyDriverUtils::PanicThread( ClientThread(), EPanicBadDescriptor ); } else { const TInt finalWrite = Kern::ThreadRawWrite( &ClientThread(), params.iCountPtr, ¤tWriteIndex, sizeof(TInt) ); if ( r == KErrNone ) { r = finalWrite; } } TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkHandles() - END - number of handles written to client: %d, ret: %d", currentWriteIndex, r)); return r; }