2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_
|
2022-08-13 20:11:56 +00:00
|
|
|
#include "libc/calls/struct/siginfo.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/calls/struct/sigset.h"
|
2022-08-13 20:11:56 +00:00
|
|
|
#include "libc/calls/ucontext.h"
|
2022-04-12 12:20:17 +00:00
|
|
|
#include "libc/dce.h"
|
2022-06-09 03:01:28 +00:00
|
|
|
#include "libc/sysv/consts/sig.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
2022-08-13 20:11:56 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
typedef void (*sighandler_t)(int);
|
2022-09-02 12:08:35 +00:00
|
|
|
typedef void (*sigaction_f)(int, struct siginfo *,
|
|
|
|
void * /*struct ucontext **/);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
struct sigaction { /* cosmo abi */
|
|
|
|
union {
|
|
|
|
sighandler_t sa_handler;
|
|
|
|
sigaction_f sa_sigaction;
|
|
|
|
};
|
|
|
|
uint64_t sa_flags;
|
|
|
|
void (*sa_restorer)(void);
|
|
|
|
struct sigset sa_mask;
|
|
|
|
int64_t __pad;
|
2021-10-14 00:27:13 +00:00
|
|
|
};
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-10-14 00:27:13 +00:00
|
|
|
sighandler_t signal(int, sighandler_t);
|
|
|
|
int sigaction(int, const struct sigaction *, struct sigaction *);
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
|
|
|
|
|
|
void _init_onntconsoleevent(void);
|
|
|
|
void _init_wincrash(void);
|
2022-03-25 14:11:44 +00:00
|
|
|
void _check_sigwinch();
|
2021-10-14 00:27:13 +00:00
|
|
|
|
|
|
|
#ifndef __SIGACTION_YOINK
|
|
|
|
#define __SIGACTION_YOINK(SIG) \
|
|
|
|
do { \
|
|
|
|
if (SupportsWindows()) { \
|
|
|
|
if (__builtin_constant_p(SIG)) { \
|
|
|
|
switch (SIG) { \
|
|
|
|
case SIGINT: \
|
|
|
|
case SIGQUIT: \
|
|
|
|
case SIGHUP: \
|
|
|
|
case SIGTERM: \
|
|
|
|
YOINK(_init_onntconsoleevent); \
|
|
|
|
break; \
|
|
|
|
case SIGTRAP: \
|
|
|
|
case SIGILL: \
|
|
|
|
case SIGSEGV: \
|
|
|
|
case SIGABRT: \
|
|
|
|
case SIGFPE: \
|
|
|
|
YOINK(_init_wincrash); \
|
|
|
|
break; \
|
2022-03-16 20:33:13 +00:00
|
|
|
case SIGWINCH: \
|
|
|
|
YOINK(_check_sigwinch); \
|
|
|
|
break; \
|
2021-10-14 00:27:13 +00:00
|
|
|
default: \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
YOINK(_init_onntconsoleevent); \
|
|
|
|
YOINK(_init_wincrash); \
|
2022-03-16 20:33:13 +00:00
|
|
|
YOINK(_check_sigwinch); \
|
2021-10-14 00:27:13 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define sigaction(SIG, ACT, OLD) \
|
|
|
|
({ \
|
|
|
|
__SIGACTION_YOINK(SIG); \
|
|
|
|
sigaction(SIG, (ACT), OLD); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define signal(SIG, HAND) \
|
|
|
|
({ \
|
|
|
|
__SIGACTION_YOINK(SIG); \
|
|
|
|
signal(SIG, HAND); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#endif /* GNU && !ANSI */
|
2022-08-13 20:11:56 +00:00
|
|
|
|
2021-10-14 00:27:13 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
2020-06-15 14:18:57 +00:00
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_ */
|