OSDN Git Service

* sigproc.h (sigframe::unregister): Return true/false whether this frame is
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / sigproc.h
1 /* sigproc.h
2
3    Copyright 1997, 1998, 2000, 2001 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   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   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
77   sigframe (): st (NULL) {}
78   sigframe (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0))
79   {
80     if (!t.frame && t.id == GetCurrentThreadId ())
81       set (t, ebp);
82     else
83       st = NULL;
84   }
85   ~sigframe ()
86   {
87     unregister ();
88   }
89
90   int call_signal_handler ();
91 };
92
93 extern sigthread mainthread;
94 extern HANDLE signal_arrived;
95
96 BOOL __stdcall my_parent_is_alive ();
97 extern "C" int __stdcall sig_dispatch_pending (int force = FALSE);
98 extern "C" void __stdcall set_process_mask (sigset_t newmask);
99 extern "C" void __stdcall reset_signal_arrived ();
100 int __stdcall sig_handle (int);
101 void __stdcall sig_clear (int);
102 void __stdcall sig_set_pending (int);
103 int __stdcall handle_sigsuspend (sigset_t);
104
105 int __stdcall proc_subproc (DWORD, DWORD);
106
107 class _pinfo;
108 void __stdcall proc_terminate ();
109 void __stdcall sigproc_init ();
110 void __stdcall subproc_init ();
111 void __stdcall sigproc_terminate ();
112 BOOL __stdcall proc_exists (_pinfo *) __attribute__ ((regparm(1)));
113 BOOL __stdcall pid_exists (pid_t) __attribute__ ((regparm(1)));
114 int __stdcall sig_send (_pinfo *, int, DWORD ebp = (DWORD) __builtin_frame_address (0),
115                         bool exception = 0)  __attribute__ ((regparm(3)));
116 void __stdcall signal_fixup_after_fork ();
117 void __stdcall signal_fixup_after_exec (bool);
118
119 extern char myself_nowait_dummy[];
120 extern char myself_nowait_nonmain_dummy[];
121
122 #define WAIT_SIG_EXITING (WAIT_OBJECT_0 + 1)
123
124 #define myself_nowait ((_pinfo *)myself_nowait_dummy)
125 #define myself_nowait_nonmain ((_pinfo *)myself_nowait_nonmain_dummy)