static void sig_usr1(int signo) { time_t starttime; if (canjump == 0) return; /* unexpected signal, ignore */ pr_mask("starting sig_usr1: "); alarm(3); /* SIGALRM in 3 seconds */ starttime = time(NULL); for (;;) /* busy wait for 5 seconds */ if (time(NULL) > starttime + 5) break; pr_mask("finishing sig_usr1: "); canjump = 0; siglongjmp(jmpbuf, 1); /* jump back to main, don't return */ }
static void sigbus_hdl(int sig, siginfo_t *si, void *ptr) { switch (si->si_code) { case BUS_MCEERR_AO: fprintf(stderr, "%s: BUS_MCEERR_AO addr: %p len: %d\n", __func__, si->si_addr, 1 << si->si_addr_lsb); sig_mcerr_ao++; break; case BUS_MCEERR_AR: fprintf(stderr, "%s: BUS_MCEERR_AR addr: %p len: %d\n", __func__, si->si_addr, 1 << si->si_addr_lsb); sig_mcerr_ar++; break; default: sig_count++; break; } siglongjmp(sj_env, 1); }
static void exception_throw(chk_expn_frame *frame,const char *exception,siginfo_t* info) { int32_t sig = 0; chk_expn_thd *expthd = chk_exp_get_thread_expn(); if(!frame) { expthd->sz = backtrace(expthd->bt, LOG_STACK_SIZE); expthd->exception = exception; expthd->addr = info->si_addr; frame = chk_exp_top(); } if(frame) { frame->is_process = 0; if(exception == segfault) sig = SIGSEGV; else if(exception == sigbug) sig = SIGBUS; else if(exception == sigfpe) sig = SIGFPE; siglongjmp(frame->jumpbuffer,sig); }else { chk_exp_log_exption_stack(); //没有try,直接终止进程 exit(0); } }
int ckptRestoreStack(ckptImage * image, size_t size, void *stack_start) { int dummy; if ((void *)&dummy > (void *)((char *)stack_start - size - 2*STACK_GAP)) ckptRestoreStack(image, size, stack_start); /* Here we do some hack, reading directly from file, but there's no other way here */ dummy = image->fd; F_REAL_READ(image->fd, (void *)((char *)stack_start - size - STACK_GAP), size); F_REAL_CLOSE(dummy); ckptSystemIgnore--; siglongjmp(ckptJumpBuffer, 1); /* XXX: to make compiler happy */ return 0; }
static void handler(int sig) { /* UNSAFE: This handler uses non-async-signal-safe functions (printf(), strsignal(), printSigMask(); see Section 21.1.2) */ printf("Received signal %d (%s), signal mask is:\n", sig, strsignal(sig)); printSigMask(stdout, NULL); if (!canJump) { printf("'env' buffer not yet set, doing a simple return\n"); return; } #ifdef USE_SIGSETJMP siglongjmp(senv, 1); #else longjmp(env, 1); #endif }
static void coroutine_trampoline(int i0, int i1) { union cc_arg arg; CoroutineUContext *self; Coroutine *co; arg.i[0] = i0; arg.i[1] = i1; self = arg.p; co = &self->base; /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } while (true) { co->entry(co->entry_arg); qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE); } }
void sig_hldr(int signal, siginfo_t *si, void *arg) { pthread_t id; int i; //printf("Caught segfault at address %p ", si->si_addr); id = pthread_self(); printf("\n thread id = %lu\n",id); for (i = 0; i < gloc; i++) { if (tid[i] == id) break; } if (i >= gloc) printf("\nmain thread: caught signal %d\n", signal); else printf("\nthread no %d: thread id %lu: caught signal %d\n", i+1, id, signal); siglongjmp(env, i+1); return; }
/* SIGTSTP handler. This function care user's ^Z input. */ void sigtstp (int sig) { /* Execute "end" command. */ vtysh_execute ("end"); /* Initialize readline. */ rl_initialize (); printf ("\n"); /* Check jmpflag for duplicate siglongjmp(). */ if (! jmpflag) return; /* vtysh_kill_more();*/ jmpflag = 0; /* Back to main command loop. */ siglongjmp (jmpbuf, 1); }
static void fatal_error_handler (j_common_ptr cinfo) { struct error_handler_data *errmgr; char buffer[JMSG_LENGTH_MAX]; errmgr = (struct error_handler_data *) cinfo->err; /* Create the message */ (* cinfo->err->format_message) (cinfo, buffer); if ((errmgr->error != NULL) && (*errmgr->error == NULL)) g_set_error (errmgr->error, JPEG_ERROR, JPEG_ERROR_FAILED, "Error interpreting JPEG image\n\n%s", buffer); siglongjmp (errmgr->setjmp_buffer, 1); g_assert_not_reached (); }
static void sig_usr1(int signo) { time_t starttime; if (canjump == 0) return; // unexpected signal, ignore pr_mask("starting sig_usr1: "); alarm(3); starttime = time(NULL); for (;;) // busy wait for 5 seconds if (time(NULL) > starttime + 5) break; pr_mask("finishing sig_usr1: "); canjump = 0; siglongjmp(jmpbuf, 1); }
VCSI_OBJECT error(VCSI_CONTEXT vc, char* text, VCSI_OBJECT obj) { #ifdef DEBUG printf("Error: %s - %s\n",text,print_obj(vc,vc->tmpstr,obj,1)); #endif #ifdef WITH_THREADS pthread_mutex_lock(vc->error_mutex); #endif vc->errobj->type = SYMBOL; VCELL(vc->errobj) = cons(vc,make_string(vc,text),cons(vc,obj,NULL)); vc->got_error = 1; #ifdef WITH_THREADS pthread_mutex_unlock(vc->error_mutex); #endif siglongjmp(DYNERR(vc->root_wind),1); return vc->errobj; }
static void timer(int signum) { (void)signum; logmsg("alarm!"); timeout += rexmtval; if(timeout >= maxtimeout) { if(wrotepidfile) { wrotepidfile = 0; unlink(pidname); } if(serverlogslocked) { serverlogslocked = 0; clear_advisor_read_lock(SERVERLOGS_LOCK); } exit(1); } #ifdef HAVE_SIGSETJMP siglongjmp(timeoutbuf, 1); #endif }
void catch_signals(int signo) { switch(signo) { case SIGUSR1: quitflag++; // signal to the timer loop break; case SIGSEGV: siglongjmp(env, 1);// jump back to the setjmp() point break; case SIGTERM: gFrame->Close(); break; default: break; } }
/* Handler for SIGHUP, SIGINT */ void sage_interrupt_handler(int sig) { #if ENABLE_DEBUG_INTERRUPT if (sage_interrupt_debug_level >= 1) { fprintf(stderr, "\n*** SIG %i *** %s sig_on\n", sig, (_signals.sig_on_count > 0) ? "inside" : "outside"); if (sage_interrupt_debug_level >= 3) print_backtrace(); fflush(stderr); /* Store time of this signal, unless there is already a * pending signal. */ if (!_signals.interrupt_received) gettimeofday(&sigtime, NULL); } #endif if (_signals.sig_on_count > 0) { if (!_signals.block_sigint) { /* Actually raise an exception so Python can see it */ sig_raise_exception(sig); /* Jump back to sig_on() (the first one if there is a stack) */ reset_CPU(); siglongjmp(_signals.env, sig); } } else { /* Set the Python interrupt indicator, which will cause the * Python-level interrupt handler in sage/ext/c_lib.pyx to be * called. */ PyErr_SetInterrupt(); } /* If we are here, we cannot handle the interrupt immediately, so * we store the signal number for later use. But make sure we * don't overwrite a SIGHUP or SIGTERM which we already received. */ if (_signals.interrupt_received != SIGHUP && _signals.interrupt_received != SIGTERM) _signals.interrupt_received = sig; }
void hilo5(){ sigsetjmp(env_5,1); if (h5==0) { } else{ end_h5=0; static int i=0; static float j=0; static long double acc=1.0; acc_h5=0.0; while(1){ int returned_from_longjump=1; if ((returned_from_longjump = sigsetjmp(env_5,1)) ==0){ siglongjmp(env_sc,1);} if (end_h5==0){ for(i=1;i<n_5+1;i++){ sigsetjmp(env_5,1); acc=1.0; for (j=2*i;j>i;j--){ acc*=j/(4*(j-i)); } porcentajehilo5actual = i*57/n_5; acc=acc/(2*i+1); acc_h5=acc_h5+acc; } end_h5=1; } } } }
extern void rc_raise(ecodes e) { if (e == eError && rc_pid != getpid()) exit(1); /* child processes exit on an error/signal */ for (; estack != NULL; estack = estack->prev) if (estack->e != e) { if (e == eBreak && estack->e != eArena && estack->e != eVarstack) rc_error("break outside of loop"); else if (e == eReturn && estack->e == eError) /* can return from loops inside functions */ rc_error("return outside of function"); switch (estack->e) { default: break; case eVarstack: varrm(estack->data.name, TRUE); break; case eArena: restoreblock(estack->data.b); break; case eFifo: unlink(estack->data.name); break; case eFd: close(estack->data.fd); break; } } else { if (e == eError && !estack->interactive) { popinput(); } else { Jbwrap *j = estack->data.jb; interactive = estack->interactive; estack = estack->prev; siglongjmp(j->j, 1); } } rc_exit(1); /* top of exception stack */ }
/* Try to jump to userland. */ static void coffeecatch_try_jump_userland(native_code_handler_struct* const t, const int code, siginfo_t *const si, void * const sc) { (void) si; /* UNUSED */ (void) sc; /* UNUSED */ /* Valid context ? */ if (t != NULL && t->ctx_is_set) { DEBUG(print("calling siglongjmp()\n")); /* Invalidate the context */ t->ctx_is_set = 0; /* We need to revert the alternate stack before jumping. */ coffeecatch_revert_alternate_stack(); /* * Note on async-signal-safety of siglongjmp() [POSIX] : * "Note that longjmp() and siglongjmp() are not in the list of * async-signal-safe functions. This is because the code executing after * longjmp() and siglongjmp() can call any unsafe functions with the same * danger as calling those unsafe functions directly from the signal * handler. Applications that use longjmp() and siglongjmp() from within * signal handlers require rigorous protection in order to be portable. * Many of the other functions that are excluded from the list are * traditionally implemented using either malloc() or free() functions or * the standard I/O library, both of which traditionally use data * structures in a non-async-signal-safe manner. Since any combination of * different functions using a common data structure can cause * async-signal-safety problems, this volume of POSIX.1-2008 does not * define the behavior when any unsafe function is called in a signal * handler that interrupts an unsafe function." */ siglongjmp(t->ctx, code); } }
static void sig_usr1(int signo) { time_t starttime; if (0 == canjump) { return ; } pr_mask("starting sig_usr1:"); alarm(3); starttime = time(NULL); /* 时间太长了! for (; ;) { if (time(NULL) > starttime + 5) { break; } } */ pr_mask("finishing sig_usr1:"); canjump = 0; siglongjmp(jmpbuf,1); }
void int_handler(int signo) { if (signo == SIGPIPE) { siglongjmp(int_jb, 1); } if (signo == SIGINT) { // I need to kill less so less can wipe the screen if (!kill(less_pid, SIGTERM)) waitpid(less_pid, NULL, 0); else fprintf(stderr, "Error while killing less: %s\n", strerror(errno)); // Less disables echo so I need to re-enable it struct termios tp; if (!tcgetattr(STDIN_FILENO, &tp)) { tp.c_lflag |= ECHO; if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) < 0) fprintf(stderr, "Error while setting terminal attributes: %s\n", strerror(errno)); } else { fprintf(stderr, "Error while getting terminal attributes: %s\n", strerror(errno)); } fprintf(stderr, "\nFiles Processed: %d, Bytes Processed: %d!\n", dwFilesProcessed, dwBytesProcessed); exit(1); } }
static Term VarNames(VarEntry *p, Term l USES_REGS) { if (p != NULL) { if (strcmp(p->VarRep, "_") != 0) { Term t[2]; Term o; t[0] = MkAtomTerm(Yap_LookupAtom(p->VarRep)); t[1] = p->VarAdr; o = Yap_MkApplTerm(FunctorEq, 2, t); o = MkPairTerm(o, VarNames(p->VarRight, VarNames(p->VarLeft, l PASS_REGS) PASS_REGS)); if (HR > ASP - 4096) { save_machine_regs(); siglongjmp(LOCAL_IOBotch, 1); } return (o); } else { return VarNames(p->VarRight, VarNames(p->VarLeft, l PASS_REGS) PASS_REGS); } } else { return (l); } }
void handle_sigint(SIGNAL_ARGS) { int save_errno = errno; /* Don't muck around if prompting for a password. */ if (prompt_state) return; if (cancelConn == NULL) siglongjmp(main_loop_jmp, 1); cancel_pressed = true; if (PQrequestCancel(cancelConn)) write_stderr("Cancel request sent\n"); else { write_stderr("Could not send cancel request: "); write_stderr(PQerrorMessage(cancelConn)); } errno = save_errno; /* just in case the write changed it */ }
static void handle_sigint(SIGNAL_ARGS) { int save_errno = errno; int rc; char errbuf[256]; /* if we are waiting for input, longjmp out of it */ if (sigint_interrupt_enabled) { sigint_interrupt_enabled = false; siglongjmp(sigint_interrupt_jmp, 1); } /* else, set cancel flag to stop any long-running loops */ cancel_pressed = true; /* and send QueryCancel if we are processing a database query */ if (cancelConn != NULL) { if (PQcancel(cancelConn, errbuf, sizeof(errbuf))) { rc = write_stderr("Cancel request sent\n"); (void) rc; /* ignore errors, nothing we can do here */ } else { rc = write_stderr("Could not send cancel request: "); (void) rc; /* ignore errors, nothing we can do here */ sprintf(errbuf, "signal: %d\n", postgres_signal_arg); rc = write_stderr(errbuf); (void) rc; /* ignore errors, nothing we can do here */ } } errno = save_errno; /* just in case the write changed it */ }
void send_fd_timed_out(int sigcode) { char *errstr; errstr = newString(HUGE_STRING_LEN,STR_TMP); if(exit_callback) (*exit_callback)(); if (sigcode != SIGPIPE) { sprintf(errstr,"HTTPd: send timed out for %s, URL: %s", (gCurrentRequest->remote_name ? gCurrentRequest->remote_name : "remote host"), (gCurrentRequest->url ? gCurrentRequest->url : "-")); } else { sprintf(errstr,"HTTPd: send aborted for %s, URL: %s", (gCurrentRequest->remote_name ? gCurrentRequest->remote_name : "remote host"), (gCurrentRequest->url ? gCurrentRequest->url : "-")); } log_error(errstr,gCurrentRequest->hostInfo->error_log); log_transaction(gCurrentRequest); alarm(0); signal(SIGALRM,SIG_IGN); signal(SIGPIPE,SIG_IGN); CloseAll(); /* close all spurious file descriptors */ if (!standalone) { fclose(stdin); fclose(stdout); exit(0); } else { #ifdef NO_SIGLONGJMP longjmp(jmpbuffer,1); #else siglongjmp(jmpbuffer,1); #endif /* NO_SIGLONGJMP */ } }
/* * error function */ void ia32_panic(const char *str, ...) { extern char *cpu_reg2str(void); char buf[2048]; va_list ap; va_start(ap, str); vsnprintf(buf, sizeof(buf), str, ap); va_end(ap); strcat(buf, "\n"); strcat(buf, cpu_reg2str()); msgbox("ia32_panic", buf); #if defined(IA32_REBOOT_ON_PANIC) VERBOSE(("ia32_panic: reboot")); pccore_reset(); siglongjmp(exec_1step_jmpbuf, 2); #else __ASSERT(0); exit(1); #endif }
void sig_pipe(int sig) { server->error++; server->sigpipe++; #ifdef PRE_FORK (server->childs)[my_num].status = S_SIGPIPE; #if 0 (server->childs)[my_num].pid = 0x00; #endif shutdown(0, 2); #endif #ifdef WEB_ERROR_LOG weblog_line(server->error_log, "ERR=\"%s\" REQ=\"%s %s\" UA=\"%s\"", "Caught SIGPIPE", request_rec->request_method, request_rec->URI, request_rec->user_agent); fflush(server->error_log); #endif #ifdef PRE_FORK siglongjmp(env, 1); #else _exit(13); /* SIGPIPE 13 Exit Broken Pipe */ #endif }
/* Allows the user to cancel a long operation and get back to the shell. */ void BackToTop(int sigNum) { gGotSig = sigNum; if (sigNum == SIGPIPE) { if (gRunningCommand == 1) { (void) fprintf(stderr, "Unexpected broken pipe.\n"); gRunningCommand = 0; } else { SetXtermTitle("RESTORE"); exit(1); } } else if (sigNum == SIGINT) { if (gRunningCommand == 0) gDoneApplication = 1; } if (gMayBackToTopJmp > 0) { #ifdef HAVE_SIGSETJMP siglongjmp(gBackToTopJmp, 1); #else /* HAVE_SIGSETJMP */ longjmp(gBackToTopJmp, 1); #endif /* HAVE_SIGSETJMP */ } } /* BackToTop */
static void sighandler(int sig) { int childno; sigwas = sig; switch (sig) { case SIGALRM: childno = find_childno(getpid()); if (childno == CHILD_NOT_FOUND) _exit(EXIT_SUCCESS); /* Hell knows what happened, just bail. */ /* Re-arm the alarm. */ alarm(1); /* Jump back, maybe we'll make progress. */ (void)signal(sig, sighandler); siglongjmp(ret_jump, 1); break; default: _exit(EXIT_SUCCESS); } }
void intr(int ignore) { (void)ignore; siglongjmp(toplevel, 1); }
static int clone_fn(void *data_ptr) { fork_state_t *state = (fork_state_t *)data_ptr; siglongjmp(state->env, 1); }
static void write_socket_timeout(int nouse) { siglongjmp(socket_env, 1); }