Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / local_includes / sigproc.h
blob7aca80595dc9eb5fcc82e77f7cb07a2337a54c68
1 /* sigproc.h
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #pragma once
10 #include <signal.h>
11 #include "sync.h"
13 #ifdef _NSIG
14 enum
16 __SIGFLUSH = -(_NSIG + 1),
17 __SIGSTRACE = -(_NSIG + 2),
18 __SIGCOMMUNE = -(_NSIG + 3),
19 __SIGPENDING = -(_NSIG + 4),
20 __SIGDELETE = -(_NSIG + 5), /* Not currently used */
21 __SIGFLUSHFAST = -(_NSIG + 6),
22 __SIGHOLD = -(_NSIG + 7),
23 __SIGNOHOLD = -(_NSIG + 8),
24 __SIGSETPGRP = -(_NSIG + 9),
25 __SIGTHREADEXIT = -(_NSIG + 10),
26 __SIGPENDINGALL = -(_NSIG + 11),
27 __SIGNONCYGCHLD = -(_NSIG + 12),
29 #endif
31 #define SIG_BAD_MASK (1 << (SIGKILL - 1))
33 enum procstuff
35 PROC_ADD_CHILD = 1, // set up a new child
36 PROC_ATTACH_CHILD = 2, // attach child or reattach after exec
37 PROC_EXEC_CLEANUP = 3, // cleanup waiting children after exec
38 PROC_CLEARWAIT = 4, // clear all waits - signal arrived
39 PROC_WAIT = 5, // setup for wait() for subproc
40 PROC_EXECING = 6, // used to get a lock when execing
41 PROC_NOTHING = 7 // nothing, really
44 struct sigpacket
46 siginfo_t si;
47 pid_t pid;
48 class _cygtls *sigtls;
49 sigset_t *mask;
50 union
52 HANDLE wakeup;
53 HANDLE thread_handle;
54 struct sigpacket *next;
56 int process ();
57 int setup_handler (void *, struct sigaction&, _cygtls *);
60 void sig_dispatch_pending (bool fast = false);
61 void set_signal_mask (sigset_t&, sigset_t);
62 int handle_sigprocmask (int sig, const sigset_t *set,
63 sigset_t *oldset, sigset_t& opmask);
65 void sig_clear (int);
66 void sig_set_pending (int);
67 int handle_sigsuspend (sigset_t);
69 int proc_subproc (DWORD, uintptr_t);
71 class _pinfo;
72 void proc_terminate ();
73 void sigproc_init ();
74 bool pid_exists (pid_t);
75 sigset_t sig_send (_pinfo *, siginfo_t&, class _cygtls * = NULL);
76 sigset_t sig_send (_pinfo *, int, class _cygtls * = NULL);
77 void signal_fixup_after_exec ();
78 void sigalloc ();
80 int kill_pgrp (pid_t, siginfo_t&);
81 void exit_thread (DWORD) __attribute__ ((noreturn));
82 void setup_signal_exit (int);
83 int sigwait_common (const sigset_t *, siginfo_t *, PLARGE_INTEGER);
85 class no_thread_exit_protect
87 static bool flag;
88 bool modify;
89 public:
90 no_thread_exit_protect (int) {flag = true; modify = true;}
91 ~no_thread_exit_protect ()
93 if (modify)
94 flag = false;
96 no_thread_exit_protect () {modify = false;}
97 operator int () {return flag;}
101 extern "C" void sigdelayed ();
103 extern char myself_nowait_dummy[];
105 extern struct sigaction *global_sigs;
107 class lock_signals
109 bool worked;
110 public:
111 lock_signals ()
113 worked = (bool) sig_send (NULL, __SIGHOLD) == 0;
115 operator int () const
117 return worked;
119 void dont_bother ()
121 worked = false;
123 ~lock_signals ()
125 if (worked)
126 sig_send (NULL, __SIGNOHOLD);
130 class lock_pthread
132 bool bother;
133 public:
134 lock_pthread (): bother (1)
136 pthread::atforkprepare ();
138 void dont_bother ()
140 bother = false;
142 ~lock_pthread ()
144 if (bother)
145 pthread::atforkparent ();
149 class hold_everything
151 bool& ischild;
152 /* Note the order of the locks below. It is important,
153 to avoid races, that the lock order be preserved.
155 pthread is first because it serves as a master lock
156 against other forks being attempted while this one is active.
158 signals is next to stop signal processing for the duration
159 of the fork.
161 process is last. If it is put before signals, then a deadlock
162 could be introduced if the process attempts to exit due to a signal. */
163 lock_pthread pthread;
164 lock_signals signals;
165 lock_process process;
167 public:
168 hold_everything (bool& x): ischild (x) {}
169 operator int () const {return signals;}
171 ~hold_everything()
173 if (ischild)
175 pthread.dont_bother ();
176 process.dont_bother ();
177 signals.dont_bother ();
183 #define myself_nowait ((_pinfo *) myself_nowait_dummy)