当前位置: 首页>>代码示例>>C++>>正文


C++ sigaltstack函数代码示例

本文整理汇总了C++中sigaltstack函数的典型用法代码示例。如果您正苦于以下问题:C++ sigaltstack函数的具体用法?C++ sigaltstack怎么用?C++ sigaltstack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sigaltstack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NaClSignalStackUnregister

void NaClSignalStackUnregister(void)
{
  /*
   * Unregister the signal stack in case a fault occurs between the
   * thread deallocating the signal stack and exiting.  Such a fault
   * could be unsafe if the address space were reallocated before the
   * fault, although that is unlikely.
   */
  stack_t st;
  st.ss_size = 0;
  st.ss_sp = NULL;
  st.ss_flags = SS_DISABLE;
  ZLOGFAIL(sigaltstack(&st, NULL) == -1, errno, "Failed to unregister signal stack");
}
开发者ID:vi4m,项目名称:zerovm,代码行数:14,代码来源:nacl_signal.c

示例2: NaClSignalStackRegister

void NaClSignalStackRegister(void *stack) {
  /*
   * If we set up signal handlers, we must ensure that any thread that
   * runs untrusted code has an alternate signal stack set up.  The
   * default for a new thread is to use the stack pointer from the
   * point at which the fault occurs, but it would not be safe to use
   * untrusted code's %esp/%rsp value.
   */
  stack_t st;
  st.ss_size = SIGNAL_STACK_SIZE;
  st.ss_sp = ((uint8_t *) stack) + STACK_GUARD_SIZE;
  st.ss_flags = 0;
  ZLOGFAIL(sigaltstack(&st, NULL) == -1, errno, "Failed to register signal stack");
}
开发者ID:vi4m,项目名称:zerovm,代码行数:14,代码来源:nacl_signal.c

示例3: main

int
main()
{
    puts("-- 1 (should block) --");

    struct sigaction newAction;
    newAction.sa_handler = (sighandler_t)sigHandler;
    newAction.sa_mask = 0;
    newAction.sa_flags = SA_ONESHOT | SA_ONSTACK | SA_RESTART;
#if defined(__BEOS__) || defined(__HAIKU__)
    newAction.sa_userdata = (void*)kUserDataMagic;
#endif
    sigaction(SIGALRM, &newAction, NULL);

    ualarm(10000, 0);
    wait_for_key();

    puts("-- 2 (does not block, should call handler twice) --");

    newAction.sa_flags = 0;
    sigaction(SIGALRM, &newAction, NULL);

    ualarm(0, 50000);
    wait_for_key();
    wait_for_key();

    ualarm(0, 0);

    puts("-- 3 (alternate stack, should block) --");

#if defined(__BEOS__) && !defined(__HAIKU__)
    set_signal_stack(sAlternateStack, SIGSTKSZ);
#else
    stack_t newStack;
    newStack.ss_sp = sAlternateStack;
    newStack.ss_size = SIGSTKSZ;
    newStack.ss_flags = 0;
    if (sigaltstack(&newStack, NULL) != 0)
        fprintf(stderr, "sigaltstack() failed: %s\n", strerror(errno));
#endif

    newAction.sa_flags = SA_RESTART | SA_ONSTACK;
    sigaction(SIGALRM, &newAction, NULL);

    ualarm(10000, 0);
    wait_for_key();

    puts("-- end --");
    return 0;
}
开发者ID:nielx,项目名称:haiku-serviceskit,代码行数:50,代码来源:signal_test.cpp

示例4: print_signal_stack

void print_signal_stack() {
  int ret_val;
  stack_t oss;

  ret_val = sigaltstack(NULL, &oss);
  if(ret_val) {
    perror("ERROR, sigaltstack failed");
    exit(1);
  }

  printf("ESP of original stack: %p, top: %p, size: %ld, disabled = %s\n",
         oss.ss_sp, (unsigned char *)oss.ss_sp + oss.ss_size, oss.ss_size,
         (oss.ss_flags & SS_DISABLE) ? "true" : "false");
}
开发者ID:alagenchev,项目名称:school_code,代码行数:14,代码来源:sigsuspend.c

示例5: arch_os_thread_init

int arch_os_thread_init(struct thread *thread) {
    stack_t sigstack;
    /* Signal handlers are normally run on the main stack, but we've
     * swapped stacks, require that the control stack contain only
     * boxed data, and expands upwards while the C stack expands
     * downwards. */
    sigstack.ss_sp    = calc_altstack_base(thread);
    sigstack.ss_flags = 0;
    sigstack.ss_size  = calc_altstack_size(thread);
    if(sigaltstack(&sigstack,0)<0)
        lose("Cannot sigaltstack: %s\n",strerror(errno));

    return 1;                   /* success */
}
开发者ID:krwq,项目名称:sbcl,代码行数:14,代码来源:arm-linux-os.c

示例6: minithread_clock_init

/*
 * Register the minithread clock handler by making
 * mini_clock_handler point to it.
 *
 * Then set the signal handler for SIGRTMAX-1 to
 * handle_interrupt.  This signal handler will either
 * interrupt the minithreads, or drop the interrupt,
 * depending on safety conditions.
 *
 * The signals are handled on their own stack to reduce
 * chances of an overrun.
 */
