void Thread::ResumeFromWait() { // Cancel any outstanding wakeup events for this thread CoreTiming::UnscheduleEvent(ThreadWakeupEventType, callback_handle); switch (status) { case THREADSTATUS_WAIT_SYNCH: // Remove this thread from all other WaitObjects for (auto wait_object : wait_objects) wait_object->RemoveWaitingThread(this); break; case THREADSTATUS_WAIT_ARB: case THREADSTATUS_WAIT_SLEEP: break; case THREADSTATUS_RUNNING: case THREADSTATUS_READY: DEBUG_ASSERT_MSG(false, "Thread with object id %u has already resumed.", GetObjectId()); return; case THREADSTATUS_DEAD: // This should never happen, as threads must complete before being stopped. DEBUG_ASSERT_MSG(false, "Thread with object id %u cannot be resumed because it's DEAD.", GetObjectId()); return; } ready_queue.push_back(current_priority, this); status = THREADSTATUS_READY; }
ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions) { if (base_address != 0) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s: already mapped at 0x%08X!", GetObjectId(), address, name.c_str(), base_address); // TODO: Verify error code with hardware return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } // TODO(Subv): Return E0E01BEE when permissions and other_permissions don't // match what was specified when the memory block was created. // TODO(Subv): Return E0E01BEE when address should be 0. // Note: Find out when that's the case. if (fixed_address != 0) { if (address != 0 && address != fixed_address) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s: fixed_addres is 0x%08X!", GetObjectId(), address, name.c_str(), fixed_address); // TODO: Verify error code with hardware return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } // HACK(yuriks): This is only here to support the APT shared font mapping right now. // Later, this should actually map the memory block onto the address space. return RESULT_SUCCESS; } if (address < Memory::SHARED_MEMORY_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s outside of shared mem bounds!", GetObjectId(), address, name.c_str()); // TODO: Verify error code with hardware return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } // TODO: Test permissions // HACK: Since there's no way to write to the memory block without mapping it onto the game // process yet, at least initialize memory the first time it's mapped. if (address != this->base_address) { std::memset(Memory::GetPointer(address), 0, size); } this->base_address = address; return RESULT_SUCCESS; }
u8* SharedMemory::GetPointer(u32 offset) { if (base_address != 0) return Memory::GetPointer(base_address + offset); LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId()); return nullptr; }
//-------------------------------------------------------------- void AnimatedObject::draw(bool bEditorMode){ //>>?? int t = ofGetElapsedTimef()*100-collisionTime; if(t<highlightTime){ ofSetHexColor(highlightColor); }else{ if(/*(SimpleMission::MISSION_CALIFICATIONS == currentMission->GetMissionState()) && */ (*currentMissions)[idCurrtentMission]->isElementHit(GetObjectId())){ ofSetHexColor(highlightColor); } else{ ofSetHexColor(color); } } //<<?? material.begin(); ofPoint scaleModel = assimpModel.getScale(); body.transformGL(); ofScale(scaleModel.x,scaleModel.y,scaleModel.z); //assimpModel.getMesh(0).drawFaces(); //assimpModel.getMesh(0).drawWireframe(); assimpModel.getCurrentAnimatedMesh(0).drawWireframe(); body.restoreTramsformGL(); glPopAttrib(); material.end(); }
ResultVal<u8*> SharedMemory::GetPointer(u32 offset) { if (base_address != 0) return MakeResult<u8*>(Memory::GetPointer(base_address + offset)); LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId()); // TODO(yuriks): Verify error code. return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, ErrorSummary::InvalidState, ErrorLevel::Permanent); }
//-------------------------------------------------------------- void GeneratedMesh::draw(bool bEditorMode){ //>>?? int t = ofGetElapsedTimef()*100-collisionTime; if(t<highlightTime){ ofSetHexColor(highlightColor); }else{ if(/*(SimpleMission::MISSION_CALIFICATIONS == currentMission->GetMissionState()) && */ (*currentMissions)[idCurrtentMission]->isElementHit(GetObjectId())){ ofSetHexColor(highlightColor); } else{ ofSetHexColor(color); } } //<<?? body.transformGL(); ofSetColor( 255, 255, 255, 255 ); fbo.getTextureReference().bind(); glSamplerParameterf( fbo.getTextureReference().texData.textureTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy ); ofSetTextureWrap( GL_REPEAT, GL_REPEAT ); mesh.draw(); fbo.getTextureReference().unbind(); body.restoreTramsformGL(); #if 0 material.begin(); ofPoint scaleModel = assimpModel.getScale(); mesh = assimpModel.getCurrentAnimatedMesh(0); body.updateMesh( this->world->world, mesh ); body.getRigidBody()->getCollisionShape()->setLocalScaling(btVector3(scaleModel.x, scaleModel.y, scaleModel.z)); body.transformGL(); ofScale(scaleModel.x,scaleModel.y,scaleModel.z); //assimpModel.getMesh(0).drawFaces(); //assimpModel.getMesh(0).drawWireframe(); //if (ModelPath.compare(_sysPath) == 0) // ofRotateX(90); mesh.drawWireframe(); body.restoreTramsformGL(); glPopAttrib(); material.end(); #endif }
//-------------------------------------------------------------------------------- bool CFileIndexObject::Read(CFile& file, bool bResetPosOnError) { DWORD nPos; bool bPosOk = false; DWORD nNum; char* pBuf = NULL; bool bRv = true; TRY { if(bResetPosOnError) { nPos = file.GetPosition(); bPosOk = true; } // read the object id if(file.Read(&nNum, sizeof(nNum)) == sizeof(nNum)) // be sure we're reading the object we want if(nNum == GetObjectId()) // read the name length if(file.Read(&nNum, sizeof(nNum)) == sizeof(nNum)) { pBuf = m_sName.GetBuffer(nNum); bRv = (file.Read(pBuf, nNum) == nNum); } char temp[1024]; file.Read(temp, 1024); } CATCH_ALL(e) { bRv = false; } END_CATCH_ALL; if(pBuf != NULL) m_sName.ReleaseBuffer(); if(bResetPosOnError && bPosOk && ! bRv) TRY { file.Seek(nPos, CFile::begin); } CATCH_ALL(e) { } END_CATCH_ALL; return bRv; }
void Timer::Signal(int cycles_late) { LOG_TRACE(Kernel, "Timer %u fired", GetObjectId()); signaled = true; // Resume all waiting threads WakeupAllWaitingThreads(); if (interval_delay != 0) { // Reschedule the timer with the interval delay u64 interval_microseconds = interval_delay / 1000; CoreTiming::ScheduleEvent(usToCycles(interval_microseconds) - cycles_late, timer_callback_event_type, callback_handle); } }
ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions) { if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!", GetObjectId(), address); // TODO: Verify error code with hardware return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } this->base_address = address; this->permissions = permissions; this->other_permissions = other_permissions; return RESULT_SUCCESS; }
//-------------------------------------------------------------- void AnimatedMotionPath::draw(bool bEditorMode){ //>>?? int t = ofGetElapsedTimef()*100-collisionTime; if(t<highlightTime){ ofSetHexColor(highlightColor); }else{ if(/*(SimpleMission::MISSION_CALIFICATIONS == currentMission->GetMissionState()) && */ (*currentMissions)[idCurrtentMission]->isElementHit(GetObjectId())){ ofSetHexColor(highlightColor); } else{ ofSetHexColor(color); } } //<<?? material.begin(); ofPoint scaleModel = assimpModel.getScale(); body.transformGL(); ofScale(scaleModel.x,scaleModel.y,scaleModel.z); //assimpModel.getMesh(0).drawFaces(); //assimpModel.getMesh(0).drawWireframe(); //if (ModelPath.compare(sysPath) == 0) // ofRotateX(90); ofxAssimpMeshHelper &modelMeshHelper = assimpModel.getMeshHelper(0); //assimpModel.getCurrentAnimatedMesh(0).drawWireframe(); ofPushMatrix(); //ofMultMatrix(modelMeshHelper.matrix); modelMeshHelper.vbo.drawElements(GL_LINES,modelMeshHelper.indices.size()); ofPopMatrix(); ofxAssimpMeshHelper &pathMeshHelper = assimpPath.getMeshHelper(m_AnimationMeshNo); //assimpPath.getCurrentAnimatedMesh(m_AnimationMeshNo).drawWireframe(); ofPushMatrix(); //ofMultMatrix(pathMeshHelper.matrix); pathMeshHelper.vbo.drawElements(GL_LINES,pathMeshHelper.indices.size()); ofPopMatrix(); assimpPath.drawWireframe(); body.restoreTramsformGL(); glPopAttrib(); material.end(); }
//-------------------------------------------------------------------------------- bool CFileIndexObject::Write(CFile& file, bool bResetPosOnError) { DWORD nPos; bool bPosOk = false; bool bRv = true; TRY { if(bResetPosOnError) { nPos = file.GetPosition(); bPosOk = true; } DWORD nNum = GetObjectId(); file.Write(&nNum, sizeof(nNum)); nNum = m_sName.GetLength(); file.Write(&nNum, sizeof(nNum)); file.Write((LPCTSTR) m_sName, nNum); char temp[1024]; file.Write(temp, 1024); } CATCH_ALL(e) { bRv = false; } END_CATCH_ALL; if(bPosOk && bResetPosOnError && ! bRv) TRY { file.Seek(nPos, CFile::begin); } CATCH_ALL(e) { } END_CATCH_ALL; return bRv; }
/* return 1 on success and 0 on failure. * By side effect returns private key, cert, and optionally ca. * Parses and decodes the parts of PKCS12 * * NOTE: can parse with USER RSA enabled but may return cert that is not the * pair for the key when using RSA key pairs. * * pkcs12 : non-null WC_PKCS12 struct * psw : password to use for PKCS12 decode * pkey : Private key returned * cert : x509 cert returned * ca : optional ca returned */ int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw, byte** pkey, word32* pkeySz, byte** cert, word32* certSz, WC_DerCertList** ca) { ContentInfo* ci = NULL; WC_DerCertList* certList = NULL; byte* buf = NULL; word32 i, oid; int ret, pswSz; WOLFSSL_ENTER("wc_PKCS12_parse"); if (pkcs12 == NULL || psw == NULL || cert == NULL || certSz == NULL || pkey == NULL || pkeySz == NULL) { return BAD_FUNC_ARG; } pswSz = (int)XSTRLEN(psw); *cert = NULL; *pkey = NULL; if (ca != NULL) { *ca = NULL; } /* if there is sign data then verify the MAC */ if (pkcs12->signData != NULL ) { if ((ret = wc_PKCS12_verify(pkcs12, pkcs12->safe->data, pkcs12->safe->dataSz, (byte*)psw, pswSz)) != 0) { WOLFSSL_MSG("PKCS12 Bad MAC on verify"); WOLFSSL_LEAVE("wc_PKCS12_parse verify ", ret); return MAC_CMP_FAILED_E; } } /* Decode content infos */ ci = pkcs12->safe->CI; for (i = 0; i < pkcs12->safe->numCI; i++) { byte* data; word32 idx = 0; int size, totalSz; if (ci->type == WC_PKCS12_ENCRYPTED_DATA) { int number; WOLFSSL_MSG("Decrypting PKCS12 Content Info Container"); data = ci->data; if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if ((ret = GetSequence(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if ((ret = GetShortInt(data, &idx, &number, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if (number != 0) { WOLFSSL_MSG("Expecting 0 for Integer with Encrypted PKCS12"); } if ((ret = GetSequence(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } ret = GetObjectId(data, &idx, &oid, oidIgnoreType, ci->dataSz); if (ret < 0 || oid != WC_PKCS12_DATA) { WOLFSSL_MSG("Not PKCS12 DATA object or get object parse error"); freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } /* decrypted content overwrites input buffer */ size = ci->dataSz - idx; buf = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (buf == NULL) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } XMEMCPY(buf, data + idx, size); if ((ret = DecryptContent(buf, size, psw, pswSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); WOLFSSL_MSG("Decryption failed, algorithm not compiled in?"); return ret; } data = buf; idx = 0; #ifdef WOLFSSL_DEBUG_PKCS12 { byte* p; for (printf("\tData = "), p = (byte*)buf; p < (byte*)buf + size; printf("%02X", *p), p++); printf("\n"); } #endif } else { /* type DATA */ WOLFSSL_MSG("Parsing PKCS12 DATA Content Info Container"); data = ci->data; if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) <= 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if (data[idx++] != ASN_OCTET_STRING) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } } /* parse through bags in ContentInfo */ if ((ret = GetSequence(data, &idx, &totalSz, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } totalSz += idx; while ((int)idx < totalSz) { int bagSz; if ((ret = GetSequence(data, &idx, &bagSz, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } bagSz += idx; if ((ret = GetObjectId(data, &idx, &oid, oidIgnoreType, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } switch (oid) { case WC_PKCS12_KeyBag: /* 667 */ WOLFSSL_MSG("PKCS12 Key Bag found"); if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) <= 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if (*pkey == NULL) { *pkey = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (*pkey == NULL) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } XMEMCPY(*pkey, data + idx, size); *pkeySz = ToTraditional(*pkey, size); } #ifdef WOLFSSL_DEBUG_PKCS12 { byte* p; for (printf("\tKey = "), p = (byte*)*pkey; p < (byte*)*pkey + size; printf("%02X", *p), p++); printf("\n"); } #endif idx += size; break; case WC_PKCS12_ShroudedKeyBag: /* 668 */ { byte* k; WOLFSSL_MSG("PKCS12 Shrouded Key Bag found"); if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } k = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (k == NULL) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } XMEMCPY(k, data + idx, size); /* overwrites input, be warned */ if ((ret = ToTraditionalEnc(k, size, psw, pswSz)) < 0) { freeBuffers(k, NULL, pkcs12->heap); freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if (ret < size) { /* shrink key buffer */ k = (byte*)XREALLOC(k, ret, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (k == NULL) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } } size = ret; if (*pkey == NULL) { *pkey = k; *pkeySz = size; } else { /* only expecting one key */ freeBuffers(k, NULL, pkcs12->heap); } idx += size; #ifdef WOLFSSL_DEBUG_PKCS12 { byte* p; for (printf("\tKey = "), p = (byte*)k; p < (byte*)k + ret; printf("%02X", *p), p++); printf("\n"); } #endif } break; case WC_PKCS12_CertBag: /* 669 */ { WC_DerCertList* node; WOLFSSL_MSG("PKCS12 Cert Bag found"); if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } /* get cert bag type */ if ((ret = GetSequence(data, &idx, &size, ci->dataSz)) <0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if ((ret = GetObjectId(data, &idx, &oid, oidIgnoreType, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } switch (oid) { case WC_PKCS12_CertBag_Type1: /* 675 */ /* type 1 */ WOLFSSL_MSG("PKCS12 cert bag type 1"); if (data[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) <= 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } if (data[idx++] != ASN_OCTET_STRING) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(data, &idx, &size, ci->dataSz)) < 0) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ret; } break; default: WOLFSSL_MSG("Unknown PKCS12 cert bag type"); } if (size + idx > (word32)bagSz) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return ASN_PARSE_E; } /* list to hold all certs found */ node = (WC_DerCertList*)XMALLOC(sizeof(WC_DerCertList), pkcs12->heap, DYNAMIC_TYPE_PKCS); if (node == NULL) { freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } XMEMSET(node, 0, sizeof(WC_DerCertList)); node->buffer = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (node->buffer == NULL) { XFREE(node, pkcs12->heap, DYNAMIC_TYPE_PKCS); freeBuffers(*pkey, buf, pkcs12->heap); freeCertList(certList, pkcs12->heap); return MEMORY_E; } XMEMCPY(node->buffer, data + idx, size); node->bufferSz = size; /* put the new node into the list */ if (certList != NULL) { WOLFSSL_MSG("Pushing new cert onto stack"); node->next = certList; certList = node; } else { certList = node; } /* on to next */ idx += size; } break; case WC_PKCS12_CrlBag: /* 670 */ WOLFSSL_MSG("PKCS12 CRL BAG not yet supported"); break; case WC_PKCS12_SecretBag: /* 671 */ WOLFSSL_MSG("PKCS12 Secret BAG not yet supported"); break; case WC_PKCS12_SafeContentsBag: /* 672 */ WOLFSSL_MSG("PKCS12 Safe Contents BAG not yet supported"); break; default: WOLFSSL_MSG("Unknown PKCS12 BAG type found"); } /* Attribute, unknown bag or unsupported */ if ((int)idx < bagSz) { idx = bagSz; /* skip for now */ } } /* free temporary buffer */ if (buf != NULL) { XFREE(buf, pkcs12->heap, DYNAMIC_TYPE_PKCS); buf = NULL; } ci = ci->next; WOLFSSL_MSG("Done Parsing PKCS12 Content Info Container"); } /* check if key pair, remove from list */ { WC_DerCertList* current = certList; WC_DerCertList* previous = NULL; if (*pkey != NULL) { while (current != NULL) { DecodedCert DeCert; InitDecodedCert(&DeCert, current->buffer, current->bufferSz, pkcs12->heap); if (ParseCertRelative(&DeCert, CERT_TYPE, NO_VERIFY, NULL) == 0) { if (wc_CheckPrivateKey(*pkey, *pkeySz, &DeCert) == 1) { WOLFSSL_MSG("Key Pair found"); *cert = current->buffer; *certSz = current->bufferSz; if (previous == NULL) { certList = current->next; } else { previous->next = current->next; } FreeDecodedCert(&DeCert); XFREE(current, pkcs12->heap, DYNAMIC_TYPE_PKCS); break; } } FreeDecodedCert(&DeCert); previous = current; current = current->next; } } } if (ca != NULL) { *ca = certList; } else { /* free list, not wanted */ freeCertList(certList, pkcs12->heap); } return 1; }
static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input, word32* idx, int maxIdx) { AuthenticatedSafe* safe; word32 oid; word32 localIdx = *idx; int ret; int size = 0; safe = (AuthenticatedSafe*)XMALLOC(sizeof(AuthenticatedSafe), pkcs12->heap, DYNAMIC_TYPE_PKCS); if (safe == NULL) { return MEMORY_E; } XMEMSET(safe, 0, sizeof(AuthenticatedSafe)); ret = GetObjectId(input, &localIdx, &oid, oidIgnoreType, maxIdx); if (ret < 0) { WOLFSSL_LEAVE("Get object id failed", ret); freeSafe(safe, pkcs12->heap); return ASN_PARSE_E; } safe->oid = oid; /* check tag, length */ if (input[localIdx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) { WOLFSSL_MSG("Unexpected tag in PKCS12 DER"); freeSafe(safe, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(input, &localIdx, &size, maxIdx)) <= 0) { freeSafe(safe, pkcs12->heap); return ret; } switch (oid) { case WC_PKCS12_ENCRYPTED_DATA: WOLFSSL_MSG("Found PKCS12 OBJECT: ENCRYPTED DATA\n"); break; case WC_PKCS12_DATA: WOLFSSL_MSG("Found PKCS12 OBJECT: DATA"); /* get octets holding contents */ if (input[localIdx++] != ASN_OCTET_STRING) { WOLFSSL_MSG("Wrong tag with content PKCS12 type DATA"); freeSafe(safe, pkcs12->heap); return ASN_PARSE_E; } if ((ret = GetLength(input, &localIdx, &size, maxIdx)) <= 0) { freeSafe(safe, pkcs12->heap); return ret; } break; } safe->dataSz = size; safe->data = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); if (safe->data == NULL) { freeSafe(safe, pkcs12->heap); return MEMORY_E; } XMEMCPY(safe->data, input + localIdx, size); *idx = localIdx; /* an instance of AuthenticatedSafe is created from * ContentInfo's strung together in a SEQUENCE. Here we itterate * through the ContentInfo's and add them to our * AuthenticatedSafe struct */ localIdx = 0; input = safe->data; { int CISz; ret = GetSequence(input, &localIdx, &CISz, safe->dataSz); if (ret < 0) { freeSafe(safe, pkcs12->heap); return ASN_PARSE_E; } CISz += localIdx; while ((int)localIdx < CISz) { int curSz = 0; word32 curIdx; ContentInfo* ci = NULL; #ifdef WOLFSSL_DEBUG_PKCS12 printf("\t\tlooking for Content Info.... "); #endif if ((ret = GetSequence(input, &localIdx, &curSz, safe->dataSz)) < 0) { freeSafe(safe, pkcs12->heap); return ret; } if (curSz > CISz) { /* subset should not be larger than universe */ freeSafe(safe, pkcs12->heap); return ASN_PARSE_E; } curIdx = localIdx; if ((ret = GetObjectId(input, &localIdx, &oid, oidIgnoreType, safe->dataSz)) < 0) { WOLFSSL_LEAVE("Get object id failed", ret); freeSafe(safe, pkcs12->heap); return ret; } /* create new content info struct ... possible OID sanity check? */ ci = (ContentInfo*)XMALLOC(sizeof(ContentInfo), pkcs12->heap, DYNAMIC_TYPE_PKCS); if (ci == NULL) { freeSafe(safe, pkcs12->heap); return MEMORY_E; } ci->type = oid; ci->dataSz = curSz - (localIdx-curIdx); ci->data = (byte*)input + localIdx; localIdx += ci->dataSz; #ifdef WOLFSSL_DEBUG_PKCS12 switch (oid) { case WC_PKCS12_ENCRYPTED_DATA: printf("CONTENT INFO: ENCRYPTED DATA, size = %d\n", ci->dataSz); break; case WC_PKCS12_DATA: printf("CONTENT INFO: DATA, size = %d\n", ci->dataSz); break; default: printf("CONTENT INFO: UNKNOWN, size = %d\n", ci->dataSz); } #endif /* insert to head of list */ ci->next = safe->CI; safe->CI = ci; safe->numCI += 1; } } pkcs12->safe = safe; *idx += localIdx; return 1; }
/*---------------- to assign local id to identical chain ---------------*/ NcbiMimeAsn1Ptr CheckId(NcbiMimeAsn1Ptr pvnNcbi, CharPtr JobID) { /* to assign local id to identical chain so that to work around */ /* object manager for messaging */ /* yanli */ BiostrucAlignPtr pbsaStruct = NULL; BiostrucPtr pbsMaster = NULL, pbsSlaveHead = NULL; BiostrucAnnotSetPtr pbsaThis = NULL, pbsaHead = NULL; SeqAnnotPtr psaAlignHead = NULL; SeqEntryPtr sepHead; BiostrucFeatureSetPtr pbsfsThis = NULL, pbsfsHead = NULL; BiostrucFeaturePtr pbsfThis = NULL, pbsfHead = NULL; SeqAlignPtr salpHead; SeqIdPtr sip, sip_cpy, sipMaster, sip_temp; ObjectIdPtr oipMaster, oip; Int4 iCount1 = 0, iCount_ID = 0; Boolean IdChainFound = FALSE; CharPtr pSegmentSlave; Char PDBName[Local_max], Chain, Domain; Char AlignIdStr[Local_max]; Int4 AlignId; typedef struct local_string{ Char str[Local_max]; }Local_String, PNTR Local_StringPtr; Local_String **str; pvnNcbi = ScreenSequence(pvnNcbi, JobID); pbsaStruct = pvnNcbi->data.ptrvalue; pbsaThis = pbsaStruct->alignments; pbsSlaveHead = pbsaStruct->slaves; sepHead = pbsaStruct->sequences; psaAlignHead = pbsaStruct->seqalign; pbsfsThis = pbsaThis->features; pbsfThis = pbsfsThis->features; /* from vastsrv page, we are always considering one */ /* domain of the master, so no loop for pbsfsThis */ StringNCpy(pSegmentMaster, pbsfThis->name, 6); pSegmentMaster[6]='\0'; /*pSegmentMaster[0]=pbsfThis->name[0]; pSegmentMaster[1]=pbsfThis->name[1]; pSegmentMaster[2]=pbsfThis->name[2]; pSegmentMaster[3]=pbsfThis->name[3]; pSegmentMaster[4]=pbsfThis->name[4]; pSegmentMaster[5]=pbsfThis->name[5]; pSegmentMaster[6]='\0'; */ /* see if Master Sequence was generated by VastSearch - Ken*/ if (JobID) { for (salpHead = psaAlignHead->data; salpHead; salpHead = salpHead->next) { oipMaster = ObjectIdNew(); oipMaster = GetObjectId(pbsaStruct->master, pSegmentMaster); sipMaster = ValNodeNew(NULL); sipMaster->choice = SEQID_LOCAL; sipMaster->data.ptrvalue = oipMaster; AssignLocaIdToSeqAlignMaster(sipMaster, salpHead); } } salpHead = psaAlignHead->data; /* from SeqAnnot to SeqAlign */ sepHead = sepHead->next; /* go to the slave sequences */ iCount1 = 0; while(pbsfThis){ pSegmentSlave = StringSave(&pbsfThis->name[7]); pSegmentSlave[6]='\0'; IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1); if(IdChainFound) iCount_ID++; iCount1++; MemFree(pSegmentSlave); pbsfThis = pbsfThis->next; } str = (Pointer) MemNew((size_t) ((iCount_ID + 1) * sizeof(Pointer))); for(iCount1 = 0; iCount1 < iCount_ID; iCount1++){ str[iCount1] = (Local_StringPtr) MemNew(sizeof(Local_String)); } pbsfThis = pbsfsThis->features; iCount_ID = 0; iCount1 = 0; while(pbsfThis){ pSegmentSlave = StringSave(&pbsfThis->name[7]); pSegmentSlave[6]='\0'; /* pSegmentSlave[0]=pbsfThis->name[7]; pSegmentSlave[1]=pbsfThis->name[8]; pSegmentSlave[2]=pbsfThis->name[9]; pSegmentSlave[3]=pbsfThis->name[10]; pSegmentSlave[4]=pbsfThis->name[11]; pSegmentSlave[5]=pbsfThis->name[12]; pSegmentSlave[6]='\0'; */ IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1); if(IdChainFound){ StringNCpy(str[iCount_ID]->str, pSegmentSlave, 4); str[iCount_ID]->str[4] = ' '; str[iCount_ID]->str[5] = pSegmentSlave[4]; str[iCount_ID]->str[6] = ' '; str[iCount_ID]->str[7] = pSegmentSlave[5]; str[iCount_ID]->str[8] = '\0'; AlignId = (Int2) (pbsfThis->id % 10) ; /* clique number */ sprintf(AlignIdStr, "%d", AlignId); str[iCount_ID]->str[8] = ' '; str[iCount_ID]->str[9] = '\0'; StringCat(str[iCount_ID]->str, AlignIdStr); sip_cpy = MakeLocalId(str[iCount_ID]->str); iCount_ID++; /* oip = ObjectIdNew(); oip->str = str; sip = ValNodeNew(NULL); sip->choice = SEQID_LOCAL; sip->data.ptrvalue = oip; sip_cpy = AsnIoMemCopy(sip, (AsnReadFunc) SeqIdAsnRead, (AsnWriteFunc) SeqIdAsnWrite); */ StringNCpy(PDBName, pSegmentSlave, 4); Chain = pSegmentSlave[4]; AssignLocaIdToBiostruc(sip_cpy, PDBName, Chain, pbsSlaveHead); AssignLocaIdToBioseq(sip_cpy, PDBName, Chain, sepHead); AssignLocaIdToSeqAlign(sip_cpy, PDBName, Chain, salpHead); } MemFree(pSegmentSlave); pbsfThis = pbsfThis->next; iCount1++; if(pbsSlaveHead) pbsSlaveHead = pbsSlaveHead->next; if(sepHead) sepHead = sepHead->next; if(salpHead) salpHead = salpHead->next; } return (pvnNcbi); }
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, MemoryPermission other_permissions) { MemoryPermission own_other_permissions = target_process == owner_process ? this->permissions : this->other_permissions; // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { return ERR_INVALID_COMBINATION; } // Error out if the requested permissions don't match what the creator process allows. if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", GetObjectId(), address, name.c_str()); return ERR_INVALID_COMBINATION; } // Heap-backed memory blocks can not be mapped with other_permissions = DontCare if (base_address != 0 && other_permissions == MemoryPermission::DontCare) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", GetObjectId(), address, name.c_str()); return ERR_INVALID_COMBINATION; } // Error out if the provided permissions are not compatible with what the creator process needs. if (other_permissions != MemoryPermission::DontCare && static_cast<u32>(this->permissions) & ~static_cast<u32>(other_permissions)) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", GetObjectId(), address, name.c_str()); return ERR_WRONG_PERMISSION; } // TODO(Subv): Check for the Shared Device Mem flag in the creator process. /*if (was_created_with_shared_device_mem && address != 0) { return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); }*/ // TODO(Subv): The same process that created a SharedMemory object // can not map it in its own address space unless it was created with addr=0, result 0xD900182C. if (address != 0) { if (address < Memory::HEAP_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) { LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, invalid address", GetObjectId(), address, name.c_str()); return ERR_INVALID_ADDRESS; } } VAddr target_address = address; if (base_address == 0 && target_address == 0) { // Calculate the address at which to map the memory block. target_address = Memory::PhysicalToVirtualAddress(linear_heap_phys_address).value(); } // Map the memory block into the target process auto result = target_process->vm_manager.MapMemoryBlock( target_address, backing_block, backing_block_offset, size, MemoryState::Shared); if (result.Failed()) { LOG_ERROR( Kernel, "cannot map id=%u, target_address=0x%08X name=%s, error mapping to virtual memory", GetObjectId(), target_address, name.c_str()); return result.Code(); } return target_process->vm_manager.ReprotectRange(target_address, size, ConvertPermissions(permissions)); }