OSDN Git Service

gas/opcodes: blackfin: move dsp mac func defines to common header
[pf3gnuchains/sourceware.git] / winsup / cygwin / pinfo.h
1 /* pinfo.h: process table info
2
3    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4    2011 Red Hat, Inc.
5
6 This file is part of Cygwin.
7
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
10 details. */
11
12 #ifndef _PINFO_H
13 #define _PINFO_H
14 #include <sys/resource.h>
15 #include "thread.h"
16
17 struct commune_result
18 {
19   char *s;
20   int n;
21   HANDLE handles[2];
22 };
23
24 enum picom
25 {
26   PICOM_EXTRASTR = 0x80000000,
27   PICOM_CMDLINE = 1,
28   PICOM_CWD = 2,
29   PICOM_ROOT = 3,
30   PICOM_FDS = 4,
31   PICOM_FD = 5,
32   PICOM_PIPE_FHANDLER = 6
33 };
34
35 #define EXITCODE_SET    0x8000000
36 #define EXITCODE_NOSET  0x4000000
37 #define EXITCODE_RETRY  0x2000000
38 #define EXITCODE_OK     0x1000000
39
40 class fhandler_pipe;
41
42 class _pinfo
43 {
44 public:
45   /* Cygwin pid */
46   pid_t pid;
47
48   /* Various flags indicating the state of the process.  See PID_
49      constants in <sys/cygwin.h>. */
50   DWORD process_state;
51
52   DWORD exitcode;       /* set when process exits */
53
54 #define PINFO_REDIR_SIZE ((char *) &myself.procinfo->exitcode - (char *) myself.procinfo)
55
56   /* > 0 if started by a cygwin process */
57   DWORD cygstarted;
58
59   /* Parent process id.  */
60   pid_t ppid;
61
62   /* dwProcessId contains the processid used for sending signals.  It
63     will be reset in a child process when it is capable of receiving
64     signals.  */
65   DWORD dwProcessId;
66
67   /* Used to spawn a child for fork(), among other things. */
68   WCHAR progname[NT_MAX_PATH];
69
70   /* User information.
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
75      purposes only. */
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. */
82
83   /* Resources used by process. */
84   long start_time;
85   struct rusage rusage_self;
86   struct rusage rusage_children;
87   int nice;
88
89   /* Non-zero if process was stopped by a signal. */
90   char stopsig;
91
92   inline void set_has_pgid_children ()
93   {
94     if (pgid == pid)
95       has_pgid_children = 1;
96   }
97
98   inline void set_has_pgid_children (bool val) {has_pgid_children = val;}
99
100   commune_result commune_request (__uint32_t, ...);
101   bool alive ();
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 *);
115
116   /* signals */
117   HANDLE sendsig;
118   HANDLE exec_sendsig;
119   DWORD exec_dwProcessId;
120 public:
121   HANDLE wr_proc_pipe;
122   DWORD wr_proc_pipe_owner;
123   friend class pinfo;
124 };
125
126 DWORD WINAPI commune_process (void *);
127
128 enum parent_alerter
129 {
130   __ALERT_REPARENT = 111,               // arbitrary non-signal value
131   __ALERT_ALIVE   =  112
132 };
133
134 class pinfo
135 {
136   HANDLE h;
137   _pinfo *procinfo;
138   bool destroy;
139 public:
140   HANDLE rd_proc_pipe;
141   HANDLE hProcess;
142   bool waiter_ready;
143   class cygthread *wait_thread;
144   void init (pid_t, DWORD, HANDLE) __attribute__ ((regparm(3)));
145   pinfo () {}
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)));
150   void release ();
151   int wait () __attribute__ ((regparm (1)));
152   ~pinfo ()
153   {
154     if (destroy && procinfo)
155       release ();
156   }
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; }
170 #ifndef _SIGPROC_H
171   int remember () {system_printf ("remember is not here"); return 0;}
172 #else
173   int remember (bool detach)
174   {
175     int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADDCHILD,
176                             (DWORD) this);
177     destroy = res ? false : true;
178     return res;
179   }
180 #endif
181   HANDLE shared_handle () {return h;}
182   void set_acl ();
183   friend class _pinfo;
184   friend class winpids;
185 };
186
187 #define ISSTATE(p, f)   (!!((p)->process_state & f))
188 #define NOTSTATE(p, f)  (!((p)->process_state & f))
189
190 class winpids
191 {
192   bool make_copy;
193   DWORD npidlist;
194   DWORD *pidlist;
195   pinfo *pinfolist;
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);
200 public:
201   DWORD npids;
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)
209   {
210     set (0);
211   }
212   inline DWORD& winpid (int i) const {return pidlist[i];}
213   inline _pinfo *operator [] (int i) const {return (_pinfo *) pinfolist[i];}
214   ~winpids ();
215   void release ();
216 };
217
218 extern __inline pid_t
219 cygwin_pid (pid_t pid)
220 {
221   return pid;
222 }
223
224 void __stdcall pinfo_init (char **, int);
225 extern pinfo myself;
226
227 #define _P_VFORK 0
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
236
237 /* Helper macro to mask actual mode and drop additional flags defined above. */
238 #define _P_MODE(x)              ((x) & 0xfff)
239
240 #define __ctty() _ctty ((char *) alloca (sizeof ("ctty /dev/tty") + 20))
241 #define myctty() myself->__ctty ()
242
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 ();
247
248 void __stdcall fill_rusage (struct rusage *, HANDLE);
249 void __stdcall add_rusage (struct rusage *, struct rusage *);
250 #endif /*_PINFO_H*/