1 /* pinfo.h: process table info
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
11 #include <sys/resource.h>
29 PICOM_EXTRASTR
= 0x80000000,
35 PICOM_PIPE_FHANDLER
= 6,
36 PICOM_FILE_PATHCONV
= 7,
41 #define EXITCODE_SET 0x8000000
42 #define EXITCODE_NOSET 0x4000000
43 #define EXITCODE_RETRY 0x2000000
44 #define EXITCODE_OK 0x1000000
45 #define EXITCODE_FORK_FAILED 0x0800000
55 /* Various flags indicating the state of the process. See PID_
56 constants in <sys/cygwin.h>. */
59 pid_t ppid
; /* Parent process id. */
61 DWORD exitcode
; /* set when process exits */
63 /* > 0 if started by a cygwin process */
66 /* dwProcessId contains the processid used for sending signals. It
67 will be reset in a child process when it is capable of receiving
71 /* Used to spawn a child for fork(), among other things. The other
72 members of _pinfo take only a bit over 200 bytes. So cut off a
73 couple of bytes from progname to allow the _pinfo structure not
74 to exceed 64K. Otherwise it blocks another 64K block of VM for
76 WCHAR progname
[NT_MAX_PATH
- 512];
79 The information is derived from the GetUserName system call,
80 with the name looked up in /etc/passwd and assigned a default value
81 if not found. This data resides in the shared data area (allowing
82 tasks to store whatever they want here) so it's for informational
84 uid_t uid
; /* User ID */
85 gid_t gid
; /* Group ID */
86 pid_t pgid
; /* Process group ID */
87 pid_t sid
; /* Session ID */
88 int ctty
; /* Control tty */
89 bool has_pgid_children
;/* True if we've forked or spawned children with our GID. */
91 /* Resources used by process. */
93 struct rusage rusage_self
;
94 struct rusage rusage_children
;
97 /* Non-zero if process was stopped by a signal. */
100 inline void set_has_pgid_children ()
103 has_pgid_children
= 1;
106 inline void set_has_pgid_children (bool val
) {has_pgid_children
= val
;}
108 commune_result
commune_request (__uint32_t
, ...);
110 fhandler_pipe
*pipe_fhandler (int64_t, size_t &);
111 void *file_pathconv (int, uint32_t, size_t &);
112 char *fd (int fd
, size_t &);
113 char *fds (size_t &);
114 char *root (size_t &);
115 char *cwd (size_t &);
116 char *cmdline (size_t &);
117 char *environ (size_t &);
118 char *win_heap_info (size_t &);
119 int siginfo (sigset_t
&, sigset_t
&, sigset_t
&);
120 bool set_ctty (class fhandler_termios
*, int);
121 bool alert_parent (char);
122 int kill (siginfo_t
&);
124 const char *_ctty (char *);
129 DWORD exec_dwProcessId
;
131 friend class pinfo_minimal
;
134 DWORD
commune_process (void *);
138 __ALERT_REPARENT
= 111, // arbitrary non-signal value
148 pinfo_minimal (): h (NULL
), hProcess (NULL
), rd_proc_pipe (NULL
) {}
149 void set_rd_proc_pipe (HANDLE
& h
) {rd_proc_pipe
= h
;}
150 void set_inheritance (bool);
154 class pinfo
: public pinfo_minimal
161 class cygthread
*wait_thread
;
163 void init (pid_t
, DWORD
, HANDLE
);
164 pinfo (_pinfo
*x
= NULL
)
165 : pinfo_minimal (), destroy (false), winpid_hdl (NULL
), procinfo (x
),
166 waiter_ready (false), wait_thread (NULL
) {}
167 pinfo (pid_t n
, DWORD flag
= 0)
168 : pinfo_minimal (), destroy (false), winpid_hdl (NULL
), procinfo (NULL
),
169 waiter_ready (false), wait_thread (NULL
)
171 init (n
, flag
, NULL
);
173 pinfo (HANDLE
, pinfo_minimal
&, pid_t
);
174 void thisproc (HANDLE
);
175 void create_winpid_symlink ();
176 inline void _pinfo_release ();
181 if (destroy
&& procinfo
)
184 void exit (DWORD n
) __attribute__ ((noreturn
, ));
185 void maybe_set_exit_code_from_windows ();
186 void set_exit_code (DWORD n
);
187 _pinfo
*operator -> () const {return procinfo
;}
188 int operator == (pinfo
*x
) const {return x
->procinfo
== procinfo
;}
189 int operator == (pinfo
&x
) const {return x
.procinfo
== procinfo
;}
190 int operator == (_pinfo
*x
) const {return x
== procinfo
;}
191 int operator == (void *x
) const {return procinfo
== x
;}
192 _pinfo
*operator * () const {return procinfo
;}
193 operator _pinfo
* () const {return procinfo
;}
194 int operator !() const {return !procinfo
;}
195 void preserve () { destroy
= false; }
196 void allow_remove () { destroy
= true; }
197 #ifndef SIG_BAD_MASK // kludge to ensure that sigproc.h included
198 // int attach () {system_printf ("attach is not here"); return 0;}
199 // int remember (bool) {system_printf ("remember is not here"); return 0;}
203 int res
= proc_subproc (PROC_ATTACH_CHILD
, (uintptr_t) this);
204 destroy
= res
? false : true;
209 int res
= proc_subproc (PROC_ADD_CHILD
, (uintptr_t) this);
210 destroy
= res
? false : true;
214 HANDLE
shared_handle () {return h
;}
215 HANDLE
shared_winpid_handle () {return winpid_hdl
;}
218 friend class winpids
;
220 DWORD
status_exit (DWORD
);
223 #define MAX_PID 65536
225 #define ISSTATE(p, f) (!!((p)->process_state & f))
226 #define NOTSTATE(p, f) (!((p)->process_state & f))
234 DWORD pinfo_access
; // access type for pinfo open
235 DWORD
enum_processes (bool winpid
);
236 DWORD
enum_init (bool winpid
);
237 void add (DWORD
& nelem
, bool, DWORD pid
);
240 inline void reset () { release (); npids
= 0;}
241 void set (bool winpid
);
242 winpids (): make_copy (true) {}
243 winpids (DWORD acc
): make_copy (false), npidlist (0), pidlist (NULL
),
244 pinfolist (NULL
), pinfo_access (acc
), npids (0)
248 inline DWORD
& winpid (int i
) const {return pidlist
[i
];}
249 inline _pinfo
*operator [] (int i
) const {return (_pinfo
*) pinfolist
[i
];}
254 pid_t
create_cygwin_pid ();
255 pid_t
cygwin_pid (DWORD
);
257 void pinfo_init (char **, int);
260 /* Helper class to allow convenient setting and unsetting a process_state
261 flag in myself. This is used in certain fhandler read/write methods
262 to set the PID_TTYIN/PID_TTYOU flags in myself->process_state. */
263 class push_process_state
268 push_process_state (int add_flag
)
271 myself
->process_state
|= flag
;
273 void pop () { myself
->process_state
&= ~(flag
); }
274 ~push_process_state () { pop (); }
278 #define _P_SYSTEM 512
279 /* Add this flag in calls to child_info_spawn::worker if the calling function
280 is one of 'p' type functions: execlp, execvp, spawnlp, spawnvp. Per POSIX,
281 only these p-type functions fall back to call /bin/sh if the file is not a
282 binary. The setting of _P_PATH_TYPE_EXEC is used as a bool value in
283 av::fixup to decide if the file should be evaluated as a script, or if
284 ENOEXEC should be returned. */
285 #define _P_PATH_TYPE_EXEC 0x1000
287 /* Helper macro to mask actual mode and drop additional flags defined above. */
288 #define _P_MODE(x) ((x) & 0xfff)
290 #define __ctty() _ctty ((char *) alloca (sizeof ("ctty /dev/tty") + 20))
291 #define myctty() myself->__ctty ()
293 /* For mmaps across fork(). */
294 int fixup_mmaps_after_fork (HANDLE parent
);
295 /* for shm areas across fork (). */
296 int fixup_shms_after_fork ();
298 void fill_rusage (struct rusage
*, HANDLE
);
299 void add_rusage (struct rusage
*, struct rusage
*);