OSDN Git Service

2002-03-01 David O'Brien <obrien@FreeBSD.org>
[pf3gnuchains/pf3gnuchains3x.git] / winsup / cygwin / sigproc.h
1 /* sigproc.h
2
3    Copyright 1997, 1998, 2000, 2001, 2002 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #include <signal.h>
12
13 #define EXIT_SIGNAL      0x010000
14 #define EXIT_REPARENTING 0x020000
15 #define EXIT_NOCLOSEALL  0x040000
16
17 enum procstuff
18 {
19   PROC_ADDCHILD         = 1,    // add a new subprocess to list
20   PROC_CHILDTERMINATED  = 2,    // a child died
21   PROC_CLEARWAIT        = 3,    // clear all waits - signal arrived
22   PROC_WAIT             = 4,    // setup for wait() for subproc
23   PROC_NOTHING          = 5     // nothing, really
24 };
25
26 typedef struct struct_waitq
27 {
28   int pid;
29   int options;
30   int status;
31   HANDLE ev;
32   void *rusage;                 /* pointer to potential rusage */
33   struct struct_waitq *next;
34   HANDLE thread_ev;
35 } waitq;
36
37 struct sigthread
38 {
39   DWORD id;
40   DWORD frame;
41   CRITICAL_SECTION lock;
42   LONG winapi_lock;
43   BOOL exception;
44   bool get_winapi_lock (int test = 0);
45   void release_winapi_lock ();
46   void init (const char *s);
47 };
48
49 class sigframe
50 {
51 private:
52   sigthread *st;
53   inline bool unregister ()
54   {
55     if (!st)
56       return 0;
57     EnterCriticalSection (&st->lock);
58     st->frame = 0;
59     st->exception = 0;
60     st->release_winapi_lock ();
61     LeaveCriticalSection (&st->lock);
62     st = NULL;
63     return 1;
64   }
65
66 public:
67   inline void set (sigthread &t, DWORD ebp, bool is_exception = 0)
68   {
69     DWORD oframe = t.frame;
70     st = &t;
71     t.frame = ebp;
72     t.exception = is_exception;
73     if (!oframe)
74       t.get_winapi_lock ();
75   }
76   inline void init (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0))
77   {
78     if (!t.frame && t.id == GetCurrentThreadId ())
79       set (t, ebp);
80     else
81       st = NULL;
82   }
83
84   sigframe (): st (NULL) {}
85   sigframe (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0)) {init (t, ebp);}
86   ~sigframe ()
87   {
88     unregister ();
89   }
90
91   int call_signal_handler ();
92 };
93
94 extern sigthread mainthread;
95 extern HANDLE signal_arrived;
96
97 BOOL __stdcall my_parent_is_alive ();
98 extern "C" int __stdcall sig_dispatch_pending (int force = FALSE);
99 extern "C" void __stdcall set_process_mask (sigset_t newmask);
100 extern "C" void __stdcall reset_signal_arrived ();
101 int __stdcall sig_handle (int, bool);
102 void __stdcall sig_clear (int);
103 void __stdcall sig_set_pending (int);
104 int __stdcall handle_sigsuspend (sigset_t);
105
106 int __stdcall proc_subproc (DWORD, DWORD);
107
108 class _pinfo;
109 void __stdcall proc_terminate ();
110 void __stdcall sigproc_init ();
111 void __stdcall subproc_init ();
112 void __stdcall sigproc_terminate ();
113 BOOL __stdcall proc_exists (_pinfo *) __attribute__ ((regparm(1)));
114 BOOL __stdcall pid_exists (pid_t) __attribute__ ((regparm(1)));
115 int __stdcall sig_send (_pinfo *, int, DWORD ebp = (DWORD) __builtin_frame_address (0),
116                         bool exception = 0)  __attribute__ ((regparm(3)));
117 void __stdcall signal_fixup_after_fork ();
118 void __stdcall signal_fixup_after_exec (bool);
119
120 extern char myself_nowait_dummy[];
121 extern char myself_nowait_nonmain_dummy[];
122
123 #define WAIT_SIG_EXITING (WAIT_OBJECT_0 + 1)
124
125 #define myself_nowait ((_pinfo *)myself_nowait_dummy)
126 #define myself_nowait_nonmain ((_pinfo *)myself_nowait_nonmain_dummy)