void
minithread_clock_init(interrupt_handler_t clock_handler){
    timer_t timerid;
    struct sigevent sev;
    struct itimerspec its;
    struct sigaction sa;
    stack_t ss;
    mini_clock_handler = clock_handler;

    sem_init(&interrupt_received_sema,0,0);

    ss.ss_sp = malloc(SIGSTKSZ);
    if (ss.ss_sp == NULL){
        perror("malloc.");
        abort();
    }
    ss.ss_size = SIGSTKSZ;
    ss.ss_flags = 0;
    if (sigaltstack(&ss, NULL) == -1){
        perror("signal stack");
        abort();
    }


    /* Establish handler for timer signal */
    sa.sa_handler = (void*)handle_interrupt;
    sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
    sa.sa_sigaction= (void*)handle_interrupt;
    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask,SIGRTMAX-1);
    sigaddset(&sa.sa_mask,SIGRTMAX-2);
    if (sigaction(SIGRTMAX-1, &sa, NULL) == -1)
        errExit("sigaction");

    /* Create the timer */
    sev.sigev_notify = SIGEV_SIGNAL;
    sev.sigev_signo = SIGRTMAX-1;
    sev.sigev_value.sival_ptr = &timerid;
    if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &timerid) == -1)
        errExit("timer_create");

    /* Start the timer */
    its.it_value.tv_sec = (PERIOD) / 1000000000;
    its.it_value.tv_nsec = (PERIOD) % 1000000000;
    its.it_interval.tv_sec = its.it_value.tv_sec;
    its.it_interval.tv_nsec = its.it_value.tv_nsec;

    if (timer_settime(timerid, 0, &its, NULL) == -1)
        errExit("timer_settime");
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:62,代码来源:interrupts.c

示例7: rb_register_sigaltstack

/* alternate stack for SIGSEGV */
void
rb_register_sigaltstack(rb_thread_t *th)
{
    stack_t newSS, oldSS;

    if (!th->altstack)
	rb_bug("rb_register_sigaltstack: th->altstack not initialized\n");

    newSS.ss_sp = th->altstack;
    newSS.ss_size = ALT_STACK_SIZE;
    newSS.ss_flags = 0;

    sigaltstack(&newSS, &oldSS); /* ignore error. */
}
开发者ID:richo,项目名称:unrubby,代码行数:15,代码来源:signal.c

示例8: main

int main()
{
	struct sigaction act;
	
	act.sa_handler = handler;
	act.sa_flags = SA_ONSTACK;
	sigemptyset(&act.sa_mask);
	if (sigaction(SIGXFSZ,  &act, 0) == -1) {
		perror("Unexpected error while attempting to setup test "
		       "pre-conditions");
		return PTS_UNRESOLVED;
	} else {
                printf("INFO: sigaction((SIGXFSZ,  &act, 0) returned successfully\n");
        }


	if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) {
		perror("Unexpected error while attempting to setup test "
		       "pre-conditions");
		return PTS_UNRESOLVED;
	} else {
                printf("INFO: Successfully malloc'd alternative stack\n");
        }

	alt_ss.ss_size = SIGSTKSZ;
	alt_ss.ss_flags = 0;
	
	if (sigaltstack(&alt_ss, (stack_t *)0) == -1) {
		perror("Unexpected error while attempting to setup test "
		       "pre-conditions");
		return PTS_UNRESOLVED;
	} else {
                printf("INFO: sigaltstack(&alt_ss, (stack_t *)0) returned successfully\n");
        }


	if (raise(SIGXFSZ) == -1) {
		perror("Unexpected error while attempting to setup test "
		       "pre-conditions");
		return PTS_UNRESOLVED;
	} else {
                printf("INFO: raise(SGABRT) returned successfully\n");
        }


	printf("Test PASSED\n");

	return PTS_PASS;	
}
开发者ID:CSU-GH,项目名称:okl4_3.0,代码行数:49,代码来源:12-26.c

示例9: QLatin1String

