void ScanAddress::ScanAddressesInRegion(PolyWord *region, PolyWord *end) { PolyWord *pt = region; while (pt < end) { pt++; // Skip length word. // pt actually points AT the object here. PolyObject *obj = (PolyObject*)pt; if (obj->ContainsForwardingPtr()) /* skip over moved object */ { // We can now get multiple forwarding pointers as a result // of applying ShareData repeatedly. Perhaps we should // turn the forwarding pointers back into normal words in // an extra pass. while (obj->ContainsForwardingPtr()) obj = obj->GetForwardingPtr(); ASSERT(obj->ContainsNormalLengthWord()); CheckObject(obj); pt += obj->Length(); } else { ASSERT(obj->ContainsNormalLengthWord()); POLYUNSIGNED length = obj->Length(); if (pt+length > end) Crash("Malformed object at %p - length %lu\n", pt, length); if (length != 0) ScanAddressesInObject(obj); pt += length; } } }
void MemoryManager::CheckObject(long* mem, bool is_obj, long depth) { if(mem) { StackClass* cls; if(is_obj) { cls = GetClass(mem); } else { cls = GetClassMapping(mem); } if(cls) { #ifdef _DEBUG for(int i = 0; i < depth; i++) { wcout << L"\t"; } wcout << L"\t----- object: addr=" << mem << L"(" << (long)mem << L"), num=" << cls->GetNumberInstanceDeclarations() << L" -----" << endl; #endif // mark data if(MarkMemory(mem)) { CheckMemory(mem, cls->GetInstanceDeclarations(), cls->GetNumberInstanceDeclarations(), depth); } } else { // NOTE: this happens when we are trying to mark unidentified memory // segments. these segments may be parts of that stack or temp for // register variables #ifdef _DEBUG for(int i = 0; i < depth; i++) { wcout << L"\t"; } wcout <<"$: addr/value=" << mem << endl; if(is_obj) { assert(cls); } #endif // primitive or object array if(MarkValidMemory(mem)) { // ensure we're only checking int and obj arrays if(std::binary_search(allocated_memory.begin(), allocated_memory.end(), mem) && (mem[TYPE] == NIL_TYPE || mem[TYPE] == INT_TYPE)) { long* array = mem; const long size = array[0]; const long dim = array[1]; long* objects = (long*)(array + 2 + dim); for(long k = 0; k < size; k++) { CheckObject((long*)objects[k], false, 2); } } } } } }
// The initial entry to process the roots. These may be RTS addresses or addresses in // a thread stack. Also called recursively to process the addresses of constants in // code segments. This is used in situations where a scanner may return the // updated address of an object. PolyObject *MTGCProcessMarkPointers::ScanObjectAddress(PolyObject *obj) { PolyWord val = obj; LocalMemSpace *space = gMem.LocalSpaceForAddress(val.AsAddress()); if (space == 0) return obj; // Ignore it if it points to a permanent area // We may have a forwarding pointer if this has been moved by the // minor GC. if (obj->ContainsForwardingPtr()) { obj = FollowForwarding(obj); val = obj; space = gMem.LocalSpaceForAddress(val.AsAddress()); } ASSERT(obj->ContainsNormalLengthWord()); POLYUNSIGNED L = obj->LengthWord(); if (L & _OBJ_GC_MARK) return obj; // Already marked obj->SetLengthWord(L | _OBJ_GC_MARK); // Mark it if (profileMode == kProfileLiveData || (profileMode == kProfileLiveMutables && obj->IsMutable())) AddObjectProfile(obj); POLYUNSIGNED n = OBJ_OBJECT_LENGTH(L); if (debugOptions & DEBUG_GC_DETAIL) Log("GC: Mark: %p %" POLYUFMT " %u\n", obj, n, GetTypeBits(L)); if (OBJ_IS_BYTE_OBJECT(L)) return obj; // If we already have something on the stack we must being called // recursively to process a constant in a code segment. Just push // it on the stack and let the caller deal with it. if (msp != 0) PushToStack(obj); // Can't check this because it may have forwarding ptrs. else { MTGCProcessMarkPointers::ScanAddressesInObject(obj, L); // We can only check after we've processed it because if we // have addresses left over from an incomplete partial GC they // may need to forwarded. CheckObject (obj); } return obj; }
uintptr_t WINAPI MemoryManager::CheckStack(void* arg) { CollectionInfo* info = (CollectionInfo*)arg; #ifdef _DEBUG wcout << L"----- Marking Stack: stack: pos=" << info->stack_pos << L"; thread=" << GetCurrentThread() << L" -----" << endl; #endif while(info->stack_pos > -1) { CheckObject((long*)info->op_stack[info->stack_pos--], false, 1); } delete info; info = NULL; return 0; }
PUBLIC WORD Refine(Object *object, AccMask mask) { word rc = Err_Null; MCB *mcb ; IOCReply2 *rep; Port reply; #ifdef SYSDEB SysDebug(ioc)("Refine(%O,%A)",object,mask); #endif if( (rc = CheckObject(object,C_Locate)) != Err_Null ) return rc; reply = object->Reply; mcb = NewMsgBuf(0); InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP+FG_Refine|object->FnMod); MarshalCommon(mcb,object,NULL); MarshalWord(mcb,mask); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done; rep = (IOCReply2 *)mcb->Control; object->Access = rep->Cap; /* copy new capability in */ rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("Refine: %E",rc); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Refine: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); object->Result2 = rc; return rc; }
PUBLIC WORD SetDate( Object * object, STRING name, DateSet * dates ) { word rc = Err_Null; MCB *mcb ; Port reply; #ifdef SYSDEB SysDebug(ioc)("SetDate(%O,%N)",object,name); #endif if( (rc = CheckObject(object,C_Locate)) != Err_Null ) return rc; reply = object->Reply; mcb = NewMsgBuf(0); InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP+FG_SetDate|object->FnMod); MarshalCommon(mcb,object,name); MarshalDate(mcb,dates->Creation); MarshalDate(mcb,dates->Access); MarshalDate(mcb,dates->Modified); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done; rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("SetDate: %E",rc); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("SetDate: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); object->Result2 = rc; return rc; }
PUBLIC WORD ObjectInfo( Object * object, STRING name, byte * info ) { word rc = Err_Null; MCB *mcb ; Port reply; #ifdef SYSDEB SysDebug(ioc)("ObjectInfo(%O,%N,%P)",object,name,info); #endif if( (rc = CheckObject(object,C_Locate)) != Err_Null ) return rc; reply = object->Reply; mcb = NewMsgBuf(0); InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP+FG_ObjectInfo|object->FnMod); MarshalCommon(mcb,object,name); if( (rc = IOCMsg(mcb,info)) < Err_Null ) goto Done; rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("ObjectInfo: %E infosize %d",rc,mcb->MsgHdr.DataSize); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("ObjectInfo: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); object->Result2 = rc; return rc; }
PUBLIC WORD Link( Object * object, string name, Object * to ) { word rc = Err_Null; MCB *mcb ; Port reply; #ifdef SYSDEB SysDebug(ioc)("Link(%O,%N,%O)",object,name,to); #endif if( (rc = CheckObject(object,C_Locate)) != Err_Null ) return rc; reply = object->Reply; mcb = NewMsgBuf(0); InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP+FG_Link|object->FnMod); MarshalCommon(mcb,object,name); MarshalString(mcb,to->Name); MarshalCap(mcb,&to->Access); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done; rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("Link: %E",rc); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Link: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); object->Result2 = rc; return rc; }
PUBLIC WORD Protect( Object * object, STRING name, Matrix matrix ) { word rc = Err_Null; MCB *mcb ; Port reply; #ifdef SYSDEB SysDebug(ioc)("Protect(%O,%N,%X)",object,name,matrix); #endif if( (rc = CheckObject(object,C_Locate)) != Err_Null ) return rc; reply = object->Reply; mcb = NewMsgBuf(0); InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP+FG_Protect|object->FnMod); MarshalCommon(mcb,object,name); MarshalWord(mcb,matrix); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done; rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("Protect: %E",rc); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Protect: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); object->Result2 = rc; return rc; }
// попытаться родить перса bool ArtInt::TrySpawn(NumXY<float> showPoint, UINT persType) { // ограничение количества if (boars->GetAmount() + devils->GetAmount() > 10) return false; // инициализация переменных float angle = MathHelper::RandF(-XM_PI, XM_PI); float radius = Const::showRadius; NumXY<float> spawnPoint; NumXY<int> regAdr; do { // определить точку появления spawnPoint = showPoint + MathHelper::GetDisplacementFromDirection(angle, radius); regAdr = MathHelper::GetDynamicRegionAdress(spawnPoint); if (regAdr.x == -1) break; if (Mediator::regionField[regAdr.x][regAdr.y]) break; radius -= 1.0f; } while (true); // проверка на столкновение с окружающей средой NumXY<int> contAdr = MathHelper::GetContentAdress(spawnPoint); if (Mediator::regionField[regAdr.x][regAdr.y]->getContent()[contAdr.x][contAdr.y].blocked) return false; // провека на столкновение с другим персом BoundingBox potBox(NumXY<float>(spawnPoint.x, spawnPoint.y), PERS_RADIUS); if (CheckObject(potBox, false)) return false; // родить перса if (persType) { BR(boars->Spawn(spawnPoint)); } else { BR(devils->Spawn(spawnPoint)); } return true; }
static VOID TestDuplicate( _In_ HANDLE Handle) { NTSTATUS Status; HANDLE NewHandle; struct { ACCESS_MASK DesiredAccess; ULONG RequestedAttributes; ULONG Options; ACCESS_MASK GrantedAccess; ULONG ExpectedAttributes; } Tests[] = { { DIRECTORY_ALL_ACCESS, 0, 0, DIRECTORY_ALL_ACCESS, 0 }, { DIRECTORY_ALL_ACCESS, OBJ_KERNEL_HANDLE, 0, DIRECTORY_ALL_ACCESS, 0 }, { DIRECTORY_QUERY, 0, 0, DIRECTORY_QUERY, 0 }, { DIRECTORY_QUERY, OBJ_INHERIT, 0, DIRECTORY_QUERY, OBJ_INHERIT }, { DIRECTORY_QUERY, OBJ_INHERIT, DUPLICATE_SAME_ACCESS, DIRECTORY_ALL_ACCESS, OBJ_INHERIT }, /* 5 */ { DIRECTORY_QUERY, OBJ_INHERIT, DUPLICATE_SAME_ATTRIBUTES, DIRECTORY_QUERY, 0 }, { DIRECTORY_QUERY, OBJ_INHERIT, DUPLICATE_SAME_ACCESS | DUPLICATE_SAME_ATTRIBUTES, DIRECTORY_ALL_ACCESS, 0 }, }; ULONG i; for (i = 0; i < RTL_NUMBER_OF(Tests); i++) { trace("Test %lu\n", i); Status = ZwDuplicateObject(ZwCurrentProcess(), Handle, ZwCurrentProcess(), &NewHandle, Tests[i].DesiredAccess, Tests[i].RequestedAttributes, Tests[i].Options); ok_eq_hex(Status, STATUS_SUCCESS); if (!skip(NT_SUCCESS(Status), "DuplicateHandle failed\n")) { ok(IsUserHandle(NewHandle), "New handle = %p\n", NewHandle); CheckObject(NewHandle, 3UL, 2UL, Tests[i].ExpectedAttributes, Tests[i].GrantedAccess); CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS); Status = ObCloseHandle(NewHandle, UserMode); ok_eq_hex(Status, STATUS_SUCCESS); CheckObject(Handle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS); } } /* If TargetProcess is the System process, we do get a kernel handle */ Status = ZwDuplicateObject(ZwCurrentProcess(), Handle, SystemProcessHandle, &NewHandle, DIRECTORY_ALL_ACCESS, OBJ_KERNEL_HANDLE, 0); ok_eq_hex(Status, STATUS_SUCCESS); if (!skip(NT_SUCCESS(Status), "DuplicateHandle failed\n")) { ok(IsKernelHandle(NewHandle), "New handle = %p\n", NewHandle); CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS); CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS); Status = ObCloseHandle(NewHandle, UserMode); ok_eq_hex(Status, STATUS_INVALID_HANDLE); CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS); CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS); if (IsKernelHandle(NewHandle)) { Status = ObCloseHandle(NewHandle, KernelMode); ok_eq_hex(Status, STATUS_SUCCESS); CheckObject(Handle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS); } } }
bool CWorldVisitor::Visit( IComponent * component, bool bVisitEnter ) { IObject *theObject; IHashString *name; IHashString *parentName; IHashString *type; StdString parentType; StdString childType; std::string str; theObject = dynamic_cast<IObject *>(component); // This shouldn't happen but it does for some odd reason.... assert(theObject); if( theObject == NULL ) { return false; } name = theObject->GetName(); parentName = theObject->GetParentName(); type = theObject->GetComponentType(); //Check to see if it is a valid object (for object exclusion) if( !CheckObject( type->GetString() ) ) { return true; } else { if ( name == NULL ) { name = &CHashString(_T("NULL")); } if( bVisitEnter == true ) { //if( (m_pArchiver != NULL) && ( _tcscmp( type->GetString(), _T("CPhysicsObject") ) != 0 ) ) if( (m_pArchiver != NULL) ) { // Start the Node m_pArchiver->StartClass( type->GetString() ); // Write out the Unique ID aka Name m_pArchiver->Write( name->GetString(), _T("Name") ); theObject->Serialize( *m_pArchiver ); } // Removal of CPhysShape and changes to CPhysicsObject if( _tcscmp( type->GetString(), _T("CPhysicsObject") ) == 0 ) { CPhysObjectStruct tmpCPhysObject; StdString CPhyShapeFile; StdString CPhyShapeFileOld; // if it's parent is not a CTerrainSector Object if( _tcsstr( name->GetString(), _T("Terrain") ) == NULL ) { static DWORD msgHash_GetModelFileName = CHashString(_T("GetModelFileName")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_GetModelFileName, sizeof(StdString*), &CPhyShapeFile, parentName, NULL ); CPhyShapeFile += _T(".psl"); } // CTerrainSector Object else { CPhyShapeFile = _T("maps\\terrain.psl"); } IArchive *PhysObjectIn; IArchive *PhysObjectRead; CHashString memTypePhysObjectIn(_T("Memory")); int PhysObjectInMemSize = 1024 * 1024 * sizeof(char); char* PhysObjectInMemChunk = new char[PhysObjectInMemSize]; memset( PhysObjectInMemChunk, 0, PhysObjectInMemSize ); CREATEARCHIVE caPhysObjectIn; caPhysObjectIn.mode = STREAM_MODE_READ; caPhysObjectIn.streamData = PhysObjectInMemChunk; caPhysObjectIn.streamSize = PhysObjectInMemSize; caPhysObjectIn.streamType = &memTypePhysObjectIn; static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caPhysObjectIn) != MSG_HANDLED) { return true; } PhysObjectIn = caPhysObjectIn.archive; CREATESTREAM csPhysObjectIn; csPhysObjectIn.streamData = caPhysObjectIn.streamData; csPhysObjectIn.streamSize = caPhysObjectIn.streamSize; csPhysObjectIn.mode = STREAM_MODE_WRITE; static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &csPhysObjectIn) != MSG_HANDLED) { return true; } PhysObjectIn->Init(csPhysObjectIn.openStream); SERIALIZEOBJECTPARAMS sop; sop.name = name; sop.archive = PhysObjectIn; static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL); PhysObjectIn->Close(); CREATEARCHIVE caPhysObjectRead; caPhysObjectRead.mode = STREAM_MODE_WRITE; caPhysObjectRead.streamData = PhysObjectInMemChunk; caPhysObjectRead.streamSize = PhysObjectInMemSize; caPhysObjectRead.streamType = &memTypePhysObjectIn; if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caPhysObjectRead) != MSG_HANDLED) { return true; } PhysObjectRead = caPhysObjectRead.archive; CREATESTREAM csPhysObjectRead; csPhysObjectRead.streamData = caPhysObjectRead.streamData; csPhysObjectRead.streamSize = caPhysObjectRead.streamSize; csPhysObjectRead.mode = STREAM_MODE_READ; if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &csPhysObjectRead) != MSG_HANDLED) { return true; } PhysObjectRead->Init(csPhysObjectRead.openStream); PhysObjectRead->Read( tmpCPhysObject.vPosition, _T("pos") ); PhysObjectRead->Read( tmpCPhysObject.vRotation, _T("rot") ); PhysObjectRead->Read( tmpCPhysObject.vScale, _T("scale") ); PhysObjectRead->Read( tmpCPhysObject.fMass, _T("mass") ); PhysObjectRead->Read( tmpCPhysObject.szDynamic, _T("dynamics") ); PhysObjectRead->Read( CPhyShapeFileOld, _T("shapeFile") ); PhysObjectRead->Close(); // Archive the Data Back In IArchive *MemArchivePhysObject; CHashString memTypePhysObject(_T("Memory")); //int sizePhysObject = 1024 * 1024; //char* memchunkPhysObject = new char[sizePhysObject]; CREATEARCHIVE caPhysObject; caPhysObject.mode = STREAM_MODE_WRITE; caPhysObject.streamData = PhysObjectInMemChunk; caPhysObject.streamSize = PhysObjectInMemSize; caPhysObject.streamType = &memTypePhysObject; if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caPhysObject) != MSG_HANDLED) { return true; } MemArchivePhysObject = caPhysObject.archive; MemArchivePhysObject->Write( tmpCPhysObject.vPosition, _T("pos") ); MemArchivePhysObject->Write( tmpCPhysObject.vRotation, _T("rot") ); MemArchivePhysObject->Write( tmpCPhysObject.vScale, _T("scale") ); MemArchivePhysObject->Write( tmpCPhysObject.fMass, _T("mass") ); MemArchivePhysObject->Write( tmpCPhysObject.szDynamic, _T("dynamics") ); MemArchivePhysObject->Write( CPhyShapeFile, _T("shapeFile") ); CREATESTREAM csPhysObject; csPhysObject.streamData = caPhysObject.streamData; csPhysObject.streamSize = caPhysObject.streamSize; csPhysObject.mode = STREAM_MODE_READ; if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &csPhysObject) != MSG_HANDLED) { return true; } MemArchivePhysObject->Init(csPhysObject.openStream); SERIALIZEOBJECTPARAMS sopPhysObject; sopPhysObject.name = name; sopPhysObject.archive = MemArchivePhysObject; m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sopPhysObject, NULL, NULL); MemArchivePhysObject->Close(); //delete [] memchunkPhysObject; //memchunkPhysObject = NULL; delete [] PhysObjectInMemChunk; PhysObjectInMemChunk = NULL; } // Model Rename Changes if( (m_pReporter != NULL) && ( _tcscmp( type->GetString(), _T("CV3ORenderObject") ) == 0 ) ) { IArchive *MemArchive; IArchive *MemArchive2; CHashString memType(_T("Memory")); memset( m_pMemChunk, '\0', m_iMemSize ); CREATEARCHIVE ca; ca.mode = STREAM_MODE_READ; ca.streamData = m_pMemChunk; ca.streamSize = m_iMemSize; ca.streamType = &memType; static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED) { return true; } MemArchive = ca.archive; CREATESTREAM cs; cs.streamData = ca.streamData; cs.streamSize = ca.streamSize; cs.mode = STREAM_MODE_WRITE; static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &cs) != MSG_HANDLED) { return true; } MemArchive->Init(cs.openStream); SERIALIZEOBJECTPARAMS sop; sop.name = name; sop.archive = MemArchive; static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL); MemArchive->Close(); CREATEARCHIVE ca2; ca2.mode = STREAM_MODE_WRITE; ca2.streamData = m_pMemChunk; ca2.streamSize = m_iMemSize; ca2.streamType = &memType; if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &ca2) != MSG_HANDLED) { return true; } MemArchive2 = ca2.archive; CREATESTREAM cs2; cs2.streamData = ca2.streamData; cs2.streamSize = ca2.streamSize; cs2.mode = STREAM_MODE_READ; if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &cs2) != MSG_HANDLED) { return true; } MemArchive2->Init(cs2.openStream); StdString wszModelFileName; Vec3 Position; Vec3 Rotation; Vec3 Scale; MemArchive2->Read( wszModelFileName ); MemArchive2->Read( Position ); MemArchive2->Read( Rotation ); MemArchive2->Read( Scale ); MemArchive2->Close(); MODELMAP::iterator itr; bool bReArchive = false; while( 1 ) { itr = m_vModelReference.find( wszModelFileName ); // If the Model Refernce already exists if( itr != m_vModelReference.end() ) { // If its newfilename is different and it isn't an empty string // We Change the file name and set the archive flag if( (wszModelFileName != itr->second.m_wszNewFileName) && (itr->second.m_wszNewFileName != StdString("")) ) { wszModelFileName = itr->second.m_wszNewFileName; bReArchive = true; } // We've reached a file that has the same exact newfilename, no change neccisary else { break; } } // We change model name first (up above) and then make sure to add it as a reference and break out itr = m_vModelReference.find( wszModelFileName ); if( itr == m_vModelReference.end() ) { /* MODELINFO tmpModelInfo; tmpModelInfo.m_wszNewFileName = wszModelFileName; m_vModelReference[wszModelFileName] = tmpModelInfo; m_iNewEntries++; */ break; } } m_szLastV3OFileName = wszModelFileName; // Archive the object back out if( bReArchive == true ) { IArchive *MemArchiveRE; CHashString memTypeRE(_T("Memory")); int sizeRE = 1024 + sizeof(Vec3) * 3; char* memchunkRE = new char[sizeRE]; CREATEARCHIVE caRE; caRE.mode = STREAM_MODE_WRITE; caRE.streamData = memchunkRE; caRE.streamSize = sizeRE; caRE.streamType = &memTypeRE; static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caRE) != MSG_HANDLED) { return true; } MemArchiveRE = caRE.archive; MemArchiveRE->Write( wszModelFileName ); MemArchiveRE->Write( Position ); MemArchiveRE->Write( Rotation ); MemArchiveRE->Write( Scale ); CREATESTREAM csRE; csRE.streamData = caRE.streamData; csRE.streamSize = caRE.streamSize; csRE.mode = STREAM_MODE_READ; static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID(); if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &csRE) != MSG_HANDLED) { return true; } MemArchiveRE->Init(csRE.openStream); SERIALIZEOBJECTPARAMS sopRE; sopRE.name = name; sopRE.archive = MemArchiveRE; static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sopRE, NULL, NULL); MemArchiveRE->Close(); delete [] memchunkRE; memchunkRE = NULL; m_iV3ONameEdits++; } } } // bVisitEnter == false else { if( m_pArchiver != NULL ) { m_pArchiver->EndClass(); } } } return true; }
uintptr_t WINAPI MemoryManager::CheckJitRoots(void* arg) { #ifndef GC_SERIAL EnterCriticalSection(&jit_cs); #endif #ifdef _DEBUG wcout << L"---- Marking JIT method root(s): num=" << jit_roots.size() << L"; thread=" << GetCurrentThread() << L" ------" << endl; wcout << L"memory types: " << endl; #endif unordered_map<long*, ClassMethodId*>::iterator jit_iter; for(jit_iter = jit_roots.begin(); jit_iter != jit_roots.end(); ++jit_iter) { ClassMethodId* id = jit_iter->second; long* mem = id->mem; StackMethod* mthd = prgm->GetClass(id->cls_id)->GetMethod(id->mthd_id); const long dclrs_num = mthd->GetNumberDeclarations(); #ifdef _DEBUG wcout << L"\t===== JIT method: name=" << mthd->GetName() << L", id=" << id->cls_id << L"," << id->mthd_id << L"; addr=" << mthd << L"; num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // check self CheckObject(id->self, true, 1); StackDclr** dclrs = mthd->GetDeclarations(); for(int j = dclrs_num - 1; j > -1; j--) { // update address based upon type switch(dclrs[j]->type) { case FUNC_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": FUNC_PARM: value=" << (*mem) << L"," << *(mem + 1) << endl; #endif // update mem += 2; break; case CHAR_PARM: case INT_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": CHAR_PARM/INT_PARM: value=" << (*mem) << endl; #endif // update mem++; break; case FLOAT_PARM: { #ifdef _DEBUG FLOAT_VALUE value; memcpy(&value, mem, sizeof(FLOAT_VALUE)); wcout << L"\t" << j << L": FLOAT_PARM: value=" << value << endl; #endif // update mem += 2; } break; case BYTE_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": BYTE_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case CHAR_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": CHAR_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case INT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": INT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case FLOAT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": FLOAT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << L" byte(s)" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case OBJ_PARM: { #ifdef _DEBUG wcout << L"\t" << j << L": OBJ_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), id="; if(*mem) { StackClass* tmp = (StackClass*)((long*)(*mem))[SIZE_OR_CLS]; wcout << L"'" << tmp->GetName() << L"'" << endl; } else { wcout << L"Unknown" << endl; } #endif // check object CheckObject((long*)(*mem), true, 1); // update mem++; } break; // TODO: test the code below case OBJ_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": OBJ_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data if(MarkValidMemory((long*)(*mem))) { long* array = (long*)(*mem); const long size = array[0]; const long dim = array[1]; long* objects = (long*)(array + 2 + dim); for(long k = 0; k < size; k++) { CheckObject((long*)objects[k], true, 2); } } // update mem++; break; default: break; } } // NOTE: this marks temporary variables that are stored in JIT memory // during some method calls. there are 3 integer temp addresses for(int i = 0; i < 8; i++) { CheckObject((long*)mem[i], false, 1); } } #ifndef GC_SERIAL LeaveCriticalSection(&jit_cs); #endif return 0; }
PUBLIC Stream * Open( Object * object, string name, word mode ) { word rc = Err_Null; Stream *stream = NULL; MCB *mcb; IOCReply1 *rep; word stlen; Port reply; #ifdef SYSDEB SysDebug(ioc)("Open(%O,%N,%x)",object,name,mode); #endif if( CheckObject(object,C_Locate) != Err_Null ) return Null(Stream); reply = NewPort(); mcb = NewMsgBuf(0); rep = (IOCReply1 *)mcb->Control; InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP|FG_Open|object->FnMod); MarshalCommon(mcb,object,name); MarshalWord(mcb,mode); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done; stlen = sizeof(Stream) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin; stream = (Stream *)Malloc(stlen); if( stream == NULL ) { rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Stream; goto Done; } else memclr( (void *)stream, (int)stlen ); if( SetupStream( stream, mcb ) ) { stream->Flags |= mode&Flags_SaveMode; InitSemaphore( &stream->Mutex, 1 ); stream->Pos = 0; } AddStream( stream ); rc = Err_Null; if( mode & Flags_Append ) Seek(stream, S_End, 0); Done: #ifdef SYSDEB SysDebug(ioc)("Open: %E stream: %S",rc,stream); #endif FreeMsgBuf(mcb); if( rc < Err_Null ) FreePort(reply); object->Result2 = rc; return stream; }
uintptr_t WINAPI MemoryManager::CheckPdaRoots(void* arg) { #ifndef _GC_SERIAL EnterCriticalSection(&pda_frame_cs); #endif #ifdef _DEBUG wcout << L"----- PDA frames(s): num=" << pda_frames.size() << L"; thread=" << GetCurrentThread()<< L" -----" << endl; wcout << L"memory types:" << endl; #endif set<StackFrame**, StackFrame**>::iterator iter; for(iter = pda_frames.begin(); iter != pda_frames.end(); ++iter) { StackFrame** frame = *iter; StackMethod* mthd = (*frame)->method; long* mem = (*frame)->mem; #ifdef _DEBUG wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr=" << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // mark self CheckObject((long*)(*mem), true, 1); if(mthd->HasAndOr()) { mem += 2; } else { mem++; } // mark rest of memory CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0); } #ifndef _GC_SERIAL LeaveCriticalSection(&pda_frame_cs); #endif #ifndef GC_SERIAL EnterCriticalSection(&pda_monitor_cs); #endif #ifdef _DEBUG wcout << L"----- PDA method root(s): num=" << pda_monitors.size() << L"; thread=" << GetCurrentThread()<< L" -----" << endl; wcout << L"memory types:" << endl; #endif // look at pda methods unordered_map<StackFrameMonitor*, StackFrameMonitor*>::iterator pda_iter; for(pda_iter = pda_monitors.begin(); pda_iter != pda_monitors.end(); ++pda_iter) { // gather stack frames StackFrameMonitor* monitor = pda_iter->first; long call_stack_pos = *(monitor->call_stack_pos); if (call_stack_pos > 0) { StackFrame** call_stack = monitor->call_stack; StackFrame* cur_frame = *(monitor->cur_frame); // copy frames locally vector<StackFrame*> frames; frames.push_back(cur_frame); while (--call_stack_pos > -1) { frames.push_back(call_stack[call_stack_pos]); } for (size_t i = 0; i < frames.size(); ++i) { StackMethod* mthd = frames[i]->method; long* mem = frames[i]->mem; #ifdef _DEBUG wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr=" << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // mark self CheckObject((long*)(*mem), true, 1); if (mthd->HasAndOr()) { mem += 2; } else { mem++; } // mark rest of memory CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0); } } } #ifndef GC_SERIAL LeaveCriticalSection(&pda_monitor_cs); #endif return 0; }
static VOID TestCreateSection( IN HANDLE FileHandle1, IN PFILE_OBJECT FileObject1, IN HANDLE FileHandle2, IN PFILE_OBJECT FileObject2) { NTSTATUS Status = STATUS_SUCCESS; PVOID SectionObject; LARGE_INTEGER MaximumSize; ULONG PointerCount1, PointerCount2; KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION); if (!KmtIsCheckedBuild) { /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */ KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_ACCESS_VIOLATION); KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, 0, NULL, NULL); KmtEndSeh(STATUS_ACCESS_VIOLATION); } SectionObject = KmtInvalidPointer; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION); ok_eq_pointer(SectionObject, KmtInvalidPointer); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_ACCESS_VIOLATION); SectionObject = KmtInvalidPointer; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_ACCESS_VIOLATION); ok_eq_pointer(SectionObject, KmtInvalidPointer); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 0; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION); ok_eq_longlong(MaximumSize.QuadPart, 0LL); ok_eq_pointer(SectionObject, KmtInvalidPointer); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); MaximumSize.QuadPart = 0; KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4); ok_eq_longlong(MaximumSize.QuadPart, 0LL); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_ACCESS_VIOLATION); ok_eq_longlong(MaximumSize.QuadPart, 1LL); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 0; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4); ok_eq_longlong(MaximumSize.QuadPart, 0LL); ok_eq_pointer(SectionObject, KmtInvalidPointer); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); /* page file section */ SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); if (!skip(FileHandle1 != NULL && FileObject1 != NULL && FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n")) { PointerCount1 = 3; PointerCount2 = 3; /* image section */ CheckObject(FileHandle2, PointerCount2, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle2, PointerCount2, 1L); CheckSection(SectionObject, SEC_IMAGE); TestMapView(SectionObject, FALSE, TRUE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle2, PointerCount2, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); ++PointerCount2; CheckObject(FileHandle2, PointerCount2, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, TRUE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); //--PointerCount2; // ???? CheckObject(FileHandle2, PointerCount2, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle2, PointerCount2, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, TRUE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); /* image section with inappropriate file */ CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_pointer(SectionObject, KmtInvalidPointer); CheckObject(FileHandle1, PointerCount1, 1L); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); ++PointerCount1; CheckObject(FileHandle1, PointerCount1, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); //--PointerCount1; // ???? CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); /* image section with two different files */ CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle2, PointerCount2, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, TRUE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle2, PointerCount2, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); /* data file section */ CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, NULL); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle1, PointerCount1, 1L); SectionObject = KmtInvalidPointer; MaximumSize.QuadPart = 1; KmtStartSeh() Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1); KmtEndSeh(STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != NULL, "Section object pointer NULL\n"); CheckObject(FileHandle1, PointerCount1, 1L); CheckSection(SectionObject, 0); TestMapView(SectionObject, TRUE, FALSE); if (SectionObject && SectionObject != KmtInvalidPointer) ObDereferenceObject(SectionObject); CheckObject(FileHandle1, PointerCount1, 1L); } }
void MemoryManager::CheckMemory(long* mem, StackDclr** dclrs, const long dcls_size, long depth) { // check method for(long i = 0; i < dcls_size; i++) { #ifdef _DEBUG for(int j = 0; j < depth; j++) { wcout << L"\t"; } #endif // update address based upon type switch(dclrs[i]->type) { case FUNC_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": FUNC_PARM: value=" << (*mem) << L"," << *(mem + 1)<< endl; #endif // update mem += 2; break; case CHAR_PARM: case INT_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": CHAR_PARM/INT_PARM: value=" << (*mem) << endl; #endif // update mem++; break; case FLOAT_PARM: { #ifdef _DEBUG FLOAT_VALUE value; memcpy(&value, mem, sizeof(FLOAT_VALUE)); wcout << L"\t" << i << L": FLOAT_PARM: value=" << value << endl; #endif // update mem += 2; } break; case BYTE_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": BYTE_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case CHAR_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": CHAR_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case INT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": INT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case FLOAT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": FLOAT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case OBJ_PARM: { #ifdef _DEBUG wcout << L"\t" << i << L": OBJ_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), id="; if(*mem) { StackClass* tmp = (StackClass*)((long*)(*mem))[SIZE_OR_CLS]; wcout << L"'" << tmp->GetName() << L"'" << endl; } else { wcout << L"Unknown" << endl; } #endif // check object CheckObject((long*)(*mem), true, depth + 1); // update mem++; } break; case OBJ_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << i << L": OBJ_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data if(MarkValidMemory((long*)(*mem))) { long* array = (long*)(*mem); const long size = array[0]; const long dim = array[1]; long* objects = (long*)(array + 2 + dim); for(long k = 0; k < size; k++) { CheckObject((long*)objects[k], true, 2); } } // update mem++; break; default: break; } } }
PUBLIC Object * Create( Object * object, string name, word type, word size, byte * data ) { word rc = Err_Null; Object *obj = Null(Object); MCB *mcb; IOCReply1 *rep; word oblen; Port reply; #ifdef SYSDEB SysDebug(ioc)("Create(%O,%N,%T,%d,%P)",object,name,type,size,data); #endif if ( CheckObject(object,C_Locate) != Err_Null ) { return NULL; } reply = NewPort(); mcb = NewMsgBuf(0); rep = (IOCReply1 *)mcb->Control; InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP|FG_Create|object->FnMod); MarshalCommon(mcb,object,name); MarshalWord(mcb,type); MarshalWord(mcb,size); MarshalOffset(mcb); MarshalData(mcb,size,data); mcb->Timeout = object->Timeout; /* IOdebug( "Create: sending message" ); */ if ( (rc = IOCMsg(mcb, NULL)) < Err_Null ) { /* IOdebug( "Create: message send failed" ); */ goto Done; } /* IOdebug( "Create: message sent" ); */ oblen = sizeof(Object) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin; obj = (Object *)Malloc(oblen); if ( obj == NULL ) { rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Object; goto Done; } else memclr( (void *)obj, (int)oblen ); obj->Type = rep->Type; obj->Flags = rep->Flags; obj->Access = rep->Access; obj->Reply = reply; obj->FnMod = rc & SS_Mask; obj->Timeout = IOCTimeout; strcpy(obj->Name,mcb->Data+rep->Pathname); AddObject( obj ); rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("Create: %E object: %O",rc,obj); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Create: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); if( rc < Err_Null ) FreePort(reply); object->Result2 = rc; return obj; }
PUBLIC Object * Locate( Object * object, STRING name ) { word rc = Err_Null; Object *obj = Null(Object); MCB *mcb; IOCReply1 *rep; word oblen; Port reply; word fnmod = 0; #ifdef SYSDEB SysDebug(ioc)("Locate(%O,%N)",object,name); #endif /* Locate can be called with a null object pointer */ if( object != NULL ) { if( CheckObject(object,C_Locate) != Err_Null ) { return NULL; } fnmod = object->FnMod; } reply = NewPort(); mcb = NewMsgBuf(0); rep = (IOCReply1 *)mcb->Control; InitMCB(mcb,MsgHdr_Flags_preserve, MyTask->IOCPort,reply,FC_GSP|FG_Locate|fnmod); MarshalCommon(mcb,object,name); if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) { goto Done; } oblen = sizeof(Object) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin; obj = (Object *)Malloc(oblen); if( obj == NULL ) { rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Object; goto Done; } else memclr( (void *)obj, (int)oblen ); obj->Type = rep->Type; obj->Flags = rep->Flags; obj->Access = rep->Access; obj->Reply = reply; obj->FnMod = rc & SS_Mask; obj->Timeout = IOCTimeout; strcpy(obj->Name,mcb->Data+rep->Pathname); AddObject( obj ); rc = Err_Null; Done: #ifdef SYSDEB SysDebug(ioc)("Locate: %E object: %O",rc,obj); if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Locate: Non-Null Reply port %x",mcb->MsgHdr.Reply); #endif if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply); FreeMsgBuf(mcb); if( object != Null(Object) ) object->Result2 = rc; if( rc < Err_Null ) FreePort(reply); return obj; }