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
24 _CI_SAW_CTRL_C
= 0x04,
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
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. */
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
;
59 int retry
; // number of times we've tried to start child process
62 HANDLE subproc_ready
; // used for synchronization with parent
66 DWORD cygheap_reserve_sz
;
67 unsigned fhandler_union_cb
;
68 DWORD exit_code
; // process exit code
69 static int retry_count
;// retry count;
72 child_info (unsigned, child_info_types
, bool);
73 child_info (): subproc_ready (NULL
), parent (NULL
) {}
75 void refresh_cygheap () { cygheap_max
= ::cygheap_max
; }
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);
85 void postfork (pinfo
& child
)
87 ForceCloseHandle (wr_proc_pipe
);
89 child
.set_rd_proc_pipe (rd_proc_pipe
);
92 void silentfail (bool f
)
95 flag
|= _CI_SILENTFAIL
;
97 flag
&= ~_CI_SILENTFAIL
;
103 class child_info_fork
: public child_info
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
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
117 bool abort (const char *fmt
= NULL
, ...);
123 class cygheap_exec_info
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
145 cygheap_exec_info
*moreinfo
;
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 ()
167 flag
|= _CI_SAW_CTRL_C
;
170 bool signal_myself_exited ()
180 void wait_for_myself ();
181 bool has_execed () const
185 if (type
!= _CH_EXEC
)
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 ()
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
));