5d97040501
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset. (child_info::dwProcessId): Delete. (child_info::straced): New variable. (child_info::handle_fork): New member function. * dcrt0.cc (in_forkee): New global variable. (__cygwin_user_data::forkee): Mark as obsolete. (do_global_ctors): Use in_forkee rather than user_data->forkee. (get_cygwin_startup_info): Ditto. Deal with new straced field to allow strace to deal with children of attached processes. (initial_env): Accommodate changes to strace::hello. (child_info_fork::handle_fork): Rename from plain old 'handle_fork'. Move alloc_stack() call elsewhere. (dll_crt0_0): Fill out more of user_data. Reference handle_fork via fork_info. Add some debugging output. (_dll_crt0): Don't wait for sync thread if sync_startup is invalid. Zero sync_startup here. Call alloc_stack() here, if appropriate. (dll_crt0_1): Use in_forkee rather than user_data->forkee. (dll_crt0): Ditto. * malloc_wrapper.cc (malloc_init): Ditto. * dll_init.cc (in_forkee): Remove local static version of this variable. (dll_list::load_after_fork): Don't set in_forkee here. * external.cc (cygwin_internal): Use strace method rather than accessing field directly. * fhandler.cc (fhandler_base::read): Ditto. * fhandler_tty.cc (fhandler_tty_common::__acquire_output_mutex): Ditto. * fork.cc (frok::parent): Invoke strace write_childpid to communicate with potential strace. (child_copy): Add more detail to debugging output. * init.cc (calibration_id): New static variable. (prime_threads): Set sync_startup to invalid handle if we already know about thread_func_ix. Use static calibration_id to hold calibration thread id. * munge_threadfunc (munge_threadfunc): Don't try to debug if we don't find threadfunc_ix. (dll_entry): Avoid calling munge_threadfunc and _cygtls::remove on non-cygwin threads invoked during process startup. * pinfo.cc (set_myself): Always call strace.hello here regardless of DEBUGGING. * sigproc.cc (child_info::child_info): Remove spurious handling of dwProcessId. Set straced as appropriate. * spawn.cc (spawn_guts): Rename ciresrv to ch. Invoke strace write_childpid to communicate with potential strace. * strace.cc: Include child_info.h. (strace::hello): Remove inited test. Use active() method to test if strace has been activated. Handle case where we are started before (mypid): New function. (strace::vsprntf): Try to deal more intelligently with case where progname may not be filled out. Put pid in parentheses if it is a windows pid rather than a cygwin pid. myself has been filled out. (strace::write_childpid): New function for notifying strace about the creation of children. (strace::vprntf): Use strace method rather than accessing field directly. (strace_printf): Ditto. (strace::wm): Ditto. * winsup.h (in_forkee): Declare. * include/sys/strace.h (strace::write_childpid): Declare new function. (strace::attached): Define new function. (strace::active): Ditto. (strace::active_val): Ditto. (_STRACE_ON): Delete. (_STRACE_OFF): Ditto. (define_strace0): Use strace method rather than accessing field directly. (strace_printf_wrap): Ditto. (strace_printf_wrap1): Ditto. *** cygwin utils changes: * strace.cc (nprocesses): Make static global. (quiet): New variable. (strace_active): Ditto. (add_child): Increment nprocesses here. Don't add a child if it is already added (windows bug?). Report on child if not quiet. (get_child): Just return NULL if child not found. (remove_child): Report on child if not quiet. (attach_process): Don't complain if given a windows process. Use windows pid in error. (handle_output_debug_string): Issue error if trying to manipulate a process that we don't know about. Handle _STRACE_CHILD_PID - attach to reported child when we get this. (proc_child): Move nprocesses to file scope. Report on exceptions. (longopts): Implement "--quiet". (opts): Implement "-q". (main): Manipulate quiet flag. * utils.sgml (strace): Add words describing '-q'.
122 lines
2.9 KiB
C++
122 lines
2.9 KiB
C++
/* child_info.h: shared child info for cygwin
|
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005 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 <setjmp.h>
|
|
|
|
enum child_info_types
|
|
{
|
|
_PROC_EXEC,
|
|
_PROC_SPAWN,
|
|
_PROC_FORK,
|
|
_PROC_WHOOPS
|
|
};
|
|
|
|
#define OPROC_MAGIC_MASK 0xff00ff00
|
|
#define OPROC_MAGIC_GENERIC 0xaf00f000
|
|
|
|
#define PROC_MAGIC_GENERIC 0xaf00fa00
|
|
|
|
#define PROC_EXEC (_PROC_EXEC)
|
|
#define PROC_SPAWN (_PROC_SPAWN)
|
|
#define PROC_FORK (_PROC_FORK)
|
|
|
|
#define EXEC_MAGIC_SIZE sizeof(child_info)
|
|
|
|
#define CURR_CHILD_INFO_MAGIC 0xc87757a7U
|
|
|
|
/* 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. */
|
|
class child_info
|
|
{
|
|
public:
|
|
DWORD zero[4]; // must be zeroed
|
|
DWORD cb; // size of this record
|
|
DWORD intro; // improbable string
|
|
unsigned long magic; // magic number unique to child_info
|
|
unsigned short type; // type of record, exec, spawn, fork
|
|
HANDLE subproc_ready; // used for synchronization with parent
|
|
HANDLE user_h;
|
|
HANDLE parent;
|
|
init_cygheap *cygheap;
|
|
void *cygheap_max;
|
|
DWORD cygheap_reserve_sz;
|
|
unsigned char straced;
|
|
unsigned fhandler_union_cb;
|
|
child_info (unsigned, child_info_types, bool);
|
|
child_info (): subproc_ready (NULL), parent (NULL) {}
|
|
~child_info ();
|
|
void ready (bool);
|
|
bool sync (int, HANDLE&, DWORD) __attribute__ ((regparm (3)));
|
|
};
|
|
|
|
class mount_info;
|
|
class _pinfo;
|
|
|
|
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
|
|
child_info_fork ();
|
|
void handle_fork ();
|
|
};
|
|
|
|
class fhandler_base;
|
|
|
|
class cygheap_exec_info
|
|
{
|
|
public:
|
|
char *old_title;
|
|
int argc;
|
|
char **argv;
|
|
int envc;
|
|
char **envp;
|
|
HANDLE myself_pinfo;
|
|
};
|
|
|
|
class child_info_spawn: public child_info
|
|
{
|
|
public:
|
|
cygheap_exec_info *moreinfo;
|
|
|
|
~child_info_spawn ()
|
|
{
|
|
if (moreinfo)
|
|
{
|
|
if (moreinfo->old_title)
|
|
cfree (moreinfo->old_title);
|
|
if (moreinfo->envp)
|
|
{
|
|
for (char **e = moreinfo->envp; *e; e++)
|
|
cfree (*e);
|
|
cfree (moreinfo->envp);
|
|
}
|
|
CloseHandle (moreinfo->myself_pinfo);
|
|
cfree (moreinfo);
|
|
}
|
|
}
|
|
child_info_spawn (): moreinfo (NULL) {};
|
|
child_info_spawn (child_info_types, bool);
|
|
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);}
|
|
};
|
|
|
|
void __stdcall init_child_info (DWORD, child_info *, HANDLE);
|
|
|
|
extern "C" {
|
|
extern child_info *child_proc_info;
|
|
extern child_info_spawn *spawn_info asm ("_child_proc_info");
|
|
extern child_info_fork *fork_info asm ("_child_proc_info");
|
|
}
|