void SearchManager::startSearch(KURL const& root, SearchMode const& modo) { canceled_ = false; //time_.restart(); time_.start(); Q_ASSERT(root.isValid()); //Q_ASSERT(root.protocol() == "http" || root.protocol() == "https"); if(root.hasHost() && (domain_.isNull() || domain_.isEmpty())) { setDomain(root.host() + root.directory()); kdDebug(23100) << "Domain: " << domain_ << endl; } root_.setIsRoot(true); root_.setDepth(0); root_.setOriginalUrl(root.prettyURL()); root_.setAbsoluteUrl(root); root_.setOnlyCheckHeader(false); root_.setRootUrl(root); search_mode_ = modo; if(modo == depth) Q_ASSERT(depth_ != -1); else if(modo == domain) Q_ASSERT(depth_ == -1); else Q_ASSERT(depth_ != -1); searching_ = true; //Q_ASSERT(domain_ != QString::null); checkRoot(); }
int main(int argc, char *argv[]) { if (DBG_POINTERS_AND_ARRAYS) { bitmap = malloc(sizeof(ushort) * 10); bitmap[0] = 2; bitmap[1] = 3; printf("[0]: %u\n", bitmap[0]); printf("[1]: %u\n", bitmap[1]); printf("*bitmap: %u\n", *bitmap); printf("++*bitmap: %u\n", ++*bitmap); exit(0); } if (argc != 2) ezErr("usage: fscheck file_system_image"); struct stat buf; if (stat(argv[1], &buf) != 0) ezErr("image not found."); if (DBG_FL_SIZE) { printf("img file size: %lu\n", buf.st_size); } fd = open(argv[1], O_RDONLY); if (fd < 0) ezErr("image not found."); imgPtr = mmap(NULL, buf.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (imgPtr == MAP_FAILED) { ezErr("mmap failed"); } checkSuperBlock(); if (DBG_INODE_ADDRESSES) iNodeAddressStuff(); checkRoot(); parseOneINode(1, 1); close(fd); return 0; }
void Darling::binfmtRegister(const char* loader) { checkRoot(); std::ofstream reg("/proc/sys/fs/binfmt_misc/register"); if (!reg.is_open()) throw std::runtime_error("Cannot register the binfmt_misc handler, is binfmt_misc kernel support loaded and mounted?"); #if defined(__x86_64__) || defined(__powerpc64__) reg << ":Mach-O 64bit:M::\\xcf\\xfa\\xed\\xfe::" << loader << ":\n"; #elif defined(__i386__) || defined(__powerpc__) || defined(__arm__) reg << ":Mach-O 32bit:M::\\xce\\xfa\\xed\\xfe::" << loader << ":\n"; #else # error Unuspported platform #endif reg.close(); // In multilib environments, register FAT Mach-O files with dyld64 only #if !defined(MULTILIB) reg.open("/proc/sys/fs/binfmt_misc/register"); reg << ":Mach-O Universal:M::\\xca\\xfe\\xba\\xbe::" << loader << ":\n"; reg.close(); #elif defined(__x86_64__) || defined(__powerpc64__) { std::string universalLoader = loader; universalLoader.resize(universalLoader.size() - 2); reg.open("/proc/sys/fs/binfmt_misc/register"); reg << ":Mach-O Universal:M::\\xca\\xfe\\xba\\xbe::" << universalLoader.c_str() << ":\n"; reg.close(); } #endif }
void Darling::binfmtDeregister() { checkRoot(); deregister("Mach-O Universal"); if (sizeof(void*) == 8) deregister("Mach-O 64bit"); else deregister("Mach-O 32bit"); }
// [START iot_mqtt_run] int main(int argc, char* argv[]) { // check if running as root checkRoot(); OpenSSL_add_all_algorithms(); OpenSSL_add_all_digests(); OpenSSL_add_all_ciphers(); if (GetOpts(argc, argv)) { Publish(opts.payload, strlen(opts.payload)); } else { Usage(); } EVP_cleanup(); }
TObject* SmalltalkVM::performPrimitive(uint8_t opcode, hptr<TProcess>& process, TVMExecutionContext& ec, bool& failed) { switch (opcode) { // FIXME opcodes 253-255 are not standard case 255: // Debug trap std::printf("Debug trap\n"); break; case 254: m_memoryManager->collectGarbage(); break; #if defined(LLVM) case primitive::LLVMsendMessage: { //252 TObjectArray* args = ec.stackPop<TObjectArray>(); TSymbol* selector = ec.stackPop<TSymbol>(); try { return sendMessage(ec.currentContext, selector, args, 0); } catch(TBlockReturn& blockReturn) { //When we catch blockReturn we change the current context to block.creatingContext. //The post processing code will change 'block.creatingContext' to the previous one // and the result of blockReturn will be injected on the stack ec.currentContext = blockReturn.targetContext; return blockReturn.value; } catch(TContext* errorContext) { //context is thrown by LLVM:throwError primitive //that means that it was not caught by LLVM:executeProcess function //so we have to stop execution of the current process and return returnError process->context = errorContext; failed = true; return globals.nilObject; } } break; case 247: { // Jit once: aBlock try { TBlock* const block = ec.stackPop<TBlock>(); return JITRuntime::Instance()->invokeBlock(block, ec.currentContext, true); } catch(TBlockReturn& blockReturn) { ec.currentContext = blockReturn.targetContext; return blockReturn.value; } catch(TContext* errorContext) { process->context = errorContext; failed = true; return globals.nilObject; } } #endif case 251: { // TODO Unicode support TString* prompt = ec.stackPop<TString>(); std::string strPrompt(reinterpret_cast<const char*>(prompt->getBytes()), prompt->getSize()); std::string input; bool userInsertedAnything = CompletionEngine::Instance()->readline(strPrompt, input); if ( userInsertedAnything ) { if ( !input.empty() ) CompletionEngine::Instance()->addHistory(input); TString* result = static_cast<TString*>( newBinaryObject(globals.stringClass, input.size()) ); std::memcpy(result->getBytes(), input.c_str(), input.size()); return result; } else return globals.nilObject; } break; #if defined(LLVM) case 250: // patchHotMethods JITRuntime::Instance()->patchHotMethods(); break; case 249: { // printMethod TMethod* method = ec.stackPop<TMethod>(); JITRuntime::Instance()->printMethod(method); } break; case 248: JITRuntime::Instance()->printStat(); break; #endif case primitive::startNewProcess: { // 6 TInteger ticks = ec.stackPop(); TProcess* newProcess = ec.stackPop<TProcess>(); // FIXME possible stack overflow due to recursive call TExecuteResult result = this->execute(newProcess, ticks); return TInteger(result); } break; case primitive::allocateObject: { // 7 // Taking object's size and class from the stack TObject* size = ec.stackPop(); TClass* klass = ec.stackPop<TClass>(); uint32_t fieldsCount = TInteger(size); // Instantinating the object. Each object has size and class fields return newOrdinaryObject(klass, sizeof(TObject) + fieldsCount * sizeof(TObject*)); } break; case primitive::blockInvoke: { // 8 TBlock* block = ec.stackPop<TBlock>(); uint32_t argumentLocation = block->argumentLocation; // Amount of arguments stored on the stack except the block itself uint32_t argCount = ec.instruction.getArgument() - 1; // Checking the passed temps size TObjectArray* blockTemps = block->temporaries; if (argCount > (blockTemps ? blockTemps->getSize() - argumentLocation : 0) ) { ec.stackTop -= (argCount + 1); // unrolling stack failed = true; break; } // Loading temporaries array for (uint32_t index = argCount - 1, count = argCount; count > 0; index--, count--) (*blockTemps)[argumentLocation + index] = ec.stackPop(); // Switching execution context to the invoking block block->previousContext = ec.currentContext->previousContext; ec.currentContext = static_cast<TContext*>(block); ec.stackTop = 0; // resetting stack // Block is bound to the method's bytecodes, so it's // first bytecode will not be zero but the value specified ec.bytePointer = block->blockBytePointer; return block; } break; case primitive::throwError: // 19 process->context = ec.currentContext; process->result = ec.returnedValue; break; case primitive::allocateByteArray: { // 20 TInteger dataSize = ec.stackPop(); TClass* klass = ec.stackPop<TClass>(); return newBinaryObject(klass, dataSize); } break; case primitive::arrayAt: // 24 case primitive::arrayAtPut: { // 5 TObject* indexObject = ec.stackPop(); TObjectArray* array = ec.stackPop<TObjectArray>(); TObject* valueObject = 0; // If the method is Array:at:put then pop a value from the stack if (opcode == primitive::arrayAtPut) valueObject = ec.stackPop(); if (! isSmallInteger(indexObject) ) { failed = true; break; } // Smalltalk indexes arrays starting from 1, not from 0 // So we need to recalculate the actual array index before uint32_t actualIndex = TInteger(indexObject) - 1; // Checking boundaries if (actualIndex >= array->getSize()) { failed = true; break; } if (opcode == primitive::arrayAt) { return array->getField(actualIndex); } else { // Array:at:put TObject** objectSlot = &( array->getFields()[actualIndex] ); // Checking whether we need to register current object slot in the GC checkRoot(valueObject, objectSlot); // Storing the value into the array array->putField(actualIndex, valueObject); // Return self return static_cast<TObject*>(array); } } break; case primitive::cloneByteObject: { // 23 TClass* klass = ec.stackPop<TClass>(); hptr<TByteObject> original = newPointer( ec.stackPop<TByteObject>() ); // Creating clone uint32_t dataSize = original->getSize(); TByteObject* clone = newBinaryObject(klass, dataSize); // Cloning data std::memcpy(clone->getBytes(), original->getBytes(), dataSize); return static_cast<TObject*>(clone); } break; // case primitive::integerDiv: // Integer / // case primitive::integerMod: // Integer % // case primitive::integerAdd: // Integer + // case primitive::integerMul: // Integer * // case primitive::integerSub: // Integer - // case primitive::integerLess: // Integer < // case primitive::integerEqual: // Integer == // //TODO integer operations // break; case primitive::integerNew: { // 32 TObject* object = ec.stackPop(); if (! isSmallInteger(object)) { failed = true; break; } return object; // FIXME long integer } break; case primitive::flushCache: // 34 flushMethodCache(); break; case primitive::bulkReplace: { // 38 //Implementation of replaceFrom:to:with:startingAt: as a primitive // Array replaceFrom: start to: stop with: replacement startingAt: repStart // <38 start stop replacement repStart self>. // Current stack contents (top is the top) // self // repStart // replacement // stop // start TObject* destination = ec.stackPop(); TObject* sourceStartOffset = ec.stackPop(); TObject* source = ec.stackPop(); TObject* destinationStopOffset = ec.stackPop(); TObject* destinationStartOffset = ec.stackPop(); bool isSucceeded = doBulkReplace( destination, destinationStartOffset, destinationStopOffset, source, sourceStartOffset ); if (! isSucceeded) { failed = true; break; } return destination; } break; // TODO cases 33, 35, 40 // TODO case 18 // turn on debugging case primitive::objectsAreEqual: // 1 case primitive::getClass: // 2 case primitive::getSize: // 4 case primitive::ioGetChar: // 9 case primitive::ioPutChar: // 3 case primitive::ioFileOpen: // 100 case primitive::ioFileClose: // 103 case primitive::ioFileSetStatIntoArray: // 105 case primitive::ioFileReadIntoByteArray: // 106 case primitive::ioFileWriteFromByteArray: // 107 case primitive::ioFileSeek: // 108 case primitive::stringAt: // 21 case primitive::stringAtPut: // 22 case primitive::smallIntAdd: // 10 case primitive::smallIntDiv: // 11 case primitive::smallIntMod: // 12 case primitive::smallIntLess: // 13 case primitive::smallIntEqual: // 14 case primitive::smallIntMul: // 15 case primitive::smallIntSub: // 16 case primitive::smallIntBitOr: // 36 case primitive::smallIntBitAnd: // 37 case primitive::smallIntBitShift: // 39 case primitive::getSystemTicks: //253 default: { uint32_t argCount = ec.instruction.getArgument(); hptr<TObjectArray> args = newObject<TObjectArray>(argCount); uint32_t i = argCount; while (i > 0) args[--i] = ec.stackPop(); TObject* result = callPrimitive(opcode, args, failed); return result; } } return globals.nilObject; }
SmalltalkVM::TExecuteResult SmalltalkVM::execute(TProcess* p, uint32_t ticks) { // Protecting the process pointer hptr<TProcess> currentProcess = newPointer(p); assert(currentProcess->context != 0); assert(currentProcess->context->method != 0); // Initializing an execution context TVMExecutionContext ec(m_memoryManager, this); ec.currentContext = currentProcess->context; ec.loadPointers(); // Loads bytePointer & stackTop while (true) { assert(ec.currentContext != 0); assert(ec.currentContext->method != 0); assert(ec.currentContext->stack != 0); assert(ec.bytePointer <= ec.currentContext->method->byteCodes->getSize()); assert(ec.currentContext->arguments->getSize() >= 1); assert(ec.currentContext->arguments->getField(0) != 0); // Initializing helper references TByteObject& byteCodes = * ec.currentContext->method->byteCodes; TObjectArray& temporaries = * ec.currentContext->temporaries; TObjectArray& arguments = * ec.currentContext->arguments; TObjectArray& instanceVariables = * arguments.getField<TObjectArray>(0); TSymbolArray& literals = * ec.currentContext->method->literals; if (ticks && (--ticks == 0)) { // Time frame expired ec.storePointers(); currentProcess->context = ec.currentContext; currentProcess->result = ec.returnedValue; return returnTimeExpired; } // Decoding the instruction const uint16_t lastBytePointer = ec.bytePointer; ec.instruction = st::InstructionDecoder::decodeAndShiftPointer(byteCodes, ec.bytePointer); // And executing it switch (ec.instruction.getOpcode()) { case opcode::pushInstance: ec.stackPush(instanceVariables[ec.instruction.getArgument()]); break; case opcode::pushArgument: ec.stackPush(arguments[ec.instruction.getArgument()]); break; case opcode::pushTemporary: ec.stackPush(temporaries[ec.instruction.getArgument()]); break; case opcode::pushLiteral: ec.stackPush(literals[ec.instruction.getArgument()]); break; case opcode::pushConstant: doPushConstant(ec); break; case opcode::pushBlock: doPushBlock(ec); break; case opcode::assignTemporary: temporaries[ec.instruction.getArgument()] = ec.stackLast(); break; case opcode::assignInstance: { TObject* newValue = ec.stackLast(); TObject** objectSlot = & instanceVariables[ec.instruction.getArgument()]; // Checking whether we need to register current object slot in the GC checkRoot(newValue, objectSlot); // Performing the assignment *objectSlot = newValue; } break; case opcode::markArguments: doMarkArguments(ec); break; case opcode::sendMessage: doSendMessage(ec); break; case opcode::sendUnary: doSendUnary(ec); break; case opcode::sendBinary: doSendBinary(ec); break; case opcode::doPrimitive: { TExecuteResult result = doPrimitive(currentProcess, ec); if (result != returnNoReturn) return result; } break; case opcode::doSpecial: { TExecuteResult result = doSpecial(currentProcess, ec); if (result != returnNoReturn) return result; } break; default: std::fprintf(stderr, "VM: Invalid opcode %d at offset %d in method ", ec.instruction.getOpcode(), lastBytePointer); std::fprintf(stderr, "'%s'\n", ec.currentContext->method->name->toString().c_str() ); std::exit(1); } } }
// check the set root of member x belonged to // parameter: // 1. x: given member // return value: set root int checkRoot(const int x) { int root = table[x]; if (root != x) { return (table[x] = checkRoot(root)); } else { return x; } }
int main(int argc,char* argv[]) { /***********************************DECLARATIONS***********************************/ char data_dir[100],filename[100],input_buffer[50]=""; extern int root; extern int pid,cpid,ppid; int fbfd,ioct,map,val=10; int* ofile,opfd; long frame_num=1,loop=1,read_count=0,reqd_frames,write_count=0,size; unsigned int i,j; unsigned int* fbuffer; struct fb_fix_screeninfo fscreeninfo; struct fb_var_screeninfo vscreeninfo; struct timeval finish,start; CommandData cmd; /**********************************~DECLARATIONS***********************************/ /***********************************INITITIALIZE***********************************/ gettimeofday(&start,NULL); initCommandData(&cmd); setCommandData(&cmd,argc,argv); if((argc<2) || (argc==2 && argv[1][0]=='-' && argv[1][1]=='h' && !argv[1][2])) { displayAppUsage(&cmd); displayAppInfo(&cmd); __android_log_print(ANDROID_LOG_INFO,TAG_INFO,"Displaying help menu"); return 0; } if(checkRoot()==0) { //return -1; } if((fbfd=open(cmd.data[KEY('c')],O_DIRECTORY))<0) { printD("Cannot open directory '%s'\n",cmd.data[KEY('c')]); __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "Cannot open directory '%s'",cmd.data[KEY('c')]); return 1; } __android_log_print(ANDROID_LOG_INFO,TAG_INFO,"Data Dir : %s",cmd.data[KEY('c')]); close(fbfd); fbfd=open(cmd.data[KEY('z')],O_RDONLY); if(fbfd==-1) { __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "Could not open framebuffer fbfd=%d errno=%d",fbfd,errno); return 2; } ioct=ioctl(fbfd,FBIOGET_VSCREENINFO,&vscreeninfo); if(ioct==-1) { __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "VSCREEN-IOCTL failed ioct=%d errno=%d",ioct,errno); return 3; } ioct=ioctl(fbfd,FBIOGET_FSCREENINFO,&fscreeninfo); if(ioct==-1) { __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "FSCREEN-IOCTL failed ioct=%d errno=%d",ioct,errno); return 4; } //cpid = ppid = pid = getpid(); //signal(SIGUSR1,sigcatcher); /**********************************~INITITIALIZE***********************************/ /**************************************MMAP()**************************************/ /*size = fscreeninfo.smem_len/2; fbuffer=(unsigned int*)mmap(0,size,PROT_READ,MAP_SHARED,fbfd,0); printD("Address: %x\n", fbuffer);*/ /*************************************~MMAP()**************************************/ /**************************************VSCREEN*************************************/ printD("\nVscreen Info:-\n"); printD(" Xres = %4ld | Yres = %4ld\n",vscreeninfo.xres,vscreeninfo.yres); printD(" BPP = %4ld | Height = %4ld | Width = %4ld\n",vscreeninfo.bits_per_pixel, vscreeninfo.height, vscreeninfo.width); printD(" Xres_V = %4ld | Yres_V = %4ld\n",vscreeninfo.height,vscreeninfo.width); printD(" Pixel format : RGBX_%ld%ld%ld%ld\n",vscreeninfo.red.length, vscreeninfo.green.length, vscreeninfo.blue.length, vscreeninfo.transp.length); printD(" Begin of bitfields:-\n"); printD(" Red : %ld\n",vscreeninfo.red.offset); printD(" Green : %ld\n",vscreeninfo.green.offset); printD(" Blue : %ld\n",vscreeninfo.blue.offset); i=1; while(i<=100000) { ioct=ioctl(fbfd,FBIOGET_VSCREENINFO,&vscreeninfo); if(ioct==-1) { __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "VSCREEN-IOCTL failed ioct=%d errno=%d",ioct,errno); //return 3; } printD("%8u %8u | %8u %8u | %8u %8u\r",vscreeninfo.xoffset,vscreeninfo.yoffset, vscreeninfo.hsync_len,vscreeninfo.vsync_len, vscreeninfo.sync,vscreeninfo.vmode); i++; } /*************************************~VSCREEN*************************************/ /**************************************FSCREEN*************************************/ printD("\nFscreen Info:-\n"); printD(" Device ID : %s\n",fscreeninfo.id); printD(" Start of FB physical address : %u\n",fscreeninfo.smem_start); printD(" Length of FB : %ld\n",fscreeninfo.smem_len); printD(" Length of Line : %ld\n",fscreeninfo.line_length); printD(" Start of MMIO physical address : %ld\n",fscreeninfo.mmio_start); printD(" Length of MMIO : %ld\n",fscreeninfo.mmio_len); /*************************************~FSCREEN*************************************/ /*************************************SPIN-LOCK************************************/ /*while(val!=VAL_EXIT && cpid && !cmd.print_status) { //fgets(input_buffer,sizeof(input_buffer),stdin); //fscanf(stdin,"%s",input_buffer); //fgetline(); //scanf("%s",input_buffer); val = VAL_REC;//getTokenValue(input_buffer); switch(val) { case VAL_CAP: printC(!cmd.print_status,"%d\n",VAL_CAP); return getFrame(&cmd,fbuffer,size,vscreeninfo.xres,vscreeninfo.yres); break; case VAL_EXIT: printC(!cmd.print_status,"%d\n",VAL_EXIT); //Do not do anything here break; case VAL_CST: printC(!cmd.print_status,"%d\n",VAL_CST); break; case VAL_REC: printC(!cmd.print_status,"%d\n",VAL_REC); if((cpid == ppid) && (ppid == pid)) { __android_log_print(ANDROID_LOG_INFO,TAG_INFO,"P: fork()ing..."); cpid = fork(); } if(cpid<0) { __android_log_print(ANDROID_LOG_ERROR,TAG_ERR,"P: fork() failed!"); break; } if(cpid) { //Parent code follows __android_log_print(ANDROID_LOG_INFO,TAG_INFO, "P: Parent(PID)=%d | Child(PID)=%d",ppid,cpid); exit(0); } else { //Child code follows gettimeofday(&start,NULL); pid = getpid(); __android_log_print(ANDROID_LOG_INFO,TAG_INFO, "C: I am the child(PID)=%d",pid); startRecording(&cmd,fbuffer,size); //kill(ppid,SIGUSR1); } break; case VAL_STOP: printC(!cmd.print_status,"%d\n",VAL_STOP); if(cpid!=ppid) { __android_log_print(ANDROID_LOG_INFO,TAG_INFO, "P: kill()ing child(PID)=%d",cpid); kill(cpid,SIGUSR1); cpid = ppid; } break; case VAL_UNDEF: //printf("UNDEF"); printC(!cmd.print_status,"%d\n",VAL_UNDEF); __android_log_print(ANDROID_LOG_ERROR,TAG_ERR, "Undefined input '%s'",input_buffer); return -1; break; } }*/ /************************************~SPIN-LOCK************************************/ /**********************************CLEANUP-WRAPUP**********************************/ __android_log_print(ANDROID_LOG_INFO,TAG_INFO,"Unmap = %d",/*munmap(fbuffer,size)*/0); close(fbfd); gettimeofday(&finish,NULL); printD("\nAll sys calls successfull\n"); __android_log_print(ANDROID_LOG_INFO,TAG_INFO, "All sys calls successfull"); printD("PID = %d | Lifespan = %ldseconds\n",pid,finish.tv_sec-start.tv_sec); /*********************************~CLEANUP-WRAPUP**********************************/ return 0; //End of Program }