1 /* pinfo.h: process table info
3 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
14 #include <sys/resource.h>
26 PICOM_EXTRASTR = 0x80000000,
32 PICOM_PIPE_FHANDLER = 6
35 #define EXITCODE_SET 0x8000000
36 #define EXITCODE_NOSET 0x4000000
37 #define EXITCODE_RETRY 0x2000000
38 #define EXITCODE_OK 0x1000000
48 /* Various flags indicating the state of the process. See PID_
49 constants in <sys/cygwin.h>. */
52 DWORD exitcode; /* set when process exits */
54 #define PINFO_REDIR_SIZE ((char *) &myself.procinfo->exitcode - (char *) myself.procinfo)
56 /* > 0 if started by a cygwin process */
59 /* Parent process id. */
62 /* dwProcessId contains the processid used for sending signals. It
63 will be reset in a child process when it is capable of receiving
67 /* Used to spawn a child for fork(), among other things. */
68 WCHAR progname[NT_MAX_PATH];
71 The information is derived from the GetUserName system call,
72 with the name looked up in /etc/passwd and assigned a default value
73 if not found. This data resides in the shared data area (allowing
74 tasks to store whatever they want here) so it's for informational
76 __uid32_t uid; /* User ID */
77 __gid32_t gid; /* Group ID */
78 pid_t pgid; /* Process group ID */
79 pid_t sid; /* Session ID */
80 int ctty; /* Control tty */
81 bool has_pgid_children;/* True if we've forked or spawned children with our GID. */
83 /* Resources used by process. */
85 struct rusage rusage_self;
86 struct rusage rusage_children;
89 /* Non-zero if process was stopped by a signal. */
92 inline void set_has_pgid_children ()
95 has_pgid_children = 1;
98 inline void set_has_pgid_children (bool val) {has_pgid_children = val;}
100 commune_result commune_request (__uint32_t, ...);
102 fhandler_pipe *pipe_fhandler (HANDLE, size_t &);
103 char *fd (int fd, size_t &);
104 char *fds (size_t &);
105 char *root (size_t &);
106 char *cwd (size_t &);
107 char *cmdline (size_t &);
108 void set_ctty (class tty_min *, int, class fhandler_tty_slave *);
109 HANDLE dup_proc_pipe (HANDLE) __attribute__ ((regparm(2)));
110 void sync_proc_pipe ();
111 bool alert_parent (char);
112 int __stdcall kill (siginfo_t&) __attribute__ ((regparm (2)));
113 bool __stdcall exists () __attribute__ ((regparm (1)));
114 const char *_ctty (char *);
119 DWORD exec_dwProcessId;
122 DWORD wr_proc_pipe_owner;
126 DWORD WINAPI commune_process (void *);
130 __ALERT_REPARENT = 111, // arbitrary non-signal value
143 class cygthread *wait_thread;
144 void init (pid_t, DWORD, HANDLE) __attribute__ ((regparm(3)));
146 pinfo (_pinfo *x): procinfo (x), hProcess (NULL) {}
147 pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, 0, NULL);}
148 pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), waiter_ready (0), wait_thread (NULL) {init (n, flag, NULL);}
149 void thisproc (HANDLE) __attribute__ ((regparm (2)));
151 int wait () __attribute__ ((regparm (1)));
154 if (destroy && procinfo)
157 void exit (DWORD n) __attribute__ ((noreturn, regparm(2)));
158 void maybe_set_exit_code_from_windows () __attribute__ ((regparm(1)));
159 void set_exit_code (DWORD n) __attribute__ ((regparm(2)));
160 _pinfo *operator -> () const {return procinfo;}
161 int operator == (pinfo *x) const {return x->procinfo == procinfo;}
162 int operator == (pinfo &x) const {return x.procinfo == procinfo;}
163 int operator == (_pinfo *x) const {return x == procinfo;}
164 int operator == (void *x) const {return procinfo == x;}
165 int operator == (int x) const {return (int) procinfo == (int) x;}
166 int operator == (char *x) const {return (char *) procinfo == x;}
167 _pinfo *operator * () const {return procinfo;}
168 operator _pinfo * () const {return procinfo;}
169 void preserve () { destroy = false; }
171 int remember () {system_printf ("remember is not here"); return 0;}
173 int remember (bool detach)
175 int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADDCHILD,
177 destroy = res ? false : true;
181 HANDLE shared_handle () {return h;}
184 friend class winpids;
187 #define ISSTATE(p, f) (!!((p)->process_state & f))
188 #define NOTSTATE(p, f) (!((p)->process_state & f))
196 DWORD pinfo_access; // access type for pinfo open
197 DWORD enum_processes (bool winpid);
198 DWORD enum_init (bool winpid);
199 void add (DWORD& nelem, bool, DWORD pid);
202 inline void reset () { release (); npids = 0;}
203 void set (bool winpid);
204 winpids (): make_copy (true) {}
205 winpids (int): make_copy (false), npidlist (0), pidlist (NULL),
206 pinfolist (NULL), pinfo_access (0), npids (0) {}
207 winpids (DWORD acc): make_copy (false), npidlist (0), pidlist (NULL),
208 pinfolist (NULL), pinfo_access (acc), npids (0)
212 inline DWORD& winpid (int i) const {return pidlist[i];}
213 inline _pinfo *operator [] (int i) const {return (_pinfo *) pinfolist[i];}
218 extern __inline pid_t
219 cygwin_pid (pid_t pid)
224 void __stdcall pinfo_init (char **, int);
228 #define _P_SYSTEM 512
229 /* Add this flag in calls to spawn_guts if the calling function is one of
230 'p' type functions: execlp, execvp, spawnlp, spawnvp. Per POSIX, only
231 these p-type functions fall back to call /bin/sh if the file is not a
232 binary. The setting of _P_PATH_TYPE_EXEC is used as a bool value in
233 av::fixup to decide if the file should be evaluated as a script, or if
234 ENOEXEC should be returned. */
235 #define _P_PATH_TYPE_EXEC 0x1000
237 /* Helper macro to mask actual mode and drop additional flags defined above. */
238 #define _P_MODE(x) ((x) & 0xfff)
240 #define __ctty() _ctty ((char *) alloca (sizeof ("ctty /dev/tty") + 20))
241 #define myctty() myself->__ctty ()
243 /* For mmaps across fork(). */
244 int __stdcall fixup_mmaps_after_fork (HANDLE parent);
245 /* for shm areas across fork (). */
246 int __stdcall fixup_shms_after_fork ();
248 void __stdcall fill_rusage (struct rusage *, HANDLE);
249 void __stdcall add_rusage (struct rusage *, struct rusage *);