2002-08-27 06:10:54 +02:00
|
|
|
/* child_info.h: shared child info for cygwin
|
2000-09-01 22:54:22 +02:00
|
|
|
|
2006-07-06 19:16:37 +02:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
|
2000-09-01 22:54:22 +02:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
2004-12-05 20:41:26 +01:00
|
|
|
enum child_info_types
|
2000-09-01 22:54:22 +02:00
|
|
|
{
|
2001-12-26 05:53:34 +01:00
|
|
|
_PROC_EXEC,
|
|
|
|
_PROC_SPAWN,
|
2002-08-27 06:10:54 +02:00
|
|
|
_PROC_FORK,
|
|
|
|
_PROC_WHOOPS
|
2000-09-01 22:54:22 +02:00
|
|
|
};
|
|
|
|
|
2006-03-20 19:01:17 +01:00
|
|
|
enum child_status
|
|
|
|
{
|
2006-05-22 06:50:54 +02:00
|
|
|
_CI_STRACED = 0x01,
|
|
|
|
_CI_ISCYGWIN = 0x02,
|
|
|
|
_CI_SAW_CTRL_C = 0x04
|
2006-03-20 19:01:17 +01:00
|
|
|
};
|
|
|
|
|
2001-12-26 05:53:34 +01:00
|
|
|
#define OPROC_MAGIC_MASK 0xff00ff00
|
|
|
|
#define OPROC_MAGIC_GENERIC 0xaf00f000
|
2000-09-01 22:54:22 +02:00
|
|
|
|
2001-12-26 05:53:34 +01:00
|
|
|
#define PROC_MAGIC_GENERIC 0xaf00fa00
|
|
|
|
|
|
|
|
#define PROC_EXEC (_PROC_EXEC)
|
|
|
|
#define PROC_SPAWN (_PROC_SPAWN)
|
|
|
|
#define PROC_FORK (_PROC_FORK)
|
2001-10-10 04:32:12 +02:00
|
|
|
|
2000-09-01 22:54:22 +02:00
|
|
|
#define EXEC_MAGIC_SIZE sizeof(child_info)
|
2001-12-26 05:53:34 +01:00
|
|
|
|
2006-03-20 19:01:17 +01:00
|
|
|
/* Change this value if you get a message indicating that it is out-of-sync. */
|
2006-12-11 19:55:29 +01:00
|
|
|
#define CURR_CHILD_INFO_MAGIC 0x3ebda16aU
|
2001-12-26 05:53:34 +01:00
|
|
|
|
2001-12-26 07:18:41 +01:00
|
|
|
/* NOTE: Do not make gratuitous changes to the names or organization of the
|
|
|
|
below class. The layout is checksummed to determine compatibility between
|
|
|
|
different cygwin versions. */
|
2000-09-01 22:54:22 +02:00
|
|
|
class child_info
|
|
|
|
{
|
|
|
|
public:
|
2006-12-11 19:55:29 +01:00
|
|
|
DWORD msv_count; // zeroed on < W2K3, set to pseudo-count on Vista
|
2000-09-01 22:54:22 +02:00
|
|
|
DWORD cb; // size of this record
|
2001-12-26 05:53:34 +01:00
|
|
|
DWORD intro; // improbable string
|
2002-08-27 06:10:54 +02:00
|
|
|
unsigned long magic; // magic number unique to child_info
|
2001-12-26 05:53:34 +01:00
|
|
|
unsigned short type; // type of record, exec, spawn, fork
|
2000-09-01 22:54:22 +02:00
|
|
|
HANDLE subproc_ready; // used for synchronization with parent
|
2003-09-25 04:29:05 +02:00
|
|
|
HANDLE user_h;
|
2000-10-13 00:15:47 +02:00
|
|
|
HANDLE parent;
|
2000-11-14 06:53:32 +01:00
|
|
|
init_cygheap *cygheap;
|
2000-10-13 00:15:47 +02:00
|
|
|
void *cygheap_max;
|
2004-04-04 06:14:11 +02:00
|
|
|
DWORD cygheap_reserve_sz;
|
2006-03-20 19:01:17 +01:00
|
|
|
unsigned char flag;
|
2001-12-26 22:35:16 +01:00
|
|
|
unsigned fhandler_union_cb;
|
2006-03-18 20:17:21 +01:00
|
|
|
int retry; // number of times we've tried to start child process
|
|
|
|
DWORD exit_code; // process exit code
|
|
|
|
static int retry_count;// retry count;
|
2005-07-17 02:51:03 +02:00
|
|
|
child_info (unsigned, child_info_types, bool);
|
2005-08-11 18:13:30 +02:00
|
|
|
child_info (): subproc_ready (NULL), parent (NULL) {}
|
2004-12-05 20:41:26 +01:00
|
|
|
~child_info ();
|
|
|
|
void ready (bool);
|
2005-10-18 01:27:00 +02:00
|
|
|
bool sync (int, HANDLE&, DWORD) __attribute__ ((regparm (3)));
|
2006-03-20 19:01:17 +01:00
|
|
|
DWORD proc_retry (HANDLE) __attribute__ ((regparm (2)));
|
2006-03-22 04:20:28 +01:00
|
|
|
bool isstraced () const {return !!(flag & _CI_STRACED);}
|
|
|
|
bool iscygwin () const {return !!(flag & _CI_ISCYGWIN);}
|
2006-05-28 17:50:14 +02:00
|
|
|
bool saw_ctrl_c () const {return !!(flag & _CI_SAW_CTRL_C);}
|
2006-05-22 06:50:54 +02:00
|
|
|
void set_saw_ctrl_c () {flag |= _CI_SAW_CTRL_C;}
|
2000-09-01 22:54:22 +02:00
|
|
|
};
|
|
|
|
|
2002-10-14 22:25:52 +02:00
|
|
|
class mount_info;
|
|
|
|
class _pinfo;
|
|
|
|
|
2000-09-01 22:54:22 +02:00
|
|
|
class child_info_fork: public child_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HANDLE forker_finished;// for synchronization with child
|
|
|
|
DWORD stacksize; // size of parent stack
|
|
|
|
jmp_buf jmp; // where child will jump to
|
|
|
|
void *stacktop; // location of top of parent stack
|
|
|
|
void *stackbottom; // location of bottom of parent stack
|
2006-12-11 19:55:29 +01:00
|
|
|
char filler[4];
|
2004-12-05 20:41:26 +01:00
|
|
|
child_info_fork ();
|
2006-03-20 19:01:17 +01:00
|
|
|
void handle_fork () __attribute__ ((regparm (1)));;
|
|
|
|
bool handle_failure (DWORD) __attribute__ ((regparm (2)));
|
2006-04-03 19:33:07 +02:00
|
|
|
void alloc_stack ();
|
|
|
|
void alloc_stack_hard_way (volatile char *);
|
2000-09-01 22:54:22 +02:00
|
|
|
};
|
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
class fhandler_base;
|
|
|
|
|
|
|
|
class cygheap_exec_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
char *old_title;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
2000-10-17 01:55:58 +02:00
|
|
|
int envc;
|
|
|
|
char **envp;
|
2000-09-03 06:16:35 +02:00
|
|
|
HANDLE myself_pinfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
class child_info_spawn: public child_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cygheap_exec_info *moreinfo;
|
2006-12-11 19:55:29 +01:00
|
|
|
int __stdin;
|
|
|
|
int __stdout;
|
|
|
|
char filler[4];
|
2000-09-03 06:16:35 +02:00
|
|
|
|
|
|
|
~child_info_spawn ()
|
|
|
|
{
|
|
|
|
if (moreinfo)
|
|
|
|
{
|
|
|
|
if (moreinfo->old_title)
|
|
|
|
cfree (moreinfo->old_title);
|
2000-10-17 01:55:58 +02:00
|
|
|
if (moreinfo->envp)
|
2000-09-03 06:16:35 +02:00
|
|
|
{
|
2000-10-17 01:55:58 +02:00
|
|
|
for (char **e = moreinfo->envp; *e; e++)
|
2000-09-03 06:16:35 +02:00
|
|
|
cfree (*e);
|
2000-10-17 01:55:58 +02:00
|
|
|
cfree (moreinfo->envp);
|
2000-09-03 06:16:35 +02:00
|
|
|
}
|
2008-03-05 19:31:09 +01:00
|
|
|
if (type != _PROC_SPAWN && moreinfo->myself_pinfo)
|
2006-08-27 18:46:27 +02:00
|
|
|
CloseHandle (moreinfo->myself_pinfo);
|
2000-09-03 06:16:35 +02:00
|
|
|
cfree (moreinfo);
|
|
|
|
}
|
|
|
|
}
|
2005-08-11 18:13:30 +02:00
|
|
|
child_info_spawn (): moreinfo (NULL) {};
|
2005-07-17 02:51:03 +02:00
|
|
|
child_info_spawn (child_info_types, bool);
|
2005-08-11 18:13:30 +02:00
|
|
|
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
|
|
|
|
void set (child_info_types ci, bool b) { new (this) child_info_spawn (ci, b);}
|
2006-03-20 19:01:17 +01:00
|
|
|
void handle_spawn () __attribute__ ((regparm (1)));
|
2000-09-03 06:16:35 +02:00
|
|
|
};
|
|
|
|
|
2004-09-12 05:47:57 +02:00
|
|
|
void __stdcall init_child_info (DWORD, child_info *, HANDLE);
|
2000-09-01 22:54:22 +02:00
|
|
|
|
2005-03-19 22:45:15 +01:00
|
|
|
extern "C" {
|
2002-06-15 23:59:32 +02:00
|
|
|
extern child_info *child_proc_info;
|
2005-03-19 22:45:15 +01:00
|
|
|
extern child_info_spawn *spawn_info asm ("_child_proc_info");
|
|
|
|
extern child_info_fork *fork_info asm ("_child_proc_info");
|
|
|
|
}
|