CrashHandlerSetup::CrashHandlerSetup()
{
#ifdef BUILD_CRASH_HANDLER
    if (qgetenv("QTC_USE_CRASH_HANDLER").isEmpty())
        return;

    const QString crashHandlerPath = qApp->applicationDirPath()
        + QLatin1String("/qtcreator_crash_handler");
    crashHandlerPathC = qstrdup(qPrintable(crashHandlerPath));

    // Setup an alternative stack for the signal handler. This way we are able to handle SIGSEGV
    // even if the normal process stack is exhausted.
    stack_t ss;
    ss.ss_sp = signalHandlerStack = malloc(SIGSTKSZ); // Usual requirements for alternative signal stack.
    if (ss.ss_sp == 0) {
        qWarning("Warning: Could not allocate space for alternative signal stack (%s).", Q_FUNC_INFO);
        return;
    }
    ss.ss_size = SIGSTKSZ;
    ss.ss_flags = 0;
    if (sigaltstack(&ss, 0) == -1) {
        qWarning("Warning: Failed to set alternative signal stack (%s).", Q_FUNC_INFO);
        return;
    }

    // Install signal handler for calling the crash handler.
    struct sigaction sa;
    if (sigemptyset(&sa.sa_mask) == -1) {
        qWarning("Warning: Failed to empty signal set (%s).", Q_FUNC_INFO);
        return;
    }
    sa.sa_handler = &signalHandler;
    // SA_RESETHAND - Restore signal action to default after signal handler has been called.
    // SA_NODEFER - Don't block the signal after it was triggered (otherwise blocked signals get
    // inherited via fork() and execve()). Without this the signal will not be delivered to the
    // restarted Qt Creator.
    // SA_ONSTACK - Use alternative stack.
    sa.sa_flags = SA_RESETHAND | SA_NODEFER | SA_ONSTACK;
    // See "man 7 signal" for an overview of signals.
    // Do not add SIGPIPE here, QProcess and QTcpSocket use it.
    const int signalsToHandle[] = { SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGBUS, 0 };
    for (int i = 0; signalsToHandle[i]; ++i) {
        if (sigaction(signalsToHandle[i], &sa, 0) == -1 ) {
            qWarning("Warning: Failed to install signal handler for signal \"%s\" (%s).",
                strsignal(signalsToHandle[i]), Q_FUNC_INFO);
        }
    }
#endif // BUILD_CRASH_HANDLER
}
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:49,代码来源:crashhandlersetup.cpp

示例10: check_stack

void
check_stack(void *buf, const char *label)
{
	struct sigaltstack ss;

	bzero(&ss, sizeof(ss));
	if (sigaltstack(NULL, &ss) != 0)
		err(1, "failed to get sigaltstack in %s", label);
	if (ss.ss_sp != buf ||
	    ss.ss_size != SIGSTKSZ ||
	    ss.ss_flags != 0)
		errx(1, "bad sigaltstack value in %s: "
		    "buf=%p ss_sp=%p ss_size=%zu ss_flags=0x%x",
		    label, buf, ss.ss_sp, ss.ss_size, ss.ss_flags);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:15,代码来源:sigaltstack_fork.c

示例11: sigaltstack

    FatalConditionHandler::FatalConditionHandler() {
        isSet = true;
        stack_t sigStack;
        sigStack.ss_sp = altStackMem;
        sigStack.ss_size = SIGSTKSZ;
        sigStack.ss_flags = 0;
        sigaltstack(&sigStack, &oldSigStack);
        struct sigaction sa = { };

        sa.sa_handler = handleSignal;
        sa.sa_flags = SA_ONSTACK;
        for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
            sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
        }
    }
开发者ID:sakamoto-poteko,项目名称:Catch2,代码行数:15,代码来源:catch_fatal_condition.cpp

示例12: regist_signal_stack

bool regist_signal_stack()
{
	void* signal_stack = malloc(SIGSTKSZ);
	stack_t stack;
	memset(&stack, 0, sizeof(stack));
	stack.ss_sp = (char*)signal_stack;
	stack.ss_size = SIGSTKSZ;

	if (sigaltstack(&stack, NULL) == -1)
	{
		LOG_ERROR("sigaltstack() error");
		return false;
	}

	return true;
}
开发者ID:Light-Games-Ink,项目名称:LMLastChaosSource,代码行数:16,代码来源:SignalProcess.cpp

示例13: setup_altstack

void* setup_altstack(void) {
   stack_t ss;

       ss.ss_sp = malloc(20*1024);
       if (ss.ss_sp == 0) {
	   return NULL;
       }
       ss.ss_size = 20*1024;
       ss.ss_flags = 0;
       
       if (sigaltstack(&ss, NULL) == -1) {
	   perror("sigaltstack");
           return NULL;
       }
       return ss.ss_sp;
}
开发者ID:REMath,项目名称:implementations,代码行数:16,代码来源:susphello.c

示例14: rb_register_sigaltstack

/* alternate stack for SIGSEGV */
void
rb_register_sigaltstack(rb_thread_t *th)
{
    stack_t newSS, oldSS;

    if (th->altstack) return;

    newSS.ss_sp = th->altstack = malloc(ALT_STACK_SIZE);
    if (newSS.ss_sp == NULL)
	/* should handle error */
	rb_bug("rb_register_sigaltstack. malloc error\n");
    newSS.ss_size = ALT_STACK_SIZE;
    newSS.ss_flags = 0;

    sigaltstack(&newSS, &oldSS); /* ignore error. */
}
开发者ID:fi8on,项目名称:ruby,代码行数:17,代码来源:signal.c

示例15: handler

void handler(int signo)
{
	stack_t handler_s;

	if (sigaltstack((stack_t *) 0, &handler_s) == -1) {
		perror
		    ("Unexpected error while attempting to setup test pre-conditions");
		exit(PTS_UNRESOLVED);
	}

	if (handler_s.ss_flags != SS_ONSTACK) {
		printf
		    ("Test FAILED: The alternate stack's ss_flags member does not contain SS_ONSTACK even though the handler is executing on the alternate stack\n");
		exit(PTS_FAIL);
	}
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:16,代码来源:6-1.c


注:本文中的sigaltstack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。