YO_NEW_REF Event* FdEventQueue::timeddequeue(const Time& timeout) { int timeout_ms = (timeout == Time::FOREVER) ? -1 : static_cast<int>(timeout.ms()); int ret = ::poll(&pollfds[0], pollfds.size(), timeout_ms); if (ret > 0) { vector<pollfd>::const_iterator pollfd_i = pollfds.begin(); do { const pollfd& pollfd_ = *pollfd_i; if (pollfd_.revents != 0) { if (pollfd_.fd == wake_pipe[0]) { char data; read(wake_pipe[0], &data, sizeof(data)); return event_queue.trydequeue(); } else { return new FdEvent(pollfd_.fd, pollfd_.revents); } if (--ret == 0) { break; } } } while (++pollfd_i != pollfds.end()); debug_break(); return NULL; } else if (ret == 0 || errno == EINTR) { return NULL; } else { debug_break(); return NULL; } }
void input_event(int type, int key) { u8 state = type == SDL_KEYUP ? JOY_STATE_RELEASED : JOY_STATE_PRESSED; if(type == SDL_KEYUP) { if(key == input.keys.menu) { moo_pause(); } } if(key == input.keys.up) joy_set_button(JOY_BUTTON_UP, state); if(key == input.keys.down) joy_set_button(JOY_BUTTON_DOWN, state); if(key == input.keys.left) joy_set_button(JOY_BUTTON_LEFT, state); if(key == input.keys.right) joy_set_button(JOY_BUTTON_RIGHT, state); if(key == input.keys.a) joy_set_button(JOY_BUTTON_A, state); if(key == input.keys.b) joy_set_button(JOY_BUTTON_B, state); if(key == input.keys.start) joy_set_button(JOY_BUTTON_START, state); if(key == input.keys.select) joy_set_button(JOY_BUTTON_SELECT, state); #ifdef DEBUG if(key == input.keys.debug) { if (type == SDL_KEYDOWN) { debug_break(); } } #endif // DEBUG }
// just like post_call, wow! void function_context_end_invocation(ZzHookFunctionEntry *entry, zz_ptr_t next_hop, RegState *rs) { ZZ_DEBUG_LOG("%p call end-invocation", entry->target_ptr); ZzThreadStack *stack = ZzGetCurrentThreadStack(entry->thread_local_key); if (!stack) { #if defined(DEBUG_MODE) debug_break(); #endif } ZzCallStack *callstack = ZzPopCallStack(stack); /* call post_call */ if (entry->post_call) { POSTCALL post_call; HookEntryInfo entry_info; entry_info.hook_id = entry->id; entry_info.hook_address = entry->target_ptr; post_call = entry->post_call; (*post_call)(rs, (ThreadStack *)stack, (CallStack *)callstack, (const HookEntryInfo *)&entry_info); } /* set next hop */ *(zz_ptr_t *)next_hop = callstack->caller_ret_addr; ZzFreeCallStack(callstack); }
void zz_arm64_register_describe(ZzARM64Reg reg, ZzArm64RegInfo *ri) { if (reg >= ZZ_ARM64_REG_X0 && reg <= ZZ_ARM64_REG_X28) { ri->is_integer = TRUE; ri->width = 64; ri->meta = ZZ_ARM64_REG_X0 + (reg - ZZ_ARM64_REG_X0); } else if (reg == ZZ_ARM64_REG_X29 || reg == ZZ_ARM64_REG_FP) { ri->is_integer = TRUE; ri->width = 64; ri->meta = ZZ_ARM64_REG_X29; } else if (reg == ZZ_ARM64_REG_X30 || reg == ZZ_ARM64_REG_LR) { ri->is_integer = TRUE; ri->width = 64; ri->meta = ZZ_ARM64_REG_X30; } else if (reg == ZZ_ARM64_REG_SP) { ri->is_integer = TRUE; ri->width = 64; ri->meta = ZZ_ARM64_REG_X31; } else { Serror("zz_arm64_register_describe error."); #if defined(DEBUG_MODE) debug_break(); #endif ri->index = 0; } ri->index = ri->meta - ZZ_ARM64_REG_X0; }
Directory::Entry::Type ScanningWatch::type(const Stat& stbuf) { #ifdef _WIN32 if (stbuf.ISDEV()) { return Directory::Entry::TYPE_DEV; } else if (stbuf.ISDIR()) { return Directory::Entry::TYPE_DIR; } else if (stbuf.ISREG()) { return Directory::Entry::TYPE_REG; } #else if (stbuf.ISBLK()) { return Directory::Entry::TYPE_BLK; } else if (stbuf.ISCHR()) { return Directory::Entry::TYPE_CHR; } else if (stbuf.ISDIR()) { return Directory::Entry::TYPE_DIR; } else if (stbuf.ISFIFO()) { return Directory::Entry::TYPE_FIFO; } else if (stbuf.ISLNK()) { return Directory::Entry::TYPE_LNK; } else if (stbuf.ISREG()) { return Directory::Entry::TYPE_REG; } else if (stbuf.ISSOCK()) { return Directory::Entry::TYPE_SOCK; } #endif else { debug_break(); return Directory::Entry::TYPE_REG; } }
YO_NEW_REF Event* FsEventQueue::timeddequeue(const Time& timeout) { Event* event = event_queue.trydequeue(); if (event != NULL) { return event; } else { struct kevent kevent_; timespec timeout_ts = timeout; int ret = kevent(kq, 0, 0, &kevent_, 1, &timeout_ts); if (ret > 0) { debug_assert_eq(ret, 1); if (static_cast<int>(kevent_.ident) == wake_pipe[0]) { char m; ssize_t read_ret = read(wake_pipe[0], &m, sizeof(m)); debug_assert_eq(read_ret, static_cast<ssize_t>(sizeof(m))); return event_queue.trydequeue(); } else { debug_assert_eq(kevent_.filter, EVFILT_VNODE); //if (log != NULL) { // log->get_stream(Log::Level::DEBUG) << // get_type_name() << "(fd=" << fd << ", path=" << path << "): " << // "read kevent(fflags=" << kevent_.fflags << ")"; //} bsd::Watch* watch = static_cast<bsd::Watch*>(kevent_.udata); watch->read(kevent_, *this); return event_queue.trydequeue(); } } else if (ret == 0 || errno == EINTR) { return NULL; } else { debug_break(); return NULL; } } }
ErrorReactionInternal sys_display_error(const wchar_t* text, size_t flags) { printf("%ls\n\n", text); const bool manual_break = (flags & DE_MANUAL_BREAK ) != 0; const bool allow_suppress = (flags & DE_ALLOW_SUPPRESS) != 0; const bool no_continue = (flags & DE_NO_CONTINUE ) != 0; // Try the GUI prompt if possible ErrorReactionInternal ret = try_gui_display_error(text, manual_break, allow_suppress, no_continue); if (ret != ERI_NOT_IMPLEMENTED) return ret; // Otherwise fall back to the terminal-based input // Loop until valid input given: for(;;) { if(!no_continue) printf("(C)ontinue, "); if(allow_suppress) printf("(S)uppress, "); printf("(B)reak, Launch (D)ebugger, or (E)xit?\n"); // TODO Should have some kind of timeout here.. in case you're unable to // access the controlling terminal (As might be the case if launched // from an xterm and in full-screen mode) int c = getchar(); // note: don't use tolower because it'll choke on EOF switch(c) { case EOF: case 'd': case 'D': udbg_launch_debugger(); //-fallthrough case 'b': case 'B': if(manual_break) return ERI_BREAK; debug_break(); return ERI_CONTINUE; case 'c': case 'C': if(!no_continue) return ERI_CONTINUE; // continue isn't allowed, so this was invalid input. loop again. break; case 's': case 'S': if(allow_suppress) return ERI_SUPPRESS; // suppress isn't allowed, so this was invalid input. loop again. break; case 'e': case 'E': abort(); return ERI_EXIT; // placebo; never reached } } }
void ScriptEditorDebugger::_profiler_seeked() { if (!connection.is_valid() || !connection->is_connected()) return; if (breaked) return; debug_break();; }
void debug_printf(const char* fmt, ...) { char buf[16384]; va_list ap; va_start(ap, fmt); const int numChars = vsprintf_s(buf, ARRAY_SIZE(buf), fmt, ap); if (numChars < 0) debug_break(); // poor man's assert - avoid infinite loop because ENSURE also uses debug_printf va_end(ap); debug_puts_filtered(buf); }
socklen_t SocketAddress::len(int family) { switch (family) { case 0: return sizeof(sockaddr_storage); case AF_INET: return sizeof(sockaddr_in); case AF_INET6: return sizeof(sockaddr_in6); default: debug_break(); return 0; } }
int PLCContext::isDebugPixel(int pixel, int line) { for( unsigned int i = 0; i < debugPixels.size(); i += 2 ) { if( debugPixels[i] == pixel && debugPixels[i+1] == line ) { debug_break(); return TRUE; } } return FALSE; }
void ScriptEditorDebugger::_paused() { ERR_FAIL_COND(connection.is_null()); ERR_FAIL_COND(!connection->is_connected()); if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) { debug_break(); } if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) { debug_continue(); } }
void _debug_assert_fail(const char *expr, const char *file, unsigned line, const char *function) { _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr); #if defined(PIPE_OS_WINDOWS) if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE)) #else if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE)) #endif debug_break(); else _debug_printf("continuing...\n"); }
void watch_event_mem_r(u16 addr) { if (in_debug_scope()) { return; } int wp; for (wp = 0; wp < watchpoint_cursor; wp++) { if (!watchpoint_enabled[wp]) { continue; } switch (watchpoints[wp].type) { case WATCHPOINT_MEM_RW: case WATCHPOINT_MEM_R: if (watchpoints[wp].mem.begin <= addr && watchpoints[wp].mem.end >= addr) { printf("WATCHPOINT %i: %.4X read %.2X\n", wp, addr, debug_read_byte(addr)); debug_break(); } default:; } } }
void watch_event_mem_w(u16 addr, u8 a, u8 b) { if (in_debug_scope()) { return; } int wp; for (wp = 0; wp < watchpoint_cursor; wp++) { if (!watchpoint_enabled[wp]) { continue; } switch (watchpoints[wp].type) { case WATCHPOINT_MEM_RW: case WATCHPOINT_MEM_W: if (watchpoints[wp].mem.begin <= addr && watchpoints[wp].mem.end >= addr) { printf("WATCHPOINT %i: %.4X changed from %.2X to %.2X\n", wp, addr, a, b); debug_break(); } default:; } } }
// just like post_call, wow! void function_context_end_invocation(ZzHookFunctionEntry *entry, zpointer next_hop, RegState *rs) { Xdebug("%p call end-invocation", entry->target_ptr); ZzThreadStack *threadstack = ZzGetCurrentThreadStack(entry->thread_local_key); if (!threadstack) { #if defined(DEBUG_MODE) debug_break(); #endif } ZzCallStack *callstack = ZzPopCallStack(threadstack); /* call post_call */ if (entry->post_call) { POSTCALL post_call; post_call = entry->post_call; (*post_call)(rs, (ThreadStack *)threadstack, (CallStack *)callstack); } /* set next hop */ *(zpointer *)next_hop = callstack->caller_ret_addr; ZzFreeCallStack(callstack); }
void function_context_half_invocation(ZzHookFunctionEntry *entry, zpointer next_hop, RegState *rs, zpointer caller_ret_addr) { Xdebug("target %p call half-invocation", entry->target_ptr); ZzThreadStack *threadstack = ZzGetCurrentThreadStack(entry->thread_local_key); if (!threadstack) { #if defined(DEBUG_MODE) debug_break(); #endif } ZzCallStack *callstack = ZzPopCallStack(threadstack); /* call half_call */ if (entry->half_call) { HALFCALL half_call; half_call = entry->half_call; (*half_call)(rs, (ThreadStack *)threadstack, (CallStack *)callstack); } /* set next hop */ *(zpointer *)next_hop = (zpointer)entry->target_half_ret_addr; ZzFreeCallStack(callstack); }
SocketAddress::SocketAddress(const SocketAddress& other, uint16_t port) { memcpy_s(&addr, sizeof(addr), &other.addr, sizeof(other.addr)); switch (get_family()) { case AF_INET: { reinterpret_cast<sockaddr_in*>(&addr)->sin_port = htons(port); } break; case AF_INET6: { reinterpret_cast<sockaddr_in6*>(&addr)->sin6_port = htons(port); } break; default: debug_break(); } if (other.next_socket_address != NULL) { next_socket_address = new SocketAddress(*other.next_socket_address, port); } else { next_socket_address = NULL; } }
Watch::Watch(const Watch&) { debug_break(); }
bool Directory::read(Entry*& entry) { struct dirent* dirent_; while ((dirent_ = readdir(dirp)) != NULL) { Entry::Type entry_type; #if defined(__FreeBSD__) || defined(__linux__) || defined(__MACH__) switch (dirent_->d_type) { case DT_BLK: entry_type = Entry::TYPE_BLK; break; case DT_CHR: entry_type = Entry::TYPE_CHR; break; case DT_DIR: entry_type = Entry::TYPE_DIR; break; case DT_FIFO: entry_type = Entry::TYPE_FIFO; break; case DT_LNK: entry_type = Entry::TYPE_LNK; break; case DT_REG: entry_type = Entry::TYPE_REG; break; case DT_SOCK: entry_type = Entry::TYPE_SOCK; break; default: debug_break(); entry_type = Entry::TYPE_REG; break; } #else struct stat stbuf; if (stat((path / dirent_->d_name).c_str(), &stbuf) != 0) { return false; } if (S_ISBLK(stbuf.st_mode)) { entry_type = Entry::TYPE_BLK; } else if (S_ISCHR(stbuf.st_mode)) { entry_type = Entry::TYPE_CHR; } else if (S_ISDIR(stbuf.st_mode)) { entry_type = Entry::TYPE_DIR; } else if (S_ISFIFO(stbuf.st_mode)) { entry_type = Entry::TYPE_FIFO; } else if (S_ISLNK(stbuf.st_mode)) { entry_type = Entry::TYPE_LNK; } else if (S_ISREG(stbuf.st_mode)) { entry_type = Entry::TYPE_REG; } else if (S_ISSOCK(stbuf.st_mode)) { entry_type = Entry::TYPE_SOCK; } else { entry_type = Entry::TYPE_REG; debug_break(); } #endif if (entry == NULL) { entry = new Entry(dirent_->d_name, entry_type); } else { entry->set_name(dirent_->d_name); entry->set_type(entry_type); } return true; } return false; }
static void kerext_debug_process(void *args) { PROCESS *prp; THREAD *thp, *act = actives[KERNCPU]; DEBUG *dep; struct kerargs_debug_process *kap = args; int status; int stopped; int tid; if(!(prp = lookup_pid(kap->pid))) { kererr(act, ESRCH); return; } dep = prp->debugger; if(kap->request == NTO_DEBUG_PROCESS_INFO || (prp->flags & _NTO_PF_TERMING)) { tid = 0; } else if(dep && kap->tid == 0) { tid = dep->tid + 1; } else { tid = kap->tid; } thp = 0; if(tid > 0 && !(thp = vector_search(&prp->threads, tid - 1, (kap->request == NTO_DEBUG_THREAD_INFO || kap->request == NTO_DEBUG_STOP) ? (unsigned *)&tid : 0))) { kererr(act, ESRCH); return; } stopped = 0; if(thp && ((thp->flags & _NTO_TF_TO_BE_STOPPED) || (thp->state != STATE_RUNNING && thp->state != STATE_READY))) { stopped = 1; } status = EINVAL; switch(kap->request) { case NTO_DEBUG_PROCESS_INFO: // pid:na:debug_process_t status = debug_process(prp, &kap->data->process); break; case NTO_DEBUG_THREAD_INFO: // pid:tid:debug_thread_t status = debug_thread(prp, thp, &kap->data->thread); break; case NTO_DEBUG_GET_GREG: // pid:tid:debug_greg_t if(thp) { memcpy(&kap->data->greg, &thp->reg, sizeof thp->reg); status = EOK; } break; case NTO_DEBUG_SET_GREG: // pid:tid:debug_greg_t if(stopped) { lock_kernel(); cpu_greg_load(thp, (CPU_REGISTERS *)&kap->data->greg); status = EOK; } break; case NTO_DEBUG_GET_FPREG: // pid:tid:debug_fpreg_t if(thp) { FPU_REGISTERS *fpudata = FPUDATA_PTR(thp->fpudata); int cpu = FPUDATA_CPU(thp->fpudata); status = ENXIO; if(fpudata) { if(FPUDATA_INUSE(thp->fpudata) && cpu != KERNCPU) { // In use on another CPU; send ipi, restart kernel call SENDIPI(cpu, IPI_CONTEXT_SAVE); KERCALL_RESTART(act); return; } if(actives_fpu[thp->runcpu] == thp) { if(KERNCPU == thp->runcpu) { cpu_force_fpu_save(thp); actives_fpu[KERNCPU] = NULL; } else { // We should not get here crash(); } } memcpy(&kap->data->fpreg, fpudata, sizeof *fpudata); status = EOK; } else if(thp->un.lcl.tls && thp->un.lcl.tls->__fpuemu_data) { // @@@ NEED TO FIND PROPER SIZE OF EMULATOR DATA memcpy(&kap->data->fpreg, thp->un.lcl.tls->__fpuemu_data, sizeof(*fpudata) + 256); status = EOK; } } break; case NTO_DEBUG_SET_FPREG: // pid:tid:debug_fpreg_t if(thp && stopped) { FPU_REGISTERS *fpudata = FPUDATA_PTR(thp->fpudata); int cpu = FPUDATA_CPU(thp->fpudata); status = ENXIO; if(thp->fpudata) { if(FPUDATA_INUSE(thp->fpudata) && cpu != KERNCPU) { // In use on another CPU; send ipi, restart kernel call SENDIPI(cpu, IPI_CONTEXT_SAVE); KERCALL_RESTART(act); return; } if(actives_fpu[thp->runcpu] == thp) { if(KERNCPU == thp->runcpu) { cpu_force_fpu_save(thp); actives_fpu[KERNCPU] = NULL; } else { // We should not get here crash(); } } memcpy(fpudata, &kap->data->fpreg, sizeof *fpudata); status = EOK; } else if(thp->un.lcl.tls && thp->un.lcl.tls->__fpuemu_data) { // @@@ NEED TO FIND PROPER SIZE OF EMULATOR DATA memcpy(thp->un.lcl.tls->__fpuemu_data, &kap->data->fpreg, sizeof(*fpudata) + 256); status = EOK; } } break; case NTO_DEBUG_STOP: // pid:na:na if(dep) { status = debug_stop(prp); } break; case NTO_DEBUG_RUN: // pid:tid:debug_run_t if(dep && stopped) { status = debug_run(prp, &kap->data->run); } break; case NTO_DEBUG_CURTHREAD: // pid:tid:NULL if(dep) { lock_kernel(); SETKSTATUS(act, dep->tid + 1); if(thp) { dep->tid = thp->tid; } return; } break; case NTO_DEBUG_FREEZE: // pid:tid:NULL if(thp == NULL){ status = EINVAL; break; } if(stopped) { lock_kernel(); thp->flags |= _NTO_TF_FROZEN; } break; case NTO_DEBUG_THAW: // pid:tid:NULL if(thp == NULL){ status = EINVAL; break; } if(stopped) { lock_kernel(); thp->flags &= ~_NTO_TF_FROZEN; } break; case NTO_DEBUG_BREAK: // pid:na:debug_break_t if(dep && stopped) { status = debug_break(prp, &kap->data->brk); } break; case NTO_DEBUG_GET_BREAKLIST: // pid:na:debug_breaklist_t status = debug_break_list(prp, &kap->data->brklist); break; case NTO_DEBUG_SET_FLAG: // pid:na:uint32_t if(dep && !(kap->data->flags & ~_DEBUG_FLAG_MASK)) { lock_kernel(); dep->flags |= kap->data->flags; } break; case NTO_DEBUG_CLEAR_FLAG: // pid:na:uint32_t if(dep && !(kap->data->flags & ~_DEBUG_FLAG_MASK)) { lock_kernel(); dep->flags &= ~kap->data->flags; } break; case NTO_DEBUG_GET_ALTREG: // pid:tid:debug_altreg_t if(thp) { status = cpu_debug_get_altregs(thp, &kap->data->altreg); } break; case NTO_DEBUG_SET_ALTREG: // pid:tid:debug_altreg_t if(thp) { status = cpu_debug_set_altregs(thp, &kap->data->altreg); } break; case NTO_DEBUG_GET_PERFREG: if ( thp ) { status = cpu_debug_get_perfregs(thp, &kap->data->perfreg); } break; case NTO_DEBUG_SET_PERFREG: if ( thp && !stopped ) status = EINVAL; else { if ( (kap->data->flags & ~PERFREGS_ENABLED_FLAG) == cpu_perfreg_id() ) { status = cpu_debug_set_perfregs(thp, &kap->data->perfreg); } else status = ENODEV; } break; } if(status != EOK) { kererr(act, status); } else { lock_kernel(); SETKSTATUS(act, 0); } }
static ErrorReactionInternal try_gui_display_error(const wchar_t* text, bool manual_break, bool allow_suppress, bool no_continue) { // We'll run xmessage via fork/exec. // To avoid bad interaction between fork and pthreads, the child process // should only call async-signal-safe functions before exec. // So prepare all the child's data in advance, before forking: Status err; // ignore UTF-8 errors std::string message = utf8_from_wstring(text, &err); // Replace CRLF->LF boost::algorithm::replace_all(message, "\r\n", "\n"); // TODO: we ought to wrap the text if it's very long, // since xmessage doesn't do that and it'll get clamped // to the screen width const char* cmd = "/usr/bin/xmessage"; char buttons[256] = ""; const char* defaultButton = "Exit"; if(!no_continue) { strcat_s(buttons, sizeof(buttons), "Continue:100,"); defaultButton = "Continue"; } if(allow_suppress) strcat_s(buttons, sizeof(buttons), "Suppress:101,"); strcat_s(buttons, sizeof(buttons), "Break:102,Debugger:103,Exit:104"); // Since execv wants non-const strings, we strdup them all here // and will clean them up later (except in the child process where // memory leaks don't matter) char* const argv[] = { strdup(cmd), strdup("-geometry"), strdup("x500"), // set height so the box will always be very visible strdup("-title"), strdup("0 A.D. message"), // TODO: maybe shouldn't hard-code app name strdup("-buttons"), strdup(buttons), strdup("-default"), strdup(defaultButton), strdup(message.c_str()), NULL }; pid_t cpid = fork(); if(cpid == -1) return ERI_NOT_IMPLEMENTED; if(cpid == 0) { // This is the child process // Set ASCII charset, to avoid font warnings from xmessage setenv("LC_ALL", "C", 1); // NOTE: setenv is not async-signal-safe, so we shouldn't really use // it here (it might want some mutex that was held by another thread // in the parent process and that will never be freed within this // process). But setenv/getenv are not guaranteed reentrant either, // and this error-reporting function might get called from a non-main // thread, so we can't just call setenv before forking as it might // break the other threads. And we can't just clone environ manually // inside the parent thread and use execve, because other threads might // be calling setenv and will break our iteration over environ. // In the absence of a good easy solution, and given that this is only // an error-reporting function and shouldn't get called frequently, // we'll just do setenv after the fork and hope that it fails // extremely rarely. execv(cmd, argv); // If exec returns, it failed //fprintf(stderr, "Error running %s: %d\n", cmd, errno); exit(-1); } // This is the parent process // Avoid memory leaks for(char* const* a = argv; *a; ++a) free(*a); int status = 0; waitpid(cpid, &status, 0); // If it didn't exist successfully, fall back to the non-GUI prompt if(!WIFEXITED(status)) return ERI_NOT_IMPLEMENTED; switch(WEXITSTATUS(status)) { case 103: // Debugger udbg_launch_debugger(); //-fallthrough case 102: // Break if(manual_break) return ERI_BREAK; debug_break(); return ERI_CONTINUE; case 100: // Continue if(!no_continue) return ERI_CONTINUE; // continue isn't allowed, so this was invalid input. return ERI_NOT_IMPLEMENTED; case 101: // Suppress if(allow_suppress) return ERI_SUPPRESS; // suppress isn't allowed, so this was invalid input. return ERI_NOT_IMPLEMENTED; case 104: // Exit abort(); return ERI_EXIT; // placebo; never reached } // Unexpected return value - fall back to the non-GUI prompt return ERI_NOT_IMPLEMENTED; }
void start_bootloader (void) { static char mem[4096]; static char buffer[1024]; unsigned long off; int fd, i; struct disk_req req; struct disk_stat stat; struct elfhdr *elf; struct elf_phdr *elf_phdr; /* program header */ unsigned long e_entry, e_phoff, e_phnum; register struct ia64_boot_param *bp; char *kpath, *args; long arglen = 0; ssc(0, 0, 0, 0, SSC_CONSOLE_INIT); /* * S.Eranian: extract the commandline argument from the simulator * * The expected format is as follows: * * kernelname args... * * Both are optional but you can't have the second one without the first. */ arglen = ssc((long) buffer, 0, 0, 0, SSC_GET_ARGS); kpath = "vmlinux"; args = buffer; if (arglen > 0) { kpath = buffer; while (*args != ' ' && *args != '\0') ++args, --arglen; if (*args == ' ') *args++ = '\0', --arglen; } if (arglen <= 0) { args = ""; arglen = 1; } fd = ssc((long) kpath, 1, 0, 0, SSC_OPEN); if (fd < 0) { cons_write(kpath); cons_write(": file not found, reboot now\n"); for(;;); } stat.fd = fd; off = 0; req.len = sizeof(mem); req.addr = (long) mem; ssc(fd, 1, (long) &req, off, SSC_READ); ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION); elf = (struct elfhdr *) mem; if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) { cons_write("not an ELF file\n"); return; } if (elf->e_type != ET_EXEC) { cons_write("not an ELF executable\n"); return; } if (!elf_check_arch(elf)) { cons_write("kernel not for this processor\n"); return; } e_entry = elf->e_entry; e_phnum = elf->e_phnum; e_phoff = elf->e_phoff; cons_write("loading "); cons_write(kpath); cons_write("...\n"); for (i = 0; i < e_phnum; ++i) { req.len = sizeof(*elf_phdr); req.addr = (long) mem; ssc(fd, 1, (long) &req, e_phoff, SSC_READ); ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION); if (stat.count != sizeof(*elf_phdr)) { cons_write("failed to read phdr\n"); return; } e_phoff += sizeof(*elf_phdr); elf_phdr = (struct elf_phdr *) mem; if (elf_phdr->p_type != PT_LOAD) continue; req.len = elf_phdr->p_filesz; req.addr = __pa(elf_phdr->p_paddr); ssc(fd, 1, (long) &req, elf_phdr->p_offset, SSC_READ); ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION); memset((char *)__pa(elf_phdr->p_paddr) + elf_phdr->p_filesz, 0, elf_phdr->p_memsz - elf_phdr->p_filesz); } ssc(fd, 0, 0, 0, SSC_CLOSE); cons_write("starting kernel...\n"); /* fake an I/O base address: */ ia64_setreg(_IA64_REG_AR_KR0, 0xffffc000000UL); bp = sys_fw_init(args, arglen); ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS); debug_break(); jmp_to_kernel((unsigned long) bp, e_entry); cons_write("kernel returned!\n"); ssc(-1, 0, 0, 0, SSC_EXIT); }
int64 gp_fault_inject_impl(int32 reason, int64 arg) { switch(reason) { case GP_FAULT_USER_SEGV: *(volatile int *) 0 = 1234; break; case GP_FAULT_USER_LEAK: palloc(arg); break; case GP_FAULT_USER_LEAK_TOP: { extern MemoryContext TopMemoryContext; MemoryContext oldCtxt = MemoryContextSwitchTo(TopMemoryContext); palloc(arg); MemoryContextSwitchTo(oldCtxt); } break; case GP_FAULT_USER_RAISE_ERROR: ereport(ERROR, (errcode(ERRCODE_FAULT_INJECT), errmsg("User fault injection raised error"))); case GP_FAULT_USER_RAISE_FATAL: ereport(FATAL, (errcode(ERRCODE_FAULT_INJECT), errmsg("User fault injection raised fatal"))); case GP_FAULT_USER_RAISE_PANIC: ereport(PANIC, (errcode(ERRCODE_FAULT_INJECT), errmsg("User fault injection raised panic"))); case GP_FAULT_USER_PROCEXIT: { extern void proc_exit(int); proc_exit((int) arg); } case GP_FAULT_USER_ABORT: abort(); case GP_FAULT_USER_INFINITE_LOOP: { do { /* do nothing */ } while(true); } break; case GP_FAULT_USER_ASSERT_FAILURE: Assert(!"Inject an assert failure"); break; case GP_FAULT_USER_DEBUGBREAK: { if (arg == 0) debug_break(); else debug_break_n(arg); } break; case GP_FAULT_USER_SEGV_CRITICAL: START_CRIT_SECTION(); *(volatile int *) 0 = 1234; END_CRIT_SECTION(); break; case GP_FAULT_USER_SEGV_LWLOCK: LWLockAcquire(WALInsertLock, LW_EXCLUSIVE); *(volatile int *) 0 = 1234; break; case GP_FAULT_USER_OPEN_MANY_FILES: open_many_files((int) arg); break; case GP_FAULT_USER_MP_CONFIG: case GP_FAULT_USER_MP_ALLOC: case GP_FAULT_USER_MP_HIGHWM: case GP_FAULT_SEG_AVAILABLE: case GP_FAULT_SEG_SET_VMEMMAX: case GP_FAULT_SEG_GET_VMEMMAX: return VmemTracker_Fault(reason, arg); case GP_FAULT_LOG_LONGMSG: elog(LOG, "%s%s%s%s%s" "%s%s%s%s" "%s%s%s%s%s", longmsg, longmsg, longmsg, longmsg, longmsg, multiline, multiline, quotestr, quotestr, longmsg, longmsg, longmsg, longmsg, longmsg ); break; case GP_FAULT_LOG_3RDPARTY: fprintf(stderr, "Hello from 3rd party"); fflush(stderr); break; case GP_FAULT_LOG_3RDPARTY_LONGMSG: fprintf(stderr, "%s%s%s%s%s" "%s%s%s%s" "%s%s%s%s%s", longmsg, longmsg, longmsg, longmsg, longmsg, multiline, multiline, quotestr, quotestr, longmsg, longmsg, longmsg, longmsg, longmsg ); fflush(stderr); break; case GP_FAULT_LOG_CRASH: { PipeProtoHeader hdr; hdr.zero = 0; hdr.len = 0; hdr.pid = 1; hdr.thid = 1; hdr.main_thid = 1; hdr.chunk_no = 0; hdr.is_last = 't'; hdr.log_format = 'X'; hdr.log_line_number = reason; hdr.next = -1; write(2, &hdr, sizeof(PipeProtoHeader)); } break; case GP_FAULT_INJECT_SEGMENT_FAILURE: { gp_fault_inject_segment_failure = true; gp_fault_inject_segment_failure_segment_id = (int)arg; elog(LOG, "Inject a segment failure for segment %d", (int)arg); } break; default: elog(ERROR, "Invalid user fault injection code"); } return 0; }
void app_init (int argc, char **argv) { static gboolean nosplash = FALSE; static gboolean nonew = FALSE; static gboolean use_integrated_ui = TRUE; static gboolean credits = FALSE; static gboolean version = FALSE; static gboolean verbose = FALSE; static gboolean log_to_stderr = FALSE; #ifdef HAVE_GNOME GnomeClient *client; #endif static char *export_file_name = NULL; static char *export_file_format = NULL; static char *size = NULL; static char *show_layers = NULL; gboolean made_conversions = FALSE; GSList *files = NULL; static const gchar **filenames = NULL; int i = 0; gchar *export_format_string = /* Translators: The argument is a list of options, not to be translated */ g_strdup_printf(_("Select the filter/format out of: %s"), "cgm, dia, dxf, eps, eps-builtin, " EPS_PANGO "fig, mp, plt, hpgl, png (" # if defined(HAVE_LIBPNG) && defined(HAVE_LIBART) "png-libart, " # endif # ifdef HAVE_CAIRO "cairo-png, cairo-alpha-png, " # endif /* we always have pixbuf but don't know exactly all it's *few* save formats */ "pixbuf-png), jpg, " "shape, svg, tex (pgf-tex, pstricks-tex), " WMF "wpg"); GOptionContext *context = NULL; static GOptionEntry options[] = { {"export", 'e', 0, G_OPTION_ARG_FILENAME, NULL /* &export_file_name */, N_("Export loaded file and exit"), N_("OUTPUT")}, {"filter",'t', 0, G_OPTION_ARG_STRING, NULL /* &export_file_format */, NULL /* &export_format_string */, N_("TYPE") }, {"size", 's', 0, G_OPTION_ARG_STRING, NULL, N_("Export graphics size"), N_("WxH")}, {"show-layers", 'L', 0, G_OPTION_ARG_STRING, NULL, N_("Show only specified layers (e.g. when exporting). Can be either the layer name or a range of layer numbers (X-Y)"), N_("LAYER,LAYER,...")}, {"nosplash", 'n', 0, G_OPTION_ARG_NONE, &nosplash, N_("Don't show the splash screen"), NULL }, {"nonew", 'n', 0, G_OPTION_ARG_NONE, &nonew, N_("Don't create an empty diagram"), NULL }, {"classic", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_integrated_ui, N_("Start classic user interface (no diagrams in tabs)"), NULL }, {"log-to-stderr", 'l', 0, G_OPTION_ARG_NONE, &log_to_stderr, N_("Send error messages to stderr instead of showing dialogs."), NULL }, {"input-directory", 'I', 0, G_OPTION_ARG_CALLBACK, _check_option_input_directory, N_("Directory containing input files"), N_("DIRECTORY")}, {"output-directory", 'O', 0, G_OPTION_ARG_CALLBACK, _check_option_output_directory, N_("Directory containing output files"), N_("DIRECTORY")}, {"credits", 'c', 0, G_OPTION_ARG_NONE, &credits, N_("Display credits list and exit"), NULL }, {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Generate verbose output"), NULL }, {"version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Display version and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL /* &filenames */, NULL, NULL }, { NULL } }; /* for users of app_init() the default is interactive */ dia_is_interactive = TRUE; options[0].arg_data = &export_file_name; options[1].arg_data = &export_file_format; options[1].description = export_format_string; options[2].arg_data = &size; options[3].arg_data = &show_layers; g_assert (strcmp (options[13].long_name, G_OPTION_REMAINING) == 0); options[13].arg_data = (void*)&filenames; argv0 = (argc > 0) ? argv[0] : "(none)"; #if GTK_CHECK_VERSION(2,24,0) /* ... use setlocale directly? */ #else gtk_set_locale(); #endif setlocale(LC_NUMERIC, "C"); _setup_textdomains (); context = g_option_context_new(_("[FILE...]")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); #ifndef HAVE_GNOME /* avoid to add it a second time */ g_option_context_add_group (context, gtk_get_option_group (FALSE)); #endif if (argv) { GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { /* IMO !error here is a bug upstream, triggered e.g. with --gdk-debug=updates */ g_print ("%s", error->message); g_error_free (error); } else { g_print (_("Invalid option?")); } g_option_context_free(context); exit(1); } /* second level check of command line options, existance of input files etc. */ if (filenames) { while (filenames[i] != NULL) { gchar *filename; gchar *testpath; if (g_str_has_prefix (filenames[i], "file://")) { filename = g_filename_from_uri (filenames[i], NULL, NULL); if (!g_utf8_validate(filename, -1, NULL)) { gchar *tfn = filename; filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); g_free(tfn); } } else filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL); if (!filename) { g_print (_("Filename conversion failed: %s\n"), filenames[i]); continue; } if (g_path_is_absolute(filename)) testpath = filename; else testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL); /* we still have a problem here, if GLib's file name encoding would not be utf-8 */ if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR)) files = g_slist_append(files, filename); else { g_print (_("Missing input: %s\n"), filename); g_free (filename); } if (filename != testpath) g_free (testpath); ++i; } } /* given some files to output, we are not starting up the UI */ if (export_file_name || export_file_format || size) dia_is_interactive = FALSE; } if (argv && dia_is_interactive && !version) { #ifdef HAVE_GNOME GnomeProgram *program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, /* haven't found a quick way to pass GOption here */ GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_NONE); client = gnome_master_client(); if(client == NULL) { g_warning(_("Can't connect to session manager!\n")); } else { g_signal_connect(G_OBJECT (client), "save_yourself", G_CALLBACK (save_state), NULL); g_signal_connect(G_OBJECT (client), "die", G_CALLBACK (session_die), NULL); } /* This smaller icon is 48x48, standard Gnome size */ /* gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/dia_gnome_icon.png");*/ #else # ifdef G_THREADS_ENABLED g_thread_init (NULL); # endif gtk_init(&argc, &argv); #endif } else { #ifdef G_THREADS_ENABLED g_thread_init (NULL); #endif g_type_init(); /* * On Windows there is no command line without display so that gtk_init is harmless. * On X11 we need gtk_init_check() to avoid exit() just because there is no display * running outside of X11. */ if (!gtk_init_check(&argc, &argv)) dia_log_message ("Running without display"); } /* done with option parsing, don't leak */ g_free(export_format_string); if (version) { gchar *ver_utf8; gchar *ver_locale; #if (defined __TIME__) && (defined __DATE__) /* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */ ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__); #else ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION); #endif ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL); printf("%s\n", ver_locale); g_free(ver_locale); g_free(ver_utf8); if (verbose) dump_dependencies(); exit(0); } if (!dia_is_interactive) log_to_stderr = TRUE; libdia_init ( (dia_is_interactive ? DIA_INTERACTIVE : 0) | (log_to_stderr ? DIA_MESSAGE_STDERR : 0) | (verbose ? DIA_VERBOSE : 0) ); print_credits(credits); if (dia_is_interactive) { create_user_dirs(); if (!nosplash) app_splash_init(""); /* Init cursors: */ default_cursor = gdk_cursor_new(GDK_LEFT_PTR); ddisplay_set_all_cursor(default_cursor); } dia_register_plugins(); dia_register_builtin_plugin(internal_plugin_init); load_all_sheets(); /* new mechanism */ dia_log_message ("object defaults"); { DiaContext *ctx = dia_context_new (_("Object Defaults")); dia_object_defaults_load (NULL, TRUE /* prefs.object_defaults_create_lazy */, ctx); dia_context_release (ctx); } debug_break(); if (object_get_type("Standard - Box") == NULL) { message_error(_("Couldn't find standard objects when looking for " "object-libs; exiting...\n")); g_critical( _("Couldn't find standard objects when looking for " "object-libs in '%s'; exiting...\n"), dia_get_lib_directory("dia")); exit(1); } persistence_load(); /** Must load prefs after persistence */ prefs_init(); if (dia_is_interactive) { /* further initialization *before* reading files */ active_tool = create_modify_tool(); dia_log_message ("ui creation"); if (use_integrated_ui) { create_integrated_ui(); } else { create_toolbox(); /* for the integrated ui case it is integrated */ persistence_register_window_create("layer_window", (NullaryFunc*)&layer_dialog_create); } /*fill recent file menu */ recent_file_history_init(); /* Set up autosave to check every 5 minutes */ g_timeout_add_seconds(5*60, autosave_check_autosave, NULL); #if 0 /* do we really open these automatically in the next session? */ persistence_register_window_create("diagram_tree", &diagram_tree_show); #endif persistence_register_window_create("sheets_main_dialog", (NullaryFunc*)&sheets_dialog_create); /* In current setup, we can't find the autosaved files. */ /*autosave_restore_documents();*/ } dia_log_message ("diagrams"); made_conversions = handle_all_diagrams(files, export_file_name, export_file_format, size, show_layers, input_directory, output_directory); if (dia_is_interactive && files == NULL && !nonew) { if (use_integrated_ui) { GList * list; file_new_callback(NULL); list = dia_open_diagrams(); if (list) { Diagram * diagram = list->data; diagram_update_extents(diagram); diagram->is_default = TRUE; } } else { gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); Diagram *diagram = new_diagram (filename); g_free(filename); if (diagram != NULL) { diagram_update_extents(diagram); diagram->is_default = TRUE; /* I think this is done in diagram_init() with a call to * layer_dialog_update_diagram_list() */ layer_dialog_set_diagram(diagram); new_display(diagram); } } } g_slist_free(files); if (made_conversions) exit(0); dynobj_refresh_init(); dia_log_message ("initialized"); }