/* a c based repl */ void repl_c(interp_core_type *interp) { load_main(interp); /* while the interpreter is running */ while(interp->running) { object_type *obj=0; printf(">"); obj=parse(interp, stdin); if(interp->running) { obj=eval(interp, obj); /* if there was no error, output the result */ if(has_error(interp)) { printf("There was an error executing the given expression"); output(interp, interp->exception ? interp->exception : obj); } else { output(interp, obj); } } printf("\n"); } }
Huint _create_system_thread( hthread_t *th, hthread_attr_t *attr, hthread_start_t start, void *arg ) { Huint threadStatus; Huint threadID; // Create the thread id for the new thread if( attr->detached ) threadStatus = _create_detached(); else threadStatus = _create_joinable(); // Check if there was an error while creating the new thread. If // there was then it means that all of the available threads are // being used, so we return an error. if( has_error(threadStatus) ) return EAGAIN; // If there was no error then we need to get the new thread's id // out of the return status. threadID = extract_id( threadStatus ); // Initialize the software structures used to keep track of the thread. _setup_thread( threadID, attr, start, arg ); // Set the scheduling parameter for the thread. _set_schedparam( threadID, attr->sched_param ); // Return the thread ID to the caller. At this point the thread has // been successfully created and added to the queue so that we know // a valid thread ID will be returned to the user. *th = threadID; // The thread was created and added to the ready-to-run queue // successfully. Return the success code. return SUCCESS; }
// Command line parsing std::pair<bool, etix::tool::opt_parse> parse_cmdline(int argc, char* argv[]) { auto opt_parse = etix::tool::opt_parse{ argc, argv }; opt_parse.optional("-c", "Path to the configuration file (-c /path/to/conf)", true); opt_parse.optional("-l", "Set log level (-l 4 will only show warnings and errors)", true); opt_parse.optional("-d", "Launch the discovery tool on the given subnet", false); opt_parse.optional("-b", "Launch the bruteforce tool on all discovered devices", false); opt_parse.optional("-t", "Generate thumbnails from detected cameras", false); opt_parse.optional("-g", "Check if the stream can be opened with GStreamer", false); opt_parse.optional("-v", "Display Cameradar's version", false); opt_parse.optional("-h", "Display this help", false); opt_parse.execute(); if (opt_parse.exist("-h")) { opt_parse.print_help(); return std::make_pair(false, opt_parse); } else if (opt_parse.exist("-v")) { print_version(); return std::make_pair(false, opt_parse); } else if (opt_parse.has_error()) { std::cout << "Usage: ./cameradar [option]\n\toptions:\n" << std::endl; opt_parse.print_help(); return std::make_pair(false, opt_parse); } return std::make_pair(true, opt_parse); }
void analyzer::start() { if( has_error() )return ; automata* NFAmata = regex_reader::getInstance()->get_nfa(rules_file); nfa_to_dfa* converter = nfa_to_dfa::get_instance(); DFA = converter->get_dfa(NFAmata); comp_f_stream.open(compile_file,ios_base::binary); }
/** \internal * \brief The system call that implements the htread_exit functionality. * * \author Wesley Peck <*****@*****.**> * * This function is the system call routine which implements the * hthread_exit functionality for hthreads. The user space function * hthread_exit invokes this function to terminate a thread. * * \param retval The return value of the thread. If the currently * running thread is in the joinable state then this * value is returned to the thread which joins with * the currently running thread, otherwise this * value is discarded. * \return This function never returns to the calling thread. */ void _syscall_exit( void *retval ) { Huint status; Huint current; Hbool destroy_flag = Hfalse; // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=EXIT) (RET=0x%8.8x)\n", (Huint)retval ); // Grab the current thread current = _current_thread(); // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=EXIT) (TID=0x%8.8x) (RET=0x%8.8x)\n", (Huint)current, (Huint)retval ); if( _detached_thread(current) ) destroy_flag = Htrue; // The return value needs to be saved before we // try to exit the thread (to avoid race conditions when a parent joins // a thread and trys to get the return value). Note that we don't // need to save the return value for a detached thread. threads[current].retval = retval; // FIXME: We should check the error condition during the while loop // to ensure that the error was because the ready-to-run queue is // full. Any other error is fatal and since this function never returns // to the caller we must handle this error. status = _exit_thread( current ); while( has_error(status) ) { DEBUG_PRINTF( "Exit returned an error: (STA=0x%8.8x)\n", status ); // Yield the processor to another thread. _syscall_yield(); // Try to exit again after some other thread has run. status = _exit_thread( current ); } // If the thread is a detached thread then it can be destroyed right // away. Joinable threads cannot be destroyed until they have been joined // by some other thread (see _syscall_join). if( destroy_flag ) { _destroy_thread( current ); TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "** DETACHED = 0x%8.8x **\n",destroy_flag); } // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL DONE: (OP=EXIT) (RET=0x%8.8x)\n", (Huint)retval ); // We have now exited. Run the scheduler and never come back. _run_sched( Hfalse ); }
bootstrap::bootstrap(char* name) { file_name = name; _has_error = false; open_file(); if (!has_error()) { // initialize_tables(file_size > 0 ? (file_size / 32) : (10 * K)); initialize_tables(64 * K); parse_file(); close_file(); Universe ::cleanup_after_bootstrap(); } }
MemTrackWorker::MemTrackWorker(MemSnapshot* snapshot): _snapshot(snapshot) { // create thread uses cgc thread type for now. We should revisit // the option, or create new thread type. _has_error = !os::create_thread(this, os::cgc_thread); set_name("MemTrackWorker", 0); // initial generation circuit buffer if (!has_error()) { _head = _tail = 0; for(int index = 0; index < MAX_GENERATIONS; index ++) { ::new ((void*)&_gen[index]) GenerationData(); } } NOT_PRODUCT(_sync_point_count = 0;)
bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath) { assert(filepath, "null file path"); assert(buf != NULL && buflen > 0, "Invalid buffer"); if (has_error()) return false; ElfFile* file = get_elf_file(filepath); if (file == NULL) { return false; } if (!file->decode(addr, buf, buflen, offset)) { return false; } if (buf[0] != '\0') { demangle(buf, buf, buflen); } return true; }
bool process(int thid) { //std::cout << "thread::" << thid << "\n"; sequence_parser::job job(_parser); if (job.is_empty()) return false; for (size_t i=0; i<job->nb_filled; ++i) { const std::string& header = job->data[i].header; const std::string& seq = job->data[i].seq; const std::string& qual = job->data[i].qual; if (seq.size() != qual.size()) { std::cerr << "Error: Insufficient quality information. Quiting...\n"; exit(0); } if (!has_error(seq.c_str(), qual.c_str(), seq.size())) { // std::cout << "READ IS PERFECT" << "\n"; _output << "@" << header << "\n" << seq << "\n"; _output << "+" << header << "\n" << qual << "\n"; _output << jflib::endr; } else { //std::cout << "READ IS ERRONEOUS" << "\n"; } } return true; }
bool read (int column, uint64_t &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = sqlite3_column_int64 (context, column); return readable; }
/** \internal * \brief The system call which implements the hthread_create functionality. * * \author Wesley Peck <*****@*****.**> * * This function is the system call routine which implements the * hthread_create functionality for hthreads. The user space function * hthread_create invokes this function to create a new thread. * * \param th If the thread was created successfully then the new * thread will be stored in the location pointed to * by this argument. * \param attr The attributes to apply to the newly created thread. * See the documentation for hthread_attr_t for more on * the allowable attributes. * \param start A function pointer which is used as the beginning of * the new threads execution. If this function ever returns * then the new thread will be terminated. * \param arg An arbitrary pointer which is used as the first and * only argument to the start routine. * \return The return value is one of the following: * - EAGAIN : There was an error when attempting to create * the new thread. Trying the attempt again might * have a different result. * - ENOMEM : Not enough memory is available to satisfy the * request. Attempting again after more memory * is free might have different results. * - EINVAL : One of the parameters used when calling this * function is invalid. * - FAILURE : A generic failure occurred in the hardware * when attempting to setup the thread. * - SUCCESS : The thread was created successfully */ Hint _syscall_create( hthread_t *th, hthread_attr_t *attr, hthread_start_t start, void *arg ) { Huint threadStatus; Huint threadID; Huint addStatus; Huint setupStatus; Huint schedStatus; // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (THR=0x%8.8x) (ATTR=0x%8.8x) (STRT=0x%8.8x) (ARG=0x%8.8x)\n", (Huint)th, (Huint)attr, (Huint)start, (Huint)arg ); // Ask the thread manager to create a new thread for us. If it // is successful then the thread id will be encoded into the return // value. if( attr->detached ) threadStatus = _create_detached(); else threadStatus = _create_joinable(); TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (DET = 0x%8.8x)\n",(Huint)attr->detached ); // Check if there was an error while creating the new thread. If // there was then it means that all of the available threads are // being used, so we return an error. if( has_error(threadStatus) ) { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (STA=0x%8.8x) (ERR=CREATE)\n", threadStatus ); return EAGAIN; } // If there was no error then we need to get the new thread's id // out of the return status. threadID = extract_id( threadStatus ); TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (TID=0x%8.8x)\n", threadID ); // Initialize the software structures used to keep track of the thread. setupStatus = _setup_thread( threadID, attr, start, arg ); if( setupStatus != SUCCESS ) { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (STA=0x%8.8x) (ERR=SETUP)\n", setupStatus ); return setupStatus; } // Set the scheduling parameter for the thread. if( attr->hardware != Htrue ) { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (Software Thread Sched. Param = 0x%8.8x)\n",attr->sched_param); schedStatus = _set_schedparam( threadID, attr->sched_param ); } else { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (Hardware Thread Sched. Param = 0x%8.8x)\n",attr->hardware_addr); schedStatus = _set_schedparam( threadID, attr->hardware_addr ); } if( schedStatus != SUCCESS ) { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (STA=0x%8.8x) (ERR=SCHED)\n", schedStatus ); return schedStatus; } // Now that we have the new thread setup so that it can run we // can add the thread in the ready-to-run queue. addStatus = _add_thread( threadID ); // Check if there was an error when adding the thread into the // ready-to-run queue. If there was then we need to clean up the // new thread and return an error condition. if( has_error(addStatus) ) { TRACE_PRINTF( TRACE_DBG, TRACE_SYSCALL, "SYSCALL: (OP=CREATE) (STA=0x%8.8x) (ERR=ADD)\n", addStatus ); addStatus = _read_sched_status(threadID); _decode_sched_status(addStatus); // Clean up the software structures used by the thread. _destroy_thread( threadID ); // Remove the thread. _clear_thread( threadID ); // Return an error condition. return EAGAIN; } // Return the thread ID to the caller. At this point the thread has // been successfully created and added to the queue so that we know // a valid thread ID will be returned to the user. *th = threadID; // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL DONE: (OP=CREATE) (THR=0x%8.8x) (ATTR=0x%8.8x) (STRT=0x%8.8x) (ARG=0x%8.8x)\n", (Huint)th, (Huint)attr, (Huint)start, (Huint)arg ); // The thread was created and added to the ready-to-run queue // successfully. Return the success code. return SUCCESS; }
void WindowsDecoder::initialize() { if (!has_error() && _dbghelp_handle == NULL) { HMODULE handle = ::LoadLibrary("dbghelp.dll"); if (!handle) { _decoder_status = helper_not_found; return; } _dbghelp_handle = handle; pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions"); pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize"); _pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64"); _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName"); if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) { _pfnSymGetSymFromAddr64 = NULL; _pfnUndecorateSymbolName = NULL; ::FreeLibrary(handle); _dbghelp_handle = NULL; _decoder_status = helper_func_error; return; } HANDLE hProcess = ::GetCurrentProcess(); _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS); if (!_pfnSymInitialize(hProcess, NULL, TRUE)) { _pfnSymGetSymFromAddr64 = NULL; _pfnUndecorateSymbolName = NULL; ::FreeLibrary(handle); _dbghelp_handle = NULL; _decoder_status = helper_init_error; return; } // set pdb search paths pfn_SymSetSearchPath _pfn_SymSetSearchPath = (pfn_SymSetSearchPath)::GetProcAddress(handle, "SymSetSearchPath"); pfn_SymGetSearchPath _pfn_SymGetSearchPath = (pfn_SymGetSearchPath)::GetProcAddress(handle, "SymGetSearchPath"); if (_pfn_SymSetSearchPath != NULL && _pfn_SymGetSearchPath != NULL) { char paths[MAX_PATH]; int len = sizeof(paths); if (!_pfn_SymGetSearchPath(hProcess, paths, len)) { paths[0] = '\0'; } else { // available spaces in path buffer len -= (int)strlen(paths); } char tmp_path[MAX_PATH]; DWORD dwSize; HMODULE hJVM = ::GetModuleHandle("jvm.dll"); tmp_path[0] = '\0'; // append the path where jvm.dll is located if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) { while (dwSize > 0 && tmp_path[dwSize] != '\\') { dwSize --; } tmp_path[dwSize] = '\0'; if (dwSize > 0 && len > (int)dwSize + 1) { strncat(paths, os::path_separator(), 1); strncat(paths, tmp_path, dwSize); len -= dwSize + 1; } } // append $JRE/bin. Arguments::get_java_home actually returns $JRE // path char *p = Arguments::get_java_home(); assert(p != NULL, "empty java home"); size_t java_home_len = strlen(p); if (len > (int)java_home_len + 5) { strncat(paths, os::path_separator(), 1); strncat(paths, p, java_home_len); strncat(paths, "\\bin", 4); len -= (int)(java_home_len + 5); } // append $JDK/bin path if it exists assert(java_home_len < MAX_PATH, "Invalid path length"); // assume $JRE is under $JDK, construct $JDK/bin path and // see if it exists or not if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) { strncpy(tmp_path, p, java_home_len - 3); tmp_path[java_home_len - 3] = '\0'; strncat(tmp_path, "bin", 3); // if the directory exists DWORD dwAttrib = GetFileAttributes(tmp_path); if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { // tmp_path should have the same length as java_home_len, since we only // replaced 'jre' with 'bin' if (len > (int)java_home_len + 1) { strncat(paths, os::path_separator(), 1); strncat(paths, tmp_path, java_home_len); } } } _pfn_SymSetSearchPath(hProcess, paths); } // find out if jvm.dll contains private symbols, by decoding // current function and comparing the result address addr = (address)Decoder::demangle; char buf[MAX_PATH]; if (decode(addr, buf, sizeof(buf), NULL)) { _can_decode_in_vm = !strcmp(buf, "Decoder::demangle"); } } }
/** \internal * \brief The system call that implements the hthread_join functionality. * * \author Wesley Peck <*****@*****.**> * * This function is the system call routine which implements the * hthread_join functionality for hthreads. The user space function * hthread_join invokes this function to join to a thread. * * \param th The thread which the currently running thread will * join with. This thread must be a valid thread which * is in the joinable state and must not have another * thread waiting for its termination. * \param retval If this value is not NULL then the return value from * the thread th will be stored into the location pointed * to by retval. * \return The return value is one of the following: * - EINVAL : One of the parameters used to call this * function is invalid * - SUCCESS : The thread was joined successfully and is * now exited */ Hint _syscall_join( hthread_t th, void **retval ) { Huint exited; Huint status; // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=JOIN) (THR=0x%8.8x) (RET=0x%8.8x)\n", (Huint)th, (Huint)retval ); // Join the current thread with the given thread. status = _join_thread( th ); // If there was an error trying to join the thread then we // will return that error to the caller. if( has_error(status) ) { // If the thread that is being joined has already exited then we do // not need to wait on it so this statement will not be executed. If // the thread has not yet exited then we will release the proccessor // without adding ourself back onto the ready-to-run queue. The thread // we are joining will add us back to the queue once it has exited. exited = extract_error( status ); if( exited != HT_ALREADY_EXITED ) { DEBUG_PRINTF( "JOIN ERROR=0x%8.8x\n", exited ); return EINVAL; } } // If the thread has not already exited then block the currently // running thread until that thread has exited. exited = extract_error( status ); if( exited != HT_ALREADY_EXITED ) { _run_sched( Htrue ); } // At this point the thread we are joining is guaranteed to have exited. // We should store the return value of the thread into the retval // variable. We then destroy and clear the thread so that some other // process can make used of the thread ID. if( retval != NULL ) { // Commented out, as fast V-HWTI re-usage via smart dispatch will re-use a V-HWTI as soon as a thread is exited, // thus causing the return value to be overwritten. The new HAL bootloop copies the return value to the threads.retval location // just as SW threads do, so hardware thread's return values can be retrieved from the same place (as they are now preserved) //if( threads[ th ].hardware != 0 ) *retval = (void**)_hwti_results( threads[th].hardware - HT_HWTI_COMMAND_OFFSET ); if( threads[ th ].hardware != 0 ) *retval = threads[th].retval; else *retval = threads[th].retval; } // Deallocate the software side structures used to keep track of the // thread that was just joined. if( !_detached_thread( th ) ) { _destroy_thread( th ); } // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL DONE: (OP=JOIN) (THR=0x%8.8x) (RET=0x%8.8x)\n", (Huint)th, (Huint)retval ); // Return successfully. return SUCCESS; }
bool WindowsDecoder::can_decode_C_frame_in_vm() const { return (!has_error() && _can_decode_in_vm); }
bool read (int column, std::string &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = (const char *) sqlite3_column_text (context, column); return readable; }
bool read (int column, double &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = sqlite3_column_double (context, column); return readable; }
bool operator!() const { return has_error(); }
explicit operator bool() const { return !has_error(); }