| 1 |
/**************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* This file is part of Frama-C. */ |
| 4 |
/* */ |
| 5 |
/* Copyright (C) 2007-2022 */ |
| 6 |
/* CEA (Commissariat à l'énergie atomique et aux énergies */ |
| 7 |
/* alternatives) */ |
| 8 |
/* */ |
| 9 |
/* you can redistribute it and/or modify it under the terms of the GNU */ |
| 10 |
/* Lesser General Public License as published by the Free Software */ |
| 11 |
/* Foundation, version 2.1. */ |
| 12 |
/* */ |
| 13 |
/* It is distributed in the hope that it will be useful, */ |
| 14 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 15 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 16 |
/* GNU Lesser General Public License for more details. */ |
| 17 |
/* */ |
| 18 |
/* See the GNU Lesser General Public License version 2.1 */ |
| 19 |
/* for more details (enclosed in the file licenses/LGPLv2.1). */ |
| 20 |
/* */ |
| 21 |
/**************************************************************************/ |
| 22 |
|
| 23 |
#ifndef __FC_SIGNAL |
| 24 |
#define __FC_SIGNAL |
| 25 |
|
| 26 |
/* ISO C: 7.14 */ |
| 27 |
|
| 28 |
#include "features.h" |
| 29 |
__PUSH_FC_STDLIB |
| 30 |
#include "__fc_machdep.h" |
| 31 |
#include "__fc_define_pid_t.h" |
| 32 |
#include "__fc_define_uid_and_gid.h" |
| 33 |
#include "__fc_define_pthread_types.h" |
| 34 |
|
| 35 |
__BEGIN_DECLS |
| 36 |
|
| 37 |
/* TODO: put sig_atomic_t in machdep */ |
| 38 |
#ifndef __sig_atomic_t_defined |
| 39 |
typedef volatile int sig_atomic_t; |
| 40 |
#define __sig_atomic_t_defined |
| 41 |
#endif |
| 42 |
|
| 43 |
typedef void (*__fc_sighandler_t) (int); |
| 44 |
|
| 45 |
#define sighandler_t __fc_sighandler_t |
| 46 |
|
| 47 |
/* for BSD 4.4 */ |
| 48 |
typedef __fc_sighandler_t sig_t; |
| 49 |
|
| 50 |
extern void __fc_sig_dfl(int); |
| 51 |
extern void __fc_sig_ign(int); |
| 52 |
extern void __fc_sig_err(int); |
| 53 |
|
| 54 |
#define SIG_DFL (&__fc_sig_dfl) /* default signal handling */ |
| 55 |
#define SIG_IGN (&__fc_sig_ign) /* ignore signal */ |
| 56 |
#define SIG_ERR (&__fc_sig_err) /* error return from signal */ |
| 57 |
|
| 58 |
#define SIG_BLOCK 0 |
| 59 |
#define SIG_UNBLOCK 1 |
| 60 |
#define SIG_SETMASK 2 |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#define SIGHUP 1 |
| 65 |
#define SIGINT 2 |
| 66 |
#define SIGQUIT 3 |
| 67 |
#define SIGILL 4 |
| 68 |
#define SIGTRAP 5 |
| 69 |
#define SIGABRT 6 |
| 70 |
#define SIGIOT 6 |
| 71 |
#define SIGBUS 7 |
| 72 |
#define SIGFPE 8 |
| 73 |
#define SIGKILL 9 |
| 74 |
#define SIGUSR1 10 |
| 75 |
#define SIGSEGV 11 |
| 76 |
#define SIGUSR2 12 |
| 77 |
#define SIGPIPE 13 |
| 78 |
#define SIGALRM 14 |
| 79 |
#define SIGTERM 15 |
| 80 |
#define SIGSTKFLT 16 |
| 81 |
#define SIGCHLD 17 |
| 82 |
#define SIGCONT 18 |
| 83 |
#define SIGSTOP 19 |
| 84 |
#define SIGTSTP 20 |
| 85 |
#define SIGTTIN 21 |
| 86 |
#define SIGTTOU 22 |
| 87 |
#define SIGURG 23 |
| 88 |
#define SIGXCPU 24 |
| 89 |
#define SIGXFSZ 25 |
| 90 |
#define SIGVTALRM 26 |
| 91 |
#define SIGPROF 27 |
| 92 |
#define SIGWINCH 28 |
| 93 |
#define SIGIO 29 |
| 94 |
#define SIGPOLL SIGIO |
| 95 |
/* |
| 96 |
#define SIGLOST 29 |
| 97 |
*/ |
| 98 |
#define SIGPWR 30 |
| 99 |
#define SIGSYS 31 |
| 100 |
#define SIGUNUSED 31 |
| 101 |
|
| 102 |
#define SIGRTMIN 32 |
| 103 |
#define SIGRTMAX 64 |
| 104 |
|
| 105 |
#define NSIG __FC_NSIG |
| 106 |
#ifdef __FC__NSIG |
| 107 |
#define _NSIG __FC__NSIG |
| 108 |
#endif |
| 109 |
|
| 110 |
#define SA_NOCLDSTOP 0x00000001 |
| 111 |
#define SA_NOCLDWAIT 0x00000002 |
| 112 |
#define SA_SIGINFO 0x00000004 |
| 113 |
#define SA_ONSTACK 0x08000000 |
| 114 |
#define SA_RESTART 0x10000000 |
| 115 |
#define SA_NODEFER 0x40000000 |
| 116 |
#define SA_RESETHAND 0x80000000 |
| 117 |
|
| 118 |
#define SA_NOMASK SA_NODEFER |
| 119 |
#define SA_ONESHOT SA_RESETHAND |
| 120 |
|
| 121 |
/*@ assigns \nothing; */ |
| 122 |
extern void (*signal(int sig, void (*func)(int)))(int); |
| 123 |
|
| 124 |
/*@ |
| 125 |
assigns \nothing; |
| 126 |
ensures never_terminates: \false; */ |
| 127 |
extern int raise(int sig); |
| 128 |
#include "__fc_define_sigset_t.h" |
| 129 |
|
| 130 |
union sigval { |
| 131 |
int sival_int; |
| 132 |
void *sival_ptr; |
| 133 |
}; |
| 134 |
|
| 135 |
struct sigevent { |
| 136 |
int sigev_notify; |
| 137 |
int sigev_signo; |
| 138 |
union sigval sigev_value; |
| 139 |
void (*sigev_notify_function) (union sigval); |
| 140 |
pthread_attr_t *sigev_notify_attributes; |
| 141 |
}; |
| 142 |
|
| 143 |
#ifndef __have_siginfo_t |
| 144 |
#define __have_siginfo_t |
| 145 |
typedef struct __fc_siginfo_t { |
| 146 |
int si_signo; |
| 147 |
int si_code; |
| 148 |
union sigval si_value; |
| 149 |
int si_errno; |
| 150 |
pid_t si_pid; |
| 151 |
uid_t si_uid; |
| 152 |
void *si_addr; |
| 153 |
int si_status; |
| 154 |
int si_band; |
| 155 |
} siginfo_t; |
| 156 |
#endif |
| 157 |
|
| 158 |
struct sigaction { |
| 159 |
void (*sa_handler)(int); |
| 160 |
void (*sa_sigaction)(int, siginfo_t *, void *); |
| 161 |
sigset_t sa_mask; |
| 162 |
int sa_flags; |
| 163 |
}; |
| 164 |
|
| 165 |
/*@ |
| 166 |
requires valid_set: \valid(set); |
| 167 |
assigns *set \from \nothing; |
| 168 |
assigns \result \from \nothing; |
| 169 |
ensures initialization:set: \initialized(set); |
| 170 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 171 |
*/ |
| 172 |
extern int sigemptyset(sigset_t *set); |
| 173 |
|
| 174 |
/*@ |
| 175 |
requires valid_set: \valid(set); |
| 176 |
assigns *set \from \nothing; |
| 177 |
assigns \result \from \nothing; |
| 178 |
ensures initialization:set: \initialized(set); |
| 179 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 180 |
*/ |
| 181 |
extern int sigfillset(sigset_t *set); |
| 182 |
|
| 183 |
/*@ |
| 184 |
requires valid_set: \valid(set); |
| 185 |
requires initialization:set: \initialized(set); |
| 186 |
assigns *set \from indirect:signum; |
| 187 |
assigns \result \from signum; |
| 188 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 189 |
*/ |
| 190 |
extern int sigaddset(sigset_t *set, int signum); |
| 191 |
|
| 192 |
/*@ |
| 193 |
requires valid_set: \valid(set); |
| 194 |
requires initialization:set: \initialized(set); |
| 195 |
assigns *set \from indirect:signum; |
| 196 |
assigns \result \from signum; |
| 197 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 198 |
*/ |
| 199 |
extern int sigdelset(sigset_t *set, int signum); |
| 200 |
|
| 201 |
/*@ |
| 202 |
requires valid_read_set: \valid_read(set); |
| 203 |
requires initialization:set: \initialized(set); |
| 204 |
assigns \result \from *set, signum; |
| 205 |
ensures result_found_not_found_or_error: \result == 0 || \result == 1 |
| 206 |
|| \result == -1; |
| 207 |
*/ |
| 208 |
extern int sigismember(const sigset_t *set, int signum); |
| 209 |
|
| 210 |
__FC_EXTERN struct sigaction __fc_sigaction[SIGRTMAX+1]; |
| 211 |
struct sigaction *__fc_p_sigaction = __fc_sigaction; |
| 212 |
|
| 213 |
/*@ // missing: errno may be set to EINVAL when trying to set some signals |
| 214 |
requires valid_signal: 0 <= signum <= SIGRTMAX; |
| 215 |
requires valid_oldact_or_null: oldact == \null || \valid(oldact); |
| 216 |
requires valid_read_act_or_null: act == \null || \valid_read(act); |
| 217 |
requires separation:separated_acts: \separated(act, oldact); |
| 218 |
assigns *oldact \from __fc_p_sigaction; |
| 219 |
assigns __fc_p_sigaction[signum] \from *act; |
| 220 |
assigns \result \from indirect:signum, indirect:act, indirect:*act, |
| 221 |
indirect:oldact, indirect:*oldact; |
| 222 |
ensures act_changed: act == \null || \subset(__fc_p_sigaction[signum], *act); |
| 223 |
ensures oldact_assigned: oldact == \null || |
| 224 |
\subset({*oldact}, __fc_p_sigaction[signum]); |
| 225 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 226 |
*/ |
| 227 |
extern int sigaction(int signum, const struct sigaction *restrict act, |
| 228 |
struct sigaction *restrict oldact); |
| 229 |
|
| 230 |
/*@ // missing: assigns *oldset \from 'previous mask in process' |
| 231 |
requires valid_set_or_null: set == \null || \valid_read(set); |
| 232 |
requires valid_how: set != \null ==> |
| 233 |
how \in {SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK}; |
| 234 |
requires valid_oldset_or_null: oldset == \null || \valid(oldset); |
| 235 |
requires separation: (set == oldset == \null) || |
| 236 |
\separated(set, oldset); |
| 237 |
assigns \result \from indirect:how, indirect:set, indirect:oldset; |
| 238 |
assigns *oldset \from indirect:how, indirect:oldset; |
| 239 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 240 |
ensures initialization:oldset_initialized: |
| 241 |
oldset != \null && \result == 0 ==> \initialized(oldset); |
| 242 |
*/ |
| 243 |
extern int sigprocmask(int how, const sigset_t * restrict set, |
| 244 |
sigset_t *restrict oldset); |
| 245 |
|
| 246 |
/*@ // missing: errno may be set to EINVAL, EPERM, ESRCH |
| 247 |
// missing: assigns 'other processes' \from 'other processes' |
| 248 |
assigns \result \from indirect:pid, indirect: sig; |
| 249 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 250 |
*/ |
| 251 |
extern int kill(pid_t pid, int sig); |
| 252 |
|
| 253 |
/*@ // missing: errno may be set to EINVAL, EPERM, ESRCH |
| 254 |
// missing: assigns 'other processes' \from 'other processes' |
| 255 |
assigns \result \from indirect:pgrp, indirect: sig; |
| 256 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 257 |
*/ |
| 258 |
extern int killpg(pid_t pgrp, int sig); |
| 259 |
|
| 260 |
__END_DECLS |
| 261 |
|
| 262 |
__POP_FC_STDLIB |
| 263 |
#endif |