aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/sigproc.h
blob: dc67b6b08f82e85a186fc12da89221252482be87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* sigproc.h

   Copyright 1997, 1998, 2000, 2001 Red Hat, Inc.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#include <signal.h>

#define EXIT_SIGNAL	 0x010000
#define EXIT_REPARENTING 0x020000
#define EXIT_NOCLOSEALL  0x040000

enum procstuff
{
  PROC_ADDCHILD		= 1,	// add a new subprocess to list
  PROC_CHILDTERMINATED	= 2,	// a child died
  PROC_CLEARWAIT	= 3,	// clear all waits - signal arrived
  PROC_WAIT		= 4,	// setup for wait() for subproc
  PROC_NOTHING		= 5	// nothing, really
};

typedef struct struct_waitq
{
  int pid;
  int options;
  int status;
  HANDLE ev;
  void *rusage;			/* pointer to potential rusage */
  struct struct_waitq *next;
  HANDLE thread_ev;
} waitq;

struct sigthread
{
  DWORD id;
  DWORD frame;
  CRITICAL_SECTION lock;
  LONG winapi_lock;
  BOOL exception;
  bool get_winapi_lock (int test = 0);
  void release_winapi_lock ();
  void init (const char *s);
};

class sigframe
{
private:
  sigthread *st;
  inline bool unregister ()
  {
    if (!st)
      return 0;
    EnterCriticalSection (&st->lock);
    st->frame = 0;
    st->exception = 0;
    st->release_winapi_lock ();
    LeaveCriticalSection (&st->lock);
    st = NULL;
    return 1;
  }

public:
  inline void set (sigthread &t, DWORD ebp, bool is_exception = 0)
  {
    DWORD oframe = t.frame;
    st = &t;
    t.frame = ebp;
    t.exception = is_exception;
    if (!oframe)
      t.get_winapi_lock ();
  }
  inline void init (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0))
  {
    if (!t.frame && t.id == GetCurrentThreadId ())
      set (t, ebp);
    else
      st = NULL;
  }

  sigframe (): st (NULL) {}
  sigframe (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0)) {init (t, ebp);}
  ~sigframe ()
  {
    unregister ();
  }

  int call_signal_handler ();
};

extern sigthread mainthread;
extern HANDLE signal_arrived;

BOOL __stdcall my_parent_is_alive ();
extern "C" int __stdcall sig_dispatch_pending (int force = FALSE);
extern "C" void __stdcall set_process_mask (sigset_t newmask);
extern "C" void __stdcall reset_signal_arrived ();
int __stdcall sig_handle (int);
void __stdcall sig_clear (int);
void __stdcall sig_set_pending (int);
int __stdcall handle_sigsuspend (sigset_t);

int __stdcall proc_subproc (DWORD, DWORD);

class _pinfo;
void __stdcall proc_terminate ();
void __stdcall sigproc_init ();
void __stdcall subproc_init ();
void __stdcall sigproc_terminate ();
BOOL __stdcall proc_exists (_pinfo *) __attribute__ ((regparm(1)));
BOOL __stdcall pid_exists (pid_t) __attribute__ ((regparm(1)));
int __stdcall sig_send (_pinfo *, int, DWORD ebp = (DWORD) __builtin_frame_address (0),
			bool exception = 0)  __attribute__ ((regparm(3)));
void __stdcall signal_fixup_after_fork ();
void __stdcall signal_fixup_after_exec (bool);

extern char myself_nowait_dummy[];
extern char myself_nowait_nonmain_dummy[];

#define WAIT_SIG_EXITING (WAIT_OBJECT_0 + 1)

#define myself_nowait ((_pinfo *)myself_nowait_dummy)
#define myself_nowait_nonmain ((_pinfo *)myself_nowait_nonmain_dummy)