* dcrt0.cc (dll_crt0_0): Remove hexec_proc stuff. * fork.cc (fork_child): Remove call to pinfo_fixup_after_fork. * pinfo.cc (set_myself): Close and zero pid_handle if set. (pinfo_fixup_after_fork): Delete. (proc_waiter): Don't close vchild.hProcess here. Do that when we are remove the vchild from procs. Save hProcess as pid_handle only on first reparent operation. (pinfo::wait): Don't set pid_handle here. (pinfo::alert_parent): Always try to send signal. If unsuccessful then close and zero wr_proc_pipe. * pinfo.h (pinfo::pinfo): Make sure that appropriate parts of the class are zeroed on construction. (pinfo::alert_parent): Take char argument. (pinfo_fixup_after_fork): Delete declaration. (hexec_proc): Ditto. * sigproc.cc (remove_proc): Close pid_handle and hProcess if appropriate. * spawn.cc (spawn_guts): Set cygheap->pid_handle on first exec. * cygheap.h (init_cygheap::pid_handle): New element. * pinfo.cc (set_myself): Clear previously existing cygheap->pid_handle when a new process has been started. (pinfo::wait): Make sure that a handle to the newly forked/spawned process is kept around so that the pid will not be reused. * pinfo.h (_pinfo::pid_handle): Move. (pinfo::pid_handle): to here. * spawn.cc (spawn_guts): Create a pid_handle in cygheap prior to spawning to ensure that the pid does not get reused during the lifetime of the "cygwin pid". * pinfo.h (pinfo::alert_parent): New function. * exceptions.cc (sig_handle_tty_stop): Use alert_parent to send "signals" to parent. * fork.cc (fork_parent): Don't close pi.hProcess. Let the waiter thread do that. * pinfo.cc (proc_waiter): Detect case where process exits without setting the exit code and use value from GetExitCodeProcess. Reluctantly implement __SIGREPARENT. (pinfo::alert_parent): Define. * sigproc.h (__SIGREPARENT): New enum. * spawn.cc (spawn_guts): Send reparent signal to parent on exec. Always create process in suspended state to avoid races. Remove cygthread.h in favor of cygtls.h throughout since cygtls now includes cygthread.h. Eliminate ppid_handle usage throughout. * child_info.h: Regenerate magic number (child_info): Remove pppid_handle. * cygthread.h (cygthread::release): New method. Frees thread without waiting. * cygthread.cc (cygthread::stub): Set _ctinfo in _mytls to point to information for executing thread. Don't call SetEvent if thread is no longer in use. (cygthread::simplestub): Ditto. * cygtls.h (_cygtls::_ctinfo): New element contains pointer to information about executing cygthread, if any. * dcrt0.cc: Remove last vestiges of per_thread stuff. (dll_crt0_0): Ditto. Remove accommodation for ppid_handle. (do_exit): Remove obsolete reparenting test. (_exit): Exit with a more SUSv3-like exit value. * dtable.cc (dtable::stdio_init): Check for myself->cygstarted rather than myself->ppid_handle to see if we were started by a cygwin process. * exceptions.cc (open_stackdumpfile): Ditto. (handle_exceptions): Ditto. (ctrl_c_handler): Ditto. (sig_handle_tty_stop): Ditto. Let parent send signal to itself on STOP. (sigpacket::process): Comment out vfork test. (signal_exit): Use more SUSv3-like exit value on signal. * external.cc (fillout_pinfo): Don't set hProcess. * fork.cc: Remove VFORK cruft. (per_thread::set): Delete. (fork_child): Remove perthread stuff. (fork_parent): Remove obsolete subproc_init. Accommodate new method for tracking subprocesses. * pinfo.cc (set_myself): Accommodate new pinfo/_pinfo layout. Set some things here that used to be set in wait_sig. (_pinfo::exit): Set exitcode here. Close process pipe. (_pinfo::commune_send): Accommodeate new pinfo/_pinfo layout. (proc_waiter): New function. Waits, in a thread for subprocess to go away. (pinfo::wait): New function. Initialization for proc_waiter. * pinfo.h (_pinfo::exitcode): New element. (_pinfo::cygstarted): Ditto. (_pinfo::wr_proc_pipe): Ditto. (_pinfo::ppid_handle): Delete. (_pinfo::hProcess): Delete. (_pinfo::lock): Delete. (pinfo::hProcess): New element. (pinfo::lock): Ditto. (pinfo::wait): Declare new function. (pinfo::preserve): Define new function. * sigproc.cc: Remove old stuff from wait_subproc thread based method. (zombies): Remove. (procs): New. (my_parent_is_alive): Just check that the parent pid exists. (mychild): Just use pinfo methods to determine if child is mine. (proc_subproc): Revamp PROC_ADDCHILD to use pinfo::wait. Remove PROC_CHILDTERMINATED logic. Use different method to remove processes from list when SIGCHLD == SIG_IGN. (proc_terminate): Gut. (subproc_init): Delete. (init_child_info): Remove setting of pppid_handle. (checkstate): Revamp to only scan procs array. (remove_proc): Rename from remove_zombie. Don't close hProcess or pid_handle. Don't release memory if it's myself. (stopped_or_terminated): Change logic to handle new consolidated proc/zombie array. (wait_subproc): Delete. * sigproc.h: Remove obsolete EXIT_* defines. (subproc_init): Remove declaration. * spawn.cc (spawn_guts): Remove reparenting stuff. Use standard wait logic to wait for child if started from a non-cygwin process. * tlsoffsets.h: Regenerate. * tty.cc (tty_init): Check for myself->cygstarted rather than myself->ppid_handle to see if we were started by a cygwin process. * include/sys/signal.h (external_pinfo::exitcode): Replace hProcess. * include/sys/wait.h (WCOREDUMP): Define. * fhandler_tty.cc (fhandler_tty_slave::read): Add debugging output for timeout case. * signal.cc (abort): Flag that we are exiting with the ABORT signal.
266 lines
8.1 KiB
C++
266 lines
8.1 KiB
C++
/* sys/cygwin.h
|
|
|
|
Copyright 1997, 1998, 2000, 2001, 2002 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. */
|
|
|
|
#ifndef _SYS_CYGWIN_H
|
|
#define _SYS_CYGWIN_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern pid_t cygwin32_winpid_to_pid (int);
|
|
extern void cygwin32_win32_to_posix_path_list (const char *, char *);
|
|
extern int cygwin32_win32_to_posix_path_list_buf_size (const char *);
|
|
extern void cygwin32_posix_to_win32_path_list (const char *, char *);
|
|
extern int cygwin32_posix_to_win32_path_list_buf_size (const char *);
|
|
extern int cygwin32_conv_to_win32_path (const char *, char *);
|
|
extern int cygwin32_conv_to_full_win32_path (const char *, char *);
|
|
extern void cygwin32_conv_to_posix_path (const char *, char *);
|
|
extern void cygwin32_conv_to_full_posix_path (const char *, char *);
|
|
extern int cygwin32_posix_path_list_p (const char *);
|
|
extern void cygwin32_split_path (const char *, char *, char *);
|
|
|
|
extern pid_t cygwin_winpid_to_pid (int);
|
|
extern int cygwin_win32_to_posix_path_list (const char *, char *);
|
|
extern int cygwin_win32_to_posix_path_list_buf_size (const char *);
|
|
extern int cygwin_posix_to_win32_path_list (const char *, char *);
|
|
extern int cygwin_posix_to_win32_path_list_buf_size (const char *);
|
|
extern int cygwin_conv_to_win32_path (const char *, char *);
|
|
extern int cygwin_conv_to_full_win32_path (const char *, char *);
|
|
extern int cygwin_conv_to_posix_path (const char *, char *);
|
|
extern int cygwin_conv_to_full_posix_path (const char *, char *);
|
|
extern int cygwin_posix_path_list_p (const char *);
|
|
extern void cygwin_split_path (const char *, char *, char *);
|
|
|
|
struct __cygwin_perfile
|
|
{
|
|
const char *name;
|
|
unsigned flags;
|
|
};
|
|
|
|
/* External interface stuff */
|
|
|
|
typedef enum
|
|
{
|
|
CW_LOCK_PINFO,
|
|
CW_UNLOCK_PINFO,
|
|
CW_GETTHREADNAME,
|
|
CW_GETPINFO,
|
|
CW_SETPINFO,
|
|
CW_SETTHREADNAME,
|
|
CW_GETVERSIONINFO,
|
|
CW_READ_V1_MOUNT_TABLES,
|
|
CW_USER_DATA,
|
|
CW_PERFILE,
|
|
CW_GET_CYGDRIVE_PREFIXES,
|
|
CW_GETPINFO_FULL,
|
|
CW_INIT_EXCEPTIONS,
|
|
CW_GET_CYGDRIVE_INFO,
|
|
CW_SET_CYGWIN_REGISTRY_NAME,
|
|
CW_GET_CYGWIN_REGISTRY_NAME,
|
|
CW_STRACE_TOGGLE,
|
|
CW_STRACE_ACTIVE,
|
|
CW_CYGWIN_PID_TO_WINPID,
|
|
CW_EXTRACT_DOMAIN_AND_USER,
|
|
CW_CMDLINE,
|
|
CW_CHECK_NTSEC,
|
|
CW_GET_ERRNO_FROM_WINERROR,
|
|
CW_GET_POSIX_SECURITY_ATTRIBUTE,
|
|
CW_GET_SHMLBA,
|
|
CW_GET_UID_FROM_SID,
|
|
CW_GET_GID_FROM_SID,
|
|
CW_GET_BINMODE
|
|
} cygwin_getinfo_types;
|
|
|
|
#define CW_NEXTPID 0x80000000 /* or with pid to get next one */
|
|
unsigned long cygwin_internal (cygwin_getinfo_types, ...);
|
|
|
|
/* Flags associated with process_state */
|
|
enum
|
|
{
|
|
PID_IN_USE = 0x0001, /* Entry in use. */
|
|
PID_ZOMBIE = 0x0002, /* Child exited: no parent wait. */
|
|
PID_STOPPED = 0x0004, /* Waiting for SIGCONT. */
|
|
PID_TTYIN = 0x0008, /* Waiting for terminal input. */
|
|
PID_TTYOU = 0x0010, /* Waiting for terminal output. */
|
|
PID_ORPHANED = 0x0020, /* Member of an orphaned process group. */
|
|
PID_ACTIVE = 0x0040, /* Pid accepts signals. */
|
|
PID_CYGPARENT = 0x0080, /* Set if parent was a cygwin app. */
|
|
PID_MAP_RW = 0x0100, /* Flag to open map rw. */
|
|
PID_MYSELF = 0x0200, /* Flag that pid is me. */
|
|
PID_NOCLDSTOP = 0x0400, /* Set if no SIGCHLD signal on stop. */
|
|
PID_INITIALIZING = 0x0800, /* Set until ready to receive signals. */
|
|
PID_USETTY = 0x1000, /* Setting this enables or disables cygwin's */
|
|
/* tty support. This is inherited by */
|
|
/* all execed or forked processes. */
|
|
PID_ALLPIDS = 0x2000, /* child has execed */
|
|
PID_EXECED = 0x4000, /* redirect to original pid info block */
|
|
PID_NOREDIR = 0x8000, /* don't redirect if execed */
|
|
PID_EXITED = 0x80000000 /* Free entry. */
|
|
};
|
|
|
|
#ifdef WINVER
|
|
#ifdef _PATH_PASSWD
|
|
extern HANDLE cygwin_logon_user (const struct passwd *, const char *);
|
|
#endif
|
|
|
|
/* This lives in the app and is initialized before jumping into the DLL.
|
|
It should only contain stuff which the user's process needs to see, or
|
|
which is needed before the user pointer is initialized, or is needed to
|
|
carry inheritance information from parent to child. Note that it cannot
|
|
be used to carry inheritance information across exec!
|
|
|
|
Remember, this structure is linked into the application's executable.
|
|
Changes to this can invalidate existing executables, so we go to extra
|
|
lengths to avoid having to do it.
|
|
|
|
When adding/deleting members, remember to adjust {public,internal}_reserved.
|
|
The size of the class shouldn't change [unless you really are prepared to
|
|
invalidate all existing executables]. The program does a check (using
|
|
SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment.
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
class ResourceLocks;
|
|
class MTinterface;
|
|
#endif
|
|
|
|
struct per_process
|
|
{
|
|
char *initial_sp;
|
|
|
|
/* The offset of these 3 values can never change. */
|
|
/* magic_biscuit is the size of this class and should never change. */
|
|
unsigned long magic_biscuit;
|
|
unsigned long dll_major;
|
|
unsigned long dll_minor;
|
|
|
|
struct _reent **impure_ptr_ptr;
|
|
char ***envptr;
|
|
|
|
/* Used to point to the memory machine we should use. Usually these
|
|
point back into the dll, but they can be overridden by the user. */
|
|
void *(*malloc)(size_t);
|
|
void (*free)(void *);
|
|
void *(*realloc)(void *, size_t);
|
|
|
|
int *fmode_ptr;
|
|
|
|
int (*main)(int, char **, char **);
|
|
void (**ctors)(void);
|
|
void (**dtors)(void);
|
|
|
|
/* For fork */
|
|
void *data_start;
|
|
void *data_end;
|
|
void *bss_start;
|
|
void *bss_end;
|
|
|
|
void *(*calloc)(size_t, size_t);
|
|
/* For future expansion of values set by the app. */
|
|
void (*premain[4]) (int, char **, struct per_process *);
|
|
|
|
/* The rest are *internal* to cygwin.dll.
|
|
Those that are here because we want the child to inherit the value from
|
|
the parent (which happens when bss is copied) are marked as such. */
|
|
|
|
/* non-zero of ctors have been run. Inherited from parent. */
|
|
int run_ctors_p;
|
|
|
|
DWORD unused[7];
|
|
|
|
/* Non-zero means the task was forked. The value is the pid.
|
|
Inherited from parent. */
|
|
int forkee;
|
|
|
|
HMODULE hmodule;
|
|
|
|
DWORD api_major; /* API version that this program was */
|
|
DWORD api_minor; /* linked with */
|
|
/* For future expansion, so apps won't have to be relinked if we
|
|
add an item. */
|
|
DWORD unused2[5];
|
|
|
|
#if defined (__INSIDE_CYGWIN__) && defined (__cplusplus)
|
|
ResourceLocks *resourcelocks;
|
|
MTinterface *threadinterface;
|
|
#else
|
|
void *resourcelocks;
|
|
void *threadinterface;
|
|
#endif
|
|
struct _reent *impure_ptr;
|
|
};
|
|
#define per_process_overwrite ((unsigned) &(((struct per_process *) NULL)->resourcelocks))
|
|
|
|
extern void cygwin_premain0 (int argc, char **argv, struct per_process *);
|
|
extern void cygwin_premain1 (int argc, char **argv, struct per_process *);
|
|
extern void cygwin_premain2 (int argc, char **argv, struct per_process *);
|
|
extern void cygwin_premain3 (int argc, char **argv, struct per_process *);
|
|
|
|
extern void cygwin_set_impersonation_token (const HANDLE);
|
|
|
|
/* included if <windows.h> is included */
|
|
extern int cygwin32_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
|
|
extern int cygwin_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
|
|
|
|
#ifdef __CYGWIN__
|
|
#include <sys/resource.h>
|
|
|
|
#define TTY_CONSOLE 0x40000000
|
|
|
|
#define EXTERNAL_PINFO_VERSION_16_BIT 0
|
|
#define EXTERNAL_PINFO_VERSION_32_BIT 1
|
|
#define EXTERNAL_PINFO_VERSION EXTERNAL_PINFO_VERSION_32_BIT
|
|
|
|
#ifndef _SYS_TYPES_H
|
|
typedef unsigned short __uid16_t;
|
|
typedef unsigned short __gid16_t;
|
|
typedef unsigned long __uid32_t;
|
|
typedef unsigned long __gid32_t;
|
|
#endif
|
|
|
|
struct external_pinfo
|
|
{
|
|
pid_t pid;
|
|
pid_t ppid;
|
|
DWORD exitcode;
|
|
DWORD dwProcessId, dwSpawnedProcessId;
|
|
__uid16_t uid;
|
|
__gid16_t gid;
|
|
pid_t pgid;
|
|
pid_t sid;
|
|
int ctty;
|
|
mode_t umask;
|
|
|
|
long start_time;
|
|
struct rusage rusage_self;
|
|
struct rusage rusage_children;
|
|
|
|
char progname[MAX_PATH];
|
|
|
|
DWORD strace_mask;
|
|
DWORD version;
|
|
|
|
DWORD process_state;
|
|
|
|
/* Only available if version >= EXTERNAL_PINFO_VERSION_32_BIT */
|
|
__uid32_t uid32;
|
|
__gid32_t gid32;
|
|
};
|
|
#endif /*__CYGWIN__*/
|
|
#endif /*WINVER*/
|
|
|
|
#ifdef __cplusplus
|
|
};
|
|
#endif
|
|
#endif /* _SYS_CYGWIN_H */
|