Debian Codegraph @

src/h/stack-resize.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */
3
4
5 /*
6 * Copyright (c) 2001, Juan Jose Garcia Ripoll.
7 *
8 * See file 'LICENSE' for the copyright details.
9 *
10 */
11
12 /* internal.h -- safe stack resizing */
13
14 #ifndef ECL_STACK_RESIZE_H
15 #define ECL_STACK_RESIZE_H
16
17 /* We can't block interrupts with ecl_disable_interrupts() and write
18 * in the thread local environment if we use fast interrupt dispatch
19 * via mprotect(), so we have to use sigprocmask instead. No
20 * performance problems, since this is only used for stack
21 * resizing. */
22 #if defined(ECL_THREADS) && defined(ECL_USE_MPROTECT)
23 # ifdef HAVE_SIGPROCMASK
24 # include <signal.h>
25 # define ECL_STACK_RESIZE_DISABLE_INTERRUPTS(the_env) \
26 sigset_t __sigset_new, __sigset_previous; \
27 sigfillset(&__sigset_new); \
28 sigdelset(&__sigset_new, SIGSEGV); \
29 sigdelset(&__sigset_new, SIGBUS); \
30 pthread_sigmask(SIG_BLOCK, &__sigset_new, &__sigset_previous)
31 # define ECL_STACK_RESIZE_ENABLE_INTERRUPTS(the_env) \
32 pthread_sigmask(SIG_SETMASK, &__sigset_previous, NULL)
33 # else
34 # error "Can't protect stack resizing from interrupts without sigprocmask. Either build ECL without mprotect() or live with possible race conditions."
35 # endif /* HAVE_SIGPROCMASK */
36 #else
37 # define ECL_STACK_RESIZE_DISABLE_INTERRUPTS(the_env) ecl_disable_interrupts_env(the_env);
38 # define ECL_STACK_RESIZE_ENABLE_INTERRUPTS(the_env) ecl_enable_interrupts_env(env);
39 # endif /* ECL_THREADS && ECL_USE_MPROTECT */
40
41 #endif /* ECL_STACK_RESIZE_H */