Merge pull request #3199 from lambdageek/dev/proxy-setter
[mono.git] / mono / io-layer / process-private.h
1 /*
2  * process-private.h: Private definitions for process handles
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002-2006 Novell, Inc.
8  */
9
10 #ifndef _WAPI_PROCESS_PRIVATE_H_
11 #define _WAPI_PROCESS_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15
16 #include <mono/utils/mono-os-semaphore.h>
17
18 /* There doesn't seem to be a defined symbol for this */
19 #define _WAPI_PROCESS_CURRENT (gpointer)0xFFFFFFFF
20
21 /*
22  * Handles > _WAPI_PROCESS_UNHANDLED are pseudo handles which represent processes
23  * not started by the runtime.
24  */
25 /* This marks a system process that we don't have a handle on */
26 /* FIXME: Cope with PIDs > sizeof guint */
27 #define _WAPI_PROCESS_UNHANDLED (1 << (8*sizeof(pid_t)-1))
28 #define _WAPI_PROCESS_UNHANDLED_PID_MASK (-1 & ~_WAPI_PROCESS_UNHANDLED)
29 #define WAPI_IS_PSEUDO_PROCESS_HANDLE(handle) ((GPOINTER_TO_UINT(handle) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED)
30 #define WAPI_PID_TO_HANDLE(pid) GINT_TO_POINTER (_WAPI_PROCESS_UNHANDLED + (pid))
31 #define WAPI_HANDLE_TO_PID(handle) (GPOINTER_TO_UINT ((handle)) - _WAPI_PROCESS_UNHANDLED)
32
33 void _wapi_processes_init (void);
34 extern gpointer _wapi_process_duplicate (void);
35 extern void wapi_processes_cleanup (void);
36
37 /*
38  * MonoProcess describes processes we create.
39  * It contains a semaphore that can be waited on in order to wait
40  * for process termination. It's accessed in our SIGCHLD handler,
41  * when status is updated (and pid cleared, to not clash with 
42  * subsequent processes that may get executed).
43  */
44 struct MonoProcess {
45         pid_t pid; /* the pid of the process. This value is only valid until the process has exited. */
46         MonoSemType exit_sem; /* this semaphore will be released when the process exits */
47         int status; /* the exit status */
48         gint32 handle_count; /* the number of handles to this mono_process instance */
49         /* we keep a ref to the creating _WapiHandle_process handle until
50          * the process has exited, so that the information there isn't lost.
51          */
52         gpointer handle;
53         gboolean freeable;
54         struct MonoProcess *next;
55 };
56
57 typedef struct MonoProcess MonoProcess;
58
59 /*
60  * _WapiHandle_process is a structure containing all the required information
61  * for process handling.
62  */
63 struct _WapiHandle_process
64 {
65         pid_t id;
66         guint32 exitstatus;
67         gpointer main_thread;
68         WapiFileTime create_time;
69         WapiFileTime exit_time;
70         char *proc_name;
71         size_t min_working_set;
72         size_t max_working_set;
73         gboolean exited;
74         struct MonoProcess *mono_process;
75 };
76
77 typedef struct _WapiHandle_process WapiHandle_process;
78
79 #endif /* _WAPI_PROCESS_PRIVATE_H_ */