Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / local_includes / child_info.h
blob2da62ffaa340b24ddbdfeb702a8c0754feabbb30
1 /* child_info.h: shared child info for cygwin
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 #include <setjmp.h>
11 enum child_info_types
13 _CH_NADA = 0,
14 _CH_EXEC = 1,
15 _CH_SPAWN = 2,
16 _CH_FORK = 3,
17 _CH_WHOOPS = 4
20 enum child_status
22 _CI_STRACED = 0x01,
23 _CI_ISCYGWIN = 0x02,
24 _CI_SAW_CTRL_C = 0x04,
25 _CI_SILENTFAIL = 0x08
28 #define OPROC_MAGIC_MASK 0xff00ff00
29 #define OPROC_MAGIC_GENERIC 0xaf00f000
31 #define PROC_MAGIC_GENERIC 0xaf00fa64
33 #define EXEC_MAGIC_SIZE sizeof(child_info)
35 /* Change this value if you get a message indicating that it is out-of-sync. */
36 #define CURR_CHILD_INFO_MAGIC 0xacbf4682U
38 #include "pinfo.h"
39 struct cchildren
41 pid_t pid;
42 pinfo_minimal p;
45 /* NOTE: Do not make gratuitous changes to the names or organization of the
46 below class. The layout is checksummed to determine compatibility between
47 different cygwin versions. */
48 class child_info
50 public:
51 DWORD msv_count; // set to 0
52 DWORD cb; // size of this record
53 DWORD intro; // improbable string
54 DWORD magic; // magic number unique to child_info
55 unsigned short type; // type of record, exec, spawn, fork
56 init_cygheap *cygheap;
57 void *cygheap_max;
58 unsigned char flag;
59 int retry; // number of times we've tried to start child process
60 HANDLE rd_proc_pipe;
61 HANDLE wr_proc_pipe;
62 HANDLE subproc_ready; // used for synchronization with parent
63 HANDLE user_h;
64 HANDLE parent;
65 DWORD parent_winpid;
66 DWORD cygheap_reserve_sz;
67 unsigned fhandler_union_cb;
68 DWORD exit_code; // process exit code
69 static int retry_count;// retry count;
70 sigset_t sigmask;
72 child_info (unsigned, child_info_types, bool);
73 child_info (): subproc_ready (NULL), parent (NULL) {}
74 ~child_info ();
75 void refresh_cygheap () { cygheap_max = ::cygheap_max; }
76 void ready (bool);
77 bool sync (int, HANDLE&, DWORD);
78 DWORD proc_retry (HANDLE);
79 bool isstraced () const {return !!(flag & _CI_STRACED);}
80 bool iscygwin () const {return !!(flag & _CI_ISCYGWIN);}
81 bool saw_ctrl_c () const {return !!(flag & _CI_SAW_CTRL_C);}
82 bool silentfail () const {return !!(flag & _CI_SILENTFAIL);}
83 void prefork (bool = false);
84 void cleanup ();
85 void postfork (pinfo& child)
87 ForceCloseHandle (wr_proc_pipe);
88 wr_proc_pipe = NULL;
89 child.set_rd_proc_pipe (rd_proc_pipe);
90 rd_proc_pipe = NULL;
92 void silentfail (bool f)
94 if (f)
95 flag |= _CI_SILENTFAIL;
96 else
97 flag &= ~_CI_SILENTFAIL;
101 class mount_info;
103 class child_info_fork: public child_info
105 public:
106 HANDLE forker_finished;// for synchronization with child
107 jmp_buf jmp; // where child will jump to
108 void *stackaddr; // DeallocationStack or user-provided allocation address
109 // of parent thread
110 void *stacklimit; // StackLimit of parent thread
111 void *stackbase; // StackBase of parent thread
112 size_t guardsize; // size of POSIX guard region or (size_t) -1 if
113 // user stack
114 char filler[4];
115 child_info_fork ();
116 void handle_fork ();
117 bool abort (const char *fmt = NULL, ...);
118 void alloc_stack ();
121 class fhandler_base;
123 class cygheap_exec_info
125 public:
126 int argc;
127 char **argv;
128 int envc;
129 char **envp;
130 HANDLE myself_pinfo;
131 int nchildren;
132 cchildren children[0];
133 static cygheap_exec_info *alloc ();
134 void record_children ();
135 void reattach_children (HANDLE);
138 class child_info_spawn: public child_info
140 HANDLE hExeced;
141 HANDLE ev;
142 HANDLE sem;
143 pid_t cygpid;
144 public:
145 cygheap_exec_info *moreinfo;
146 int __stdin;
147 int __stdout;
148 char filler[4];
150 void cleanup ();
151 child_info_spawn () {};
152 child_info_spawn (child_info_types, bool);
153 void record_children ();
154 void reattach_children ();
155 void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
156 void set (child_info_types ci, bool b) { new (this) child_info_spawn (ci, b);}
157 void handle_spawn ();
158 void set_sem (HANDLE _sem)
160 /* Don't leak semaphore handle into exec'ed process. */
161 SetHandleInformation (sem = _sem, HANDLE_FLAG_INHERIT, 0);
163 bool set_saw_ctrl_c ()
165 if (!has_execed ())
166 return false;
167 flag |= _CI_SAW_CTRL_C;
168 return true;
170 bool signal_myself_exited ()
172 if (!ev)
173 return false;
174 else
176 SetEvent (ev);
177 return true;
180 void wait_for_myself ();
181 bool has_execed () const
183 if (hExeced)
184 return true;
185 if (type != _CH_EXEC)
186 return false;
187 return !!hExeced;
189 bool get_parent_handle ();
190 bool has_execed_cygwin () const { return iscygwin () && has_execed (); }
191 operator HANDLE& () {return hExeced;}
192 int worker (const char *, const char *const *, const char *const [],
193 int, int = -1, int = -1);
196 extern child_info_spawn ch_spawn;
198 #define have_execed ch_spawn.has_execed ()
199 #define have_execed_cygwin ch_spawn.has_execed_cygwin ()
201 extern "C" {
202 extern child_info *child_proc_info;
203 extern child_info_spawn *spawn_info asm (_SYMSTR (child_proc_info));
204 extern child_info_fork *fork_info asm (_SYMSTR (child_proc_info));