void ViewerCmdLine::parse() { const CmdLineOption options[] = { HELP, HELP_SHORT, OPTIONS_FILE, LISTEN, HOST, PORT, PASSWORD, SHOW_CONTROLS, VIEW_ONLY, USE_CLIPBOARD, SCALE, FULL_SCREEN, WARN_FULL_SCREEN, ENCODING, COPY_RECT, MOUSE_CURSOR, MOUSE_LOCAL, MOUSE_SWAP, JPEG_IMAGE_QUALITY, COMPRESSION_LEVEL }; if (!processCmdLine(&options[0], sizeof(options) / sizeof(CmdLineOption))) { throw CommandLineFormatException(); } if (isHelpPresent()) { throw CommandLineFormatHelp(); } if (m_wpcl.getArgumentsCount() > 2) { throw CommandLineFormatException(); } if (m_wpcl.getArgumentsCount() > 1) { if (isPresent(ViewerCmdLine::HOST)) { throw CommandLineFormatException(); } } if (isPresent(ViewerCmdLine::OPTIONS_FILE)) { parseOptionsFile(); } else { if (isPresent(ViewerCmdLine::LISTEN)) { *m_isListening = true; } else { if (!parseHost()) { throw CommandLineFormatException(); } } } parsePassword(); parseEncoding(); parseMouseShape(); parseMouseCursor(); parseScale(); parseFullScreen(); parseCompressionLevel(); parseWarnFullScr(); parseMouseSwap(); parseUseClipboard(); parseShowControl(); parseCopyRect(); parseViewOnly(); parseJpegImageQuality(); }
// @mfunc Attempt to read the number of elements given by // <p elementCount> and described by <p elementType> and // <p externalElementSize> from the data stream into the buffer // at address <p elements>. The actual number of elements read // is returned in <p elementsRead>. // @parm The element type // @parm The external element size // @parm The address of the buffer into which the elements should be read. // @parm The number of elements to read. // @parm The actual number of elements that were read. // @this const void OMDataStreamProperty::readTypedElements(const OMType* elementType, OMUInt32 externalElementSize, OMByte* elements, OMUInt32 elementCount, OMUInt32& elementsRead) const { TRACE("OMDataStreamProperty::readTypedElements"); PRECONDITION("Optional property is present", IMPLIES(isOptional(), isPresent())); PRECONDITION("Valid element type", elementType != 0); PRECONDITION("Valid element size", externalElementSize!= 0); PRECONDITION("Valid buffer", elements != 0); PRECONDITION("Valid element count", elementCount > 0); PRECONDITION("Stream byte order is known", hasByteOrder()); OMUInt64 currentPosition = position(); OMUInt64 streamSize = size(); OMUInt32 readCount = 0; if (currentPosition < streamSize) { OMUInt64 remaining = (streamSize - currentPosition) / externalElementSize; if (remaining < elementCount) { readCount = static_cast<OMUInt32>(remaining); } else { readCount = elementCount; } } if (readCount > 0) { bool reorder = false; if (byteOrder() != hostByteOrder()) { reorder = true; } // Allocate buffer for one element OMByte* buffer = new OMByte[externalElementSize]; for (OMUInt32 i = 0; i < readCount; i++) { // Read an element of the property value OMUInt32 actualByteCount; read(buffer, externalElementSize, actualByteCount); ASSERT("All bytes read", actualByteCount == externalElementSize); // Reorder an element of the property value if (reorder) { elementType->reorder(buffer, externalElementSize); } // Internalize an element of the property value OMUInt32 requiredBytesSize = elementType->internalSize( buffer, externalElementSize); elementType->internalize(buffer, externalElementSize, &elements[i * requiredBytesSize], requiredBytesSize, hostByteOrder()); } delete [] buffer; } elementsRead = readCount; }
/* * Function: sva_ghost_fault() * * Description: * Handle page faults of ghost memory pages. * * Inputs: * vaddr - The virtual address of the faulting ghost memory page. * code - The page fault code. * */ void sva_ghost_fault (uintptr_t vaddr, unsigned long code) { /* Old interrupt flags */ uintptr_t rflags; /* * Disable interrupts. */ rflags = sva_enter_critical(); /* Physical address of allocated secure memory pointer */ uintptr_t sp; /* The address of the PML4e page table */ pml4e_t pml4e; /* * Get the current interrupt context; the arguments will be in it. */ struct CPUState * cpup = getCPUState(); struct SVAThread * threadp = cpup->currentThread; /* copy-on-write page fault */ if((code & PGEX_P) && (code & PGEX_W)){ pml4e_t * pml4e_ptr = get_pml4eVaddr (get_pagetable(), vaddr); if(!isPresent (pml4e_ptr)) panic("sva_ghost_fault: cow pgfault pml4e %p does not exist\n", pml4e); pdpte_t * pdpte = get_pdpteVaddr (pml4e_ptr, vaddr); if(!isPresent (pdpte)) panic("sva_ghost_fault: cow pgfault pdpte %p does not exist\n", pdpte); pde_t * pde = get_pdeVaddr (pdpte, vaddr); if(!isPresent (pde)) panic("sva_ghost_fault: cow pgfault pde %p does not exist\n", pde); pte_t * pte = get_pteVaddr (pde, vaddr); uintptr_t paddr = *pte & PG_FRAME; page_desc_t * pgDesc = getPageDescPtr (paddr); if(pgDesc->type != PG_GHOST) panic("SVA: sva_ghost_fault: vaddr = 0x%lx paddr = 0x%lx is not a ghost memory page!\n", vaddr, paddr); /* If only one process maps this page, directly grant this process write permission */ if(pgDesc->count == 1) { * pte = (* pte) | PTE_CANWRITE; } /* Otherwise copy-on-write */ else { uintptr_t vaddr_old = (uintptr_t) getVirtualSVADMAP(paddr); uintptr_t paddr_new = alloc_frame(); page_desc_t * pgDesc_new = getPageDescPtr (paddr_new); if (pgRefCount (pgDesc_new) > 1) { panic ("SVA: Ghost page still in use somewhere else!\n"); } if (isPTP(pgDesc_new) || isCodePG (pgDesc_new)) { panic ("SVA: Ghost page has wrong type!\n"); } memcpy(getVirtualSVADMAP(paddr_new), (void *) vaddr_old, X86_PAGE_SIZE); *pte = (paddr_new & addrmask) | PTE_CANWRITE | PTE_CANUSER | PTE_PRESENT; invlpg(vaddr); getPageDescPtr (paddr_new)->type = PG_GHOST; getPageDescPtr (paddr_new)->count = 1; pgDesc->count --; } return; } /* * Determine if this is the first secure memory allocation. */ unsigned char firstSecAlloc = (threadp->secmemSize == 0); /* * Get a page of memory from the operating system. Note that the OS provides * the physical address of the allocated memory. */ if ((sp = alloc_frame()) != 0) { /* Physical address of the allocated page */ uintptr_t paddr = (uintptr_t) sp; /* * Map the memory into a part of the address space reserved for secure * memory. */ pml4e = mapSecurePage ((uintptr_t)vaddr, paddr); /* * If this is the first piece of secure memory that we've allocated, * record the address of the top-level page table that maps in the secure * memory region. The context switching intrinsics will want to know * where this entry is so that it can quickly enable and disable it on * context switches. */ if (firstSecAlloc) { threadp->secmemPML4e = pml4e; } } else { panic ("SVA: Kernel secure memory allocation failed!\n"); } /* * Zero out the ghost memory contents. */ memset ((void *)vaddr, 0, X86_PAGE_SIZE); /* Re-enable interrupts if necessary */ sva_exit_critical (rflags); return; }
std::string Card::toString() const { return isPresent() ? presentString() : notPresentString(); }
void ItemStorage<Class>::remove( Class* pClass ) { if ( isPresent(pClass) ) m_cSet.erase( pClass ); }
void ViewerCmdLine::parsePassword() { if (isPresent(PASSWORD)) { m_conData->setPlainPassword(&m_options[PASSWORD]); } }
int inspectInputBlock(SpMatrix *m, unsigned int **inputList, unsigned int **rowIndices, unsigned int **indices, unsigned int *numblocks, unsigned int *inputListCount, unsigned int bsx, unsigned int bsy) { unsigned int nblocks=0, nblocksPerRowBlock; unsigned int nrows = m->numRows; unsigned int ncols = m->numCols; unsigned int *lb = (unsigned int *)malloc(sizeof(int)*bsx); unsigned int *ub = (unsigned int *)malloc(sizeof(int)*bsx); unsigned int *bptr = (unsigned int *)malloc(sizeof(int)*bsx); unsigned int *inpListRowBlock = (unsigned int *)malloc(sizeof(int)*bsx*bsy); *rowIndices = (unsigned int *)malloc(sizeof(int)*((int)ceild(nrows,bsx)+1)); unsigned int it, iti; unsigned int maxNZPerRowBlock; // for each block of row for (it = 0, iti = 0; it < nrows; it += bsx, iti++) { // start of a row block (*rowIndices)[iti]=nblocks; maxNZPerRowBlock=0; for (unsigned int i = it; i < min(it+bsx,nrows); i++) { if (i==(nrows-1)) maxNZPerRowBlock = max(maxNZPerRowBlock,(m->numNZEntries-(m->rowPtrs)[i])); else maxNZPerRowBlock = max(maxNZPerRowBlock,((m->rowPtrs)[i+1]-(m->rowPtrs)[i])); } nblocks += (int) ceild(maxNZPerRowBlock,bsy); } (*rowIndices)[iti]=nblocks; *numblocks = nblocks; *indices = (unsigned int *)malloc(sizeof(int)*(nblocks+1)); unsigned int countPerBlock,countInputList=0; nblocks=0; // for each block of row for (it = 0, iti = 0; it < nrows; it += bsx, iti++) { // start of a row block maxNZPerRowBlock=0; for (unsigned int i = it; i < min(it+bsx,nrows); i++) { lb[i-it] = (m->rowPtrs)[i]; if (i==(nrows-1)) ub[i-it] = m->numNZEntries-1; else ub[i-it] = (m->rowPtrs)[i+1]-1; maxNZPerRowBlock = max(maxNZPerRowBlock,ub[i-it]-lb[i-it]+1); bptr[i-it] = lb[i-it]; } nblocksPerRowBlock = (int) ceild(maxNZPerRowBlock,bsy); // for each block of column within a row block for (unsigned int jt = 0, jti = 0; jt < nblocksPerRowBlock; jt += bsy, jti++,nblocks++) { (*indices)[nblocks]=countInputList; countPerBlock=0; for (unsigned int i = it; i < min(it+bsx,nrows); i++) { unsigned int j = bptr[i-it]; for (; j <= min(bptr[i-it]+bsy-1,ub[i-it]); j++) { unsigned int cInd = (m->nzentries)[j].colNum; if (i==it) inpListRowBlock[countPerBlock++]=cInd; else { if (!isPresent(inpListRowBlock,countPerBlock,cInd)) inpListRowBlock[countPerBlock++]=cInd; } } bptr[i-it] = j; } countInputList += countPerBlock; } } (*indices)[nblocks]=countInputList; *inputList = (unsigned int *)malloc(sizeof(int)*countInputList); *inputListCount = countInputList; countInputList = 0; nblocks=0; // for each block of row for (it = 0, iti = 0; it < nrows; it += bsx, iti++) { // start of a row block maxNZPerRowBlock=0; for (unsigned int i = it; i < min(it+bsx,nrows); i++) { lb[i-it] = (m->rowPtrs)[i]; if (i==(nrows-1)) ub[i-it] = m->numNZEntries-1; else ub[i-it] = (m->rowPtrs)[i+1]-1; maxNZPerRowBlock = max(maxNZPerRowBlock,ub[i-it]-lb[i-it]+1); bptr[i-it] = lb[i-it]; } nblocksPerRowBlock = (int) ceild(maxNZPerRowBlock,bsy); // for each block of column within a row block for (unsigned int jt = 0, jti = 0; jt < nblocksPerRowBlock; jt += bsy, jti++,nblocks++) { countPerBlock=0; for (unsigned int i = it; i < min(it+bsx,nrows); i++) { unsigned int j = bptr[i-it]; for (; j <= min(bptr[i-it]+bsy-1,ub[i-it]); j++) { unsigned int cInd = (m->nzentries)[j].colNum; if (i==it) inpListRowBlock[countPerBlock++]=cInd; else { if (!isPresent(inpListRowBlock,countPerBlock,cInd)) inpListRowBlock[countPerBlock++]=cInd; } } bptr[i-it] = j; } //Sort inpListRowBlock sort(inpListRowBlock,countPerBlock); if ( (countPerBlock > (bsx*bsy/2)) && (inpListRowBlock[countPerBlock-1] - inpListRowBlock[0] <512) ) { for (int k=0;k<countPerBlock;k++) (*inputList)[countInputList+k]=inpListRowBlock[k]; } else { for (int k=0;k<countPerBlock;k++) //(*inputList)[countInputList+k]=inpListRowBlock[k]; (*inputList)[countInputList+k]=ncols; } countInputList += countPerBlock; } } free(inpListRowBlock); free(lb); free(ub); free(bptr); return 0; }
bool isPresent(const Instruction *inst, std::vector<BlockVector *> &value) { for (auto Iter = value.begin(), E = value.end(); Iter != E; ++Iter) if (isPresent(inst, **Iter)) return true; return false; }
QPCSCReader::QPCSCReader( const QString &reader, QPCSC *parent ) : QObject( parent ) , d( new QPCSCReaderPrivate( parent->d ) ) { d->reader = reader.toUtf8(); d->state.szReader = d->reader.constData(); if( !d->updateState() ) return; /* Use DIRECT mode only if there is no card in the reader */ if( !isPresent() ) { #ifndef Q_OS_WIN /* Apple 10.5.7 and pcsc-lite previous to v1.5.5 do not support 0 as protocol identifier */ DWORD proto = SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1; #else DWORD proto = 0; #endif LONG rv = SCardConnect( d->d->context, d->state.szReader, SCARD_SHARE_DIRECT, proto, &d->card, &d->proto ); // Assume that there is a card in the reader in shared mode if direct communcation failed if( rv == LONG(SCARD_E_SHARING_VIOLATION) && !connect() ) return; } else if( !connect() ) return; d->friendlyName = d->attrib( SCARD_ATTR_DEVICE_FRIENDLY_NAME_A ); #if 0 qDebug() << "SCARD_ATTR_DEVICE_FRIENDLY_NAME:" << d->attrib( SCARD_ATTR_DEVICE_FRIENDLY_NAME_A ); qDebug() << "SCARD_ATTR_DEVICE_SYSTEM_NAME:" << d->attrib( SCARD_ATTR_DEVICE_SYSTEM_NAME_A ); qDebug() << "SCARD_ATTR_DEVICE_UNIT:" << d->attrib( SCARD_ATTR_DEVICE_UNIT ); qDebug() << "SCARD_ATTR_VENDOR_IFD_SERIAL_NO:" << d->attrib( SCARD_ATTR_VENDOR_IFD_SERIAL_NO ); qDebug() << "SCARD_ATTR_VENDOR_IFD_TYPE:" << d->attrib( SCARD_ATTR_VENDOR_IFD_TYPE ); qDebug() << "SCARD_ATTR_VENDOR_IFD_VERSION:" << d->attrib( SCARD_ATTR_VENDOR_IFD_VERSION ); qDebug() << "SCARD_ATTR_VENDOR_NAME:" << d->attrib( SCARD_ATTR_VENDOR_NAME ); #endif DWORD size = 0; BYTE feature[256]; LONG rv = SCardControl( d->card, CM_IOCTL_GET_FEATURE_REQUEST, 0, 0, feature, sizeof(feature), &size ); if( rv == SCARD_S_SUCCESS && (size % sizeof(PCSC_TLV_STRUCTURE)) == 0 ) { size /= sizeof(PCSC_TLV_STRUCTURE); PCSC_TLV_STRUCTURE *pcsc_tlv = (PCSC_TLV_STRUCTURE *)feature; for( DWORD i = 0; i < size; i++ ) d->ioctl[DRIVER_FEATURES(pcsc_tlv[i].tag)] = ntohl( pcsc_tlv[i].value ); } if( DWORD ioctl = d->ioctl.value(FEATURE_GET_TLV_PROPERTIES) ) { DWORD size = 0; BYTE recv[256]; rv = SCardControl( d->card, ioctl, 0, 0, recv, sizeof(recv), &size ); unsigned char *p = recv; while( DWORD(p-recv) < size ) { int tag = *p++, len = *p++, value = -1; switch( len ) { case 1: value = *p; break; case 2: value = *p + (*(p+1)<<8); break; case 4: value = *p + (*(p+1)<<8) + (*(p+2)<<16) + (*(p+3)<<24); break; default: break; } p += len; d->properties[Properties(tag)] = value; } } if( DWORD ioctl = d->ioctl.value(FEATURE_IFD_PIN_PROPERTIES) ) { DWORD size = 0; BYTE recv[256]; DWORD rv = SCardControl( d->card, ioctl, 0, 0, recv, sizeof(recv), &size ); if( rv == SCARD_S_SUCCESS ) { PIN_PROPERTIES_STRUCTURE *caps = (PIN_PROPERTIES_STRUCTURE *)recv; d->display = caps->wLcdLayout > 0; } } disconnect(); }