Adapted to separation between KERNEL and USER.
[wine] / include / server.h
1 /*
2  * Wine server definitions
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_SERVER_H
8 #define __WINE_SERVER_H
9
10 /* message header as sent on the wire */
11 struct header
12 {
13     unsigned int  len;     /* total msg length (including this header) */
14     unsigned int  type;    /* msg type */
15     unsigned int  seq;     /* sequence number */
16 };
17
18 /* max msg length (not including the header) */
19 #define MAX_MSG_LENGTH (16384 - sizeof(struct header))
20
21 /* data structure used to pass an fd with sendmsg/recvmsg */
22 struct cmsg_fd
23 {
24     int len;   /* sizeof structure */
25     int level; /* SOL_SOCKET */
26     int type;  /* SCM_RIGHTS */
27     int fd;    /* fd to pass */
28 };
29
30
31 /* Request structures */
32
33 /* following are the definitions of all the client<->server  */
34 /* communication format; requests are from client to server, */
35 /* replies are from server to client. All requests must have */
36 /* a corresponding structure; the replies can be empty in    */
37 /* which case it isn't necessary to define a structure.      */
38
39
40 /* Create a new thread from the context of the parent */
41 struct new_thread_request
42 {
43     void*        pid;          /* process id for the new thread (or 0 if none yet) */
44 };
45 struct new_thread_reply
46 {
47     void*        tid;          /* thread id */
48     int          thandle;      /* thread handle (in the current process) */
49     void*        pid;          /* process id (created if necessary) */
50     int          phandle;      /* process handle (in the current process) */
51 };
52
53
54 /* Initialize a thread; called from the child after fork()/clone() */
55 struct init_thread_request
56 {
57     int          unix_pid;     /* Unix pid of new thread */
58 };
59
60
61 /* Terminate a process */
62 struct terminate_process_request
63 {
64     int          handle;       /* process handle to terminate */
65     int          exit_code;    /* process exit code */
66 };
67
68
69 /* Terminate a thread */
70 struct terminate_thread_request
71 {
72     int          handle;       /* thread handle to terminate */
73     int          exit_code;    /* thread exit code */
74 };
75
76
77 /* Retrieve information about a process */
78 struct get_process_info_request
79 {
80     int          handle;       /* process handle */
81 };
82 struct get_process_info_reply
83 {
84     void*        pid;          /* server process id */
85     int          exit_code;    /* process exit code */
86 };
87
88
89 /* Retrieve information about a thread */
90 struct get_thread_info_request
91 {
92     int          handle;       /* thread handle */
93 };
94 struct get_thread_info_reply
95 {
96     void*        pid;          /* server thread id */
97     int          exit_code;    /* thread exit code */
98 };
99
100
101 /* Close a handle for the current process */
102 struct close_handle_request
103 {
104     int          handle;       /* handle to close */
105 };
106
107
108 /* Duplicate a handle */
109 struct dup_handle_request
110 {
111     int          src_process;  /* src process handle */
112     int          src_handle;   /* src handle to duplicate */
113     int          dst_process;  /* dst process handle */
114     int          dst_handle;   /* handle to duplicate to (or -1 for any) */
115     unsigned int access;       /* wanted access rights */
116     int          inherit;      /* inherit flag */
117     int          options;      /* duplicate options (see below) */
118 };
119 struct dup_handle_reply
120 {
121     int          handle;       /* duplicated handle in dst process */
122 };
123
124
125 /* Open a handle to a process */
126 struct open_process_request
127 {
128     void*        pid;          /* process id to open */
129     unsigned int access;       /* wanted access rights */
130     int          inherit;      /* inherit flag */
131 };
132 struct open_process_reply
133 {
134     int          handle;       /* handle to the process */
135 };
136
137
138 /* Wait for handles */
139 struct select_request
140 {
141     int          count;        /* handles count */
142     int          flags;        /* wait flags (see below) */
143     int          timeout;      /* timeout in ms */
144     /* int handles[] */
145 };
146 struct select_reply
147 {
148     int          signaled;     /* signaled handle */
149 };
150 #define SELECT_ALL       1
151 #define SELECT_MSG       2
152 #define SELECT_ALERTABLE 4
153 #define SELECT_TIMEOUT   8
154
155
156 /* Create an event */
157 struct create_event_request
158 {
159     int          manual_reset;  /* manual reset event */
160     int          initial_state; /* initial state of the event */
161     int          inherit;       /* inherit flag */
162     /* char name[] */
163 };
164 struct create_event_reply
165 {
166     int          handle;        /* handle to the event */
167 };
168
169 /* Event operation */
170 struct event_op_request
171 {
172     int           handle;       /* handle to event */
173     int           op;           /* event operation (see below) */
174 };
175 enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
176
177
178 /* Create a mutex */
179 struct create_mutex_request
180 {
181     int          owned;         /* initially owned? */
182     int          inherit;       /* inherit flag */
183     /* char name[] */
184 };
185 struct create_mutex_reply
186 {
187     int          handle;        /* handle to the mutex */
188 };
189
190
191 /* Release a mutex */
192 struct release_mutex_request
193 {
194     int          handle;        /* handle to the mutex */
195 };
196
197
198 /* Create a semaphore */
199 struct create_semaphore_request
200 {
201     unsigned int initial;       /* initial count */
202     unsigned int max;           /* maximum count */
203     int          inherit;       /* inherit flag */
204     /* char name[] */
205 };
206 struct create_semaphore_reply
207 {
208     int          handle;        /* handle to the semaphore */
209 };
210
211
212 /* Release a semaphore */
213 struct release_semaphore_request
214 {
215     int          handle;        /* handle to the semaphore */
216     unsigned int count;         /* count to add to semaphore */
217 };
218 struct release_semaphore_reply
219 {
220     unsigned int prev_count;    /* previous semaphore count */
221 };
222
223 /* Open a named object (event, mutex, semaphore) */
224 struct open_named_obj_request
225 {
226     int          type;         /* object type (see below) */
227     unsigned int access;       /* wanted access rights */
228     int          inherit;      /* inherit flag */
229     /* char name[] */
230 };
231 enum open_named_obj { OPEN_EVENT, OPEN_MUTEX, OPEN_SEMAPHORE };
232
233 struct open_named_obj_reply
234 {
235     int          handle;        /* handle to the object */
236 };
237
238
239 /* client-side functions */
240
241 #ifndef __WINE_SERVER__
242
243 /* client communication functions */
244 enum request;
245 #define CHECK_LEN(len,wanted) \
246   if ((len) == (wanted)) ; \
247   else CLIENT_ProtocolError( __FUNCTION__ ": len %d != %d\n", (len), (wanted) );
248 extern void CLIENT_ProtocolError( const char *err, ... );
249 extern void CLIENT_SendRequest( enum request req, int pass_fd,
250                                 int n, ... /* arg_1, len_1, etc. */ );
251 extern unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
252                                       int n, ... /* arg_1, len_1, etc. */ );
253
254 struct _THDB;
255 extern int CLIENT_NewThread( struct _THDB *thdb, int *thandle, int *phandle );
256 extern int CLIENT_InitThread(void);
257 extern int CLIENT_TerminateProcess( int handle, int exit_code );
258 extern int CLIENT_TerminateThread( int handle, int exit_code );
259 extern int CLIENT_CloseHandle( int handle );
260 extern int CLIENT_DuplicateHandle( int src_process, int src_handle, int dst_process,
261                                    int dst_handle, DWORD access, BOOL32 inherit, DWORD options );
262 extern int CLIENT_GetThreadInfo( int handle, struct get_thread_info_reply *reply );
263 extern int CLIENT_GetProcessInfo( int handle, struct get_process_info_reply *reply );
264 extern int CLIENT_OpenProcess( void *pid, DWORD access, BOOL32 inherit );
265 extern int CLIENT_Select( int count, int *handles, int flags, int timeout );
266 #endif  /* __WINE_SERVER__ */
267
268 #endif  /* __WINE_SERVER_H */