Implemented thread and (partial) module snapshots, based on the work
[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 #include <stdlib.h>
11 #include <time.h>
12 #include "winbase.h"
13
14 /* Request structures */
15
16 /* Following are the definitions of all the client<->server   */
17 /* communication format; if you make any change in this file, */
18 /* you must run tools/make_requests again. */
19
20
21 /* These empty macros are used by tools/make_requests */
22 /* to generate the request/reply tracing functions */
23 #define IN  /*nothing*/
24 #define OUT /*nothing*/
25
26
27 /* a path name for server requests (Unicode) */
28 typedef WCHAR path_t[MAX_PATH+1];
29
30
31 /* definitions of the event data depending on the event code */
32 struct debug_event_exception
33 {
34     EXCEPTION_RECORD record;   /* exception record */
35     int              first;    /* first chance exception? */
36 };
37 struct debug_event_create_thread
38 {
39     int         handle;     /* handle to the new thread */
40     void       *teb;        /* thread teb (in debugged process address space) */
41     void       *start;      /* thread startup routine */
42 };
43 struct debug_event_create_process
44 {
45     int         file;       /* handle to the process exe file */
46     int         process;    /* handle to the new process */
47     int         thread;     /* handle to the new thread */
48     void       *base;       /* base of executable image */
49     int         dbg_offset; /* offset of debug info in file */
50     int         dbg_size;   /* size of debug info */
51     void       *teb;        /* thread teb (in debugged process address space) */
52     void       *start;      /* thread startup routine */
53     void       *name;       /* image name (optional) */
54     int         unicode;    /* is it Unicode? */
55 };
56 struct debug_event_exit
57 {
58     int         exit_code;  /* thread or process exit code */
59 };
60 struct debug_event_load_dll
61 {
62     int         handle;     /* file handle for the dll */
63     void       *base;       /* base address of the dll */
64     int         dbg_offset; /* offset of debug info in file */
65     int         dbg_size;   /* size of debug info */
66     void       *name;       /* image name (optional) */
67     int         unicode;    /* is it Unicode? */
68 };
69 struct debug_event_unload_dll
70 {
71     void       *base;       /* base address of the dll */
72 };
73 struct debug_event_output_string
74 {
75     void       *string;     /* string to display (in debugged process address space) */
76     int         unicode;    /* is it Unicode? */
77     int         length;     /* string length */
78 };
79 struct debug_event_rip_info
80 {
81     int         error;      /* ??? */
82     int         type;       /* ??? */
83 };
84 union debug_event_data
85 {
86     struct debug_event_exception      exception;
87     struct debug_event_create_thread  create_thread;
88     struct debug_event_create_process create_process;
89     struct debug_event_exit           exit;
90     struct debug_event_load_dll       load_dll;
91     struct debug_event_unload_dll     unload_dll;
92     struct debug_event_output_string  output_string;
93     struct debug_event_rip_info       rip_info;
94 };
95
96 /* debug event data */
97 typedef struct
98 {
99     int                      code;   /* event code */
100     union debug_event_data   info;   /* event information */
101 } debug_event_t;
102
103
104 /* Create a new process from the context of the parent */
105 struct new_process_request
106 {
107     IN  int          pinherit;     /* process handle inherit flag */
108     IN  int          tinherit;     /* thread handle inherit flag */
109     IN  int          inherit_all;  /* inherit all handles from parent */
110     IN  int          create_flags; /* creation flags */
111     IN  int          start_flags;  /* flags from startup info */
112     IN  int          exe_file;     /* file handle for main exe */
113     IN  int          hstdin;       /* handle for stdin */
114     IN  int          hstdout;      /* handle for stdout */
115     IN  int          hstderr;      /* handle for stderr */
116     IN  int          cmd_show;     /* main window show mode */
117     IN  void*        env_ptr;      /* pointer to environment (FIXME: hack) */
118     OUT void*        pid;          /* process id */
119     OUT int          phandle;      /* process handle (in the current process) */
120     OUT void*        tid;          /* thread id */
121     OUT int          thandle;      /* thread handle (in the current process) */
122     OUT int          event;        /* event handle to signal startup */
123     IN  char         cmdline[1];   /* command line */
124 };
125
126
127 /* Create a new thread from the context of the parent */
128 struct new_thread_request
129 {
130     IN  int          suspend;      /* new thread should be suspended on creation */ 
131     IN  int          inherit;      /* inherit flag */
132     OUT void*        tid;          /* thread id */
133     OUT int          handle;       /* thread handle (in the current process) */
134 };
135
136
137 /* Signal that we are finished booting on the client side */
138 struct boot_done_request
139 {
140     IN  int          debug_level;  /* new debug level */
141 };
142
143
144 /* Initialize a process; called from the new process context */
145 struct init_process_request
146 {
147     IN  void*        ldt_copy;     /* addr of LDT copy */
148     IN  void*        ldt_flags;    /* addr of LDT flags */
149     OUT int          start_flags;  /* flags from startup info */
150     OUT int          exe_file;     /* file handle for main exe */
151     OUT int          hstdin;       /* handle for stdin */
152     OUT int          hstdout;      /* handle for stdout */
153     OUT int          hstderr;      /* handle for stderr */
154     OUT int          cmd_show;     /* main window show mode */
155     OUT void*        env_ptr;      /* pointer to environment (FIXME: hack) */
156     OUT char         cmdline[1];   /* command line */
157 };
158
159
160 /* Signal the end of the process initialization */
161 struct init_process_done_request
162 {
163     IN  void*        module;       /* main module base address */
164     IN  void*        entry;        /* process entry point */
165     OUT int          debugged;     /* being debugged? */
166 };
167
168
169 /* Initialize a thread; called from the child after fork()/clone() */
170 struct init_thread_request
171 {
172     IN  int          unix_pid;     /* Unix pid of new thread */
173     IN  void*        teb;          /* TEB of new thread (in thread address space) */
174     IN  void*        entry;        /* thread entry point (in thread address space) */
175 };
176
177
178 /* Retrieve the thread buffer file descriptor */
179 /* The reply to this request is the first thing a newly */
180 /* created thread gets (without having to request it) */
181 struct get_thread_buffer_request
182 {
183     OUT void*        pid;          /* process id of the new thread's process */
184     OUT void*        tid;          /* thread id of the new thread */
185     OUT int          boot;         /* is this the boot thread? */
186     OUT int          version;      /* protocol version */
187 };
188
189
190 /* Terminate a process */
191 struct terminate_process_request
192 {
193     IN  int          handle;       /* process handle to terminate */
194     IN  int          exit_code;    /* process exit code */
195     OUT int          self;         /* suicide? */
196 };
197
198
199 /* Terminate a thread */
200 struct terminate_thread_request
201 {
202     IN  int          handle;       /* thread handle to terminate */
203     IN  int          exit_code;    /* thread exit code */
204     OUT int          self;         /* suicide? */
205     OUT int          last;         /* last thread in this process? */
206 };
207
208
209 /* Retrieve information about a process */
210 struct get_process_info_request
211 {
212     IN  int          handle;           /* process handle */
213     OUT void*        pid;              /* server process id */
214     OUT int          debugged;         /* debugged? */
215     OUT int          exit_code;        /* process exit code */
216     OUT int          priority;         /* priority class */
217     OUT int          process_affinity; /* process affinity mask */
218     OUT int          system_affinity;  /* system affinity mask */
219 };
220
221
222 /* Set a process informations */
223 struct set_process_info_request
224 {
225     IN  int          handle;       /* process handle */
226     IN  int          mask;         /* setting mask (see below) */
227     IN  int          priority;     /* priority class */
228     IN  int          affinity;     /* affinity mask */
229 };
230 #define SET_PROCESS_INFO_PRIORITY 0x01
231 #define SET_PROCESS_INFO_AFFINITY 0x02
232
233
234 /* Retrieve information about a thread */
235 struct get_thread_info_request
236 {
237     IN  int          handle;       /* thread handle */
238     IN  void*        tid_in;       /* thread id (optional) */
239     OUT void*        tid;          /* server thread id */
240     OUT void*        teb;          /* thread teb pointer */
241     OUT int          exit_code;    /* thread exit code */
242     OUT int          priority;     /* thread priority level */
243 };
244
245
246 /* Set a thread informations */
247 struct set_thread_info_request
248 {
249     IN  int          handle;       /* thread handle */
250     IN  int          mask;         /* setting mask (see below) */
251     IN  int          priority;     /* priority class */
252     IN  int          affinity;     /* affinity mask */
253 };
254 #define SET_THREAD_INFO_PRIORITY 0x01
255 #define SET_THREAD_INFO_AFFINITY 0x02
256
257
258 /* Suspend a thread */
259 struct suspend_thread_request
260 {
261     IN  int          handle;       /* thread handle */
262     OUT int          count;        /* new suspend count */
263 };
264
265
266 /* Resume a thread */
267 struct resume_thread_request
268 {
269     IN  int          handle;       /* thread handle */
270     OUT int          count;        /* new suspend count */
271 };
272
273
274 /* Notify the server that a dll has been loaded */
275 struct load_dll_request
276 {
277     IN  int          handle;       /* file handle */
278     IN  void*        base;         /* base address */
279     IN  int          dbg_offset;   /* debug info offset */
280     IN  int          dbg_size;     /* debug info size */
281     IN  void*        name;         /* ptr to ptr to name (in process addr space) */
282 };
283
284
285 /* Notify the server that a dll is being unloaded */
286 struct unload_dll_request
287 {
288     IN  void*        base;         /* base address */
289 };
290
291
292 /* Queue an APC for a thread */
293 struct queue_apc_request
294 {
295     IN  int          handle;       /* thread handle */
296     IN  void*        func;         /* function to call */
297     IN  void*        param;        /* param for function to call */
298 };
299
300
301 /* Get list of APC to call */
302 struct get_apcs_request
303 {
304     OUT int          count;        /* number of apcs */
305     OUT void*        apcs[1];      /* async procedures to call */
306 };
307
308
309 /* Close a handle for the current process */
310 struct close_handle_request
311 {
312     IN  int          handle;       /* handle to close */
313 };
314
315
316 /* Get information about a handle */
317 struct get_handle_info_request
318 {
319     IN  int          handle;       /* handle we are interested in */
320     OUT int          flags;        /* handle flags */
321 };
322
323
324 /* Set a handle information */
325 struct set_handle_info_request
326 {
327     IN  int          handle;       /* handle we are interested in */
328     IN  int          flags;        /* new handle flags */
329     IN  int          mask;         /* mask for flags to set */
330 };
331
332
333 /* Duplicate a handle */
334 struct dup_handle_request
335 {
336     IN  int          src_process;  /* src process handle */
337     IN  int          src_handle;   /* src handle to duplicate */
338     IN  int          dst_process;  /* dst process handle */
339     IN  unsigned int access;       /* wanted access rights */
340     IN  int          inherit;      /* inherit flag */
341     IN  int          options;      /* duplicate options (see below) */
342     OUT int          handle;       /* duplicated handle in dst process */
343 };
344 #define DUP_HANDLE_CLOSE_SOURCE  DUPLICATE_CLOSE_SOURCE
345 #define DUP_HANDLE_SAME_ACCESS   DUPLICATE_SAME_ACCESS
346 #define DUP_HANDLE_MAKE_GLOBAL   0x80000000  /* Not a Windows flag */
347
348
349 /* Open a handle to a process */
350 struct open_process_request
351 {
352     IN  void*        pid;          /* process id to open */
353     IN  unsigned int access;       /* wanted access rights */
354     IN  int          inherit;      /* inherit flag */
355     OUT int          handle;       /* handle to the process */
356 };
357
358
359 /* Wait for handles */
360 struct select_request
361 {
362     IN  int          count;        /* handles count */
363     IN  int          flags;        /* wait flags (see below) */
364     IN  int          timeout;      /* timeout in ms */
365     OUT int          signaled;     /* signaled handle */
366     IN  int          handles[1];   /* handles to select on */
367 };
368 #define SELECT_ALL       1
369 #define SELECT_ALERTABLE 2
370 #define SELECT_TIMEOUT   4
371
372
373 /* Create an event */
374 struct create_event_request
375 {
376     IN  int          manual_reset;  /* manual reset event */
377     IN  int          initial_state; /* initial state of the event */
378     IN  int          inherit;       /* inherit flag */
379     OUT int          handle;        /* handle to the event */
380     IN  WCHAR        name[1];       /* event name */
381 };
382
383 /* Event operation */
384 struct event_op_request
385 {
386     IN  int           handle;       /* handle to event */
387     IN  int           op;           /* event operation (see below) */
388 };
389 enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
390
391
392 /* Open an event */
393 struct open_event_request
394 {
395     IN  unsigned int access;        /* wanted access rights */
396     IN  int          inherit;       /* inherit flag */
397     OUT int          handle;        /* handle to the event */
398     IN  WCHAR        name[1];       /* object name */
399 };
400
401
402 /* Create a mutex */
403 struct create_mutex_request
404 {
405     IN  int          owned;         /* initially owned? */
406     IN  int          inherit;       /* inherit flag */
407     OUT int          handle;        /* handle to the mutex */
408     IN  WCHAR        name[1];       /* mutex name */
409 };
410
411
412 /* Release a mutex */
413 struct release_mutex_request
414 {
415     IN  int          handle;        /* handle to the mutex */
416 };
417
418
419 /* Open a mutex */
420 struct open_mutex_request
421 {
422     IN  unsigned int access;        /* wanted access rights */
423     IN  int          inherit;       /* inherit flag */
424     OUT int          handle;        /* handle to the mutex */
425     IN  WCHAR        name[1];       /* object name */
426 };
427
428
429 /* Create a semaphore */
430 struct create_semaphore_request
431 {
432     IN  unsigned int initial;       /* initial count */
433     IN  unsigned int max;           /* maximum count */
434     IN  int          inherit;       /* inherit flag */
435     OUT int          handle;        /* handle to the semaphore */
436     IN  WCHAR        name[1];       /* semaphore name */
437 };
438
439
440 /* Release a semaphore */
441 struct release_semaphore_request
442 {
443     IN  int          handle;        /* handle to the semaphore */
444     IN  unsigned int count;         /* count to add to semaphore */
445     OUT unsigned int prev_count;    /* previous semaphore count */
446 };
447
448
449 /* Open a semaphore */
450 struct open_semaphore_request
451 {
452     IN  unsigned int access;        /* wanted access rights */
453     IN  int          inherit;       /* inherit flag */
454     OUT int          handle;        /* handle to the semaphore */
455     IN  WCHAR        name[1];       /* object name */
456 };
457
458
459 /* Create a file */
460 struct create_file_request
461 {
462     IN  unsigned int access;        /* wanted access rights */
463     IN  int          inherit;       /* inherit flag */
464     IN  unsigned int sharing;       /* sharing flags */
465     IN  int          create;        /* file create action */
466     IN  unsigned int attrs;         /* file attributes for creation */
467     OUT int          handle;        /* handle to the file */
468     IN  char         name[1];       /* file name */
469 };
470
471
472 /* Allocate a file handle for a Unix fd */
473 struct alloc_file_handle_request
474 {
475     IN  unsigned int access;        /* wanted access rights */
476     OUT int          handle;        /* handle to the file */
477 };
478
479
480 /* Get a Unix fd to read from a file */
481 struct get_read_fd_request
482 {
483     IN  int          handle;        /* handle to the file */
484 };
485
486
487 /* Get a Unix fd to write to a file */
488 struct get_write_fd_request
489 {
490     IN  int          handle;        /* handle to the file */
491 };
492
493
494 /* Set a file current position */
495 struct set_file_pointer_request
496 {
497     IN  int          handle;        /* handle to the file */
498     IN  int          low;           /* position low word */
499     IN  int          high;          /* position high word */
500     IN  int          whence;        /* whence to seek */
501     OUT int          new_low;       /* new position low word */
502     OUT int          new_high;      /* new position high word */
503 };
504
505
506 /* Truncate (or extend) a file */
507 struct truncate_file_request
508 {
509     IN  int          handle;        /* handle to the file */
510 };
511
512
513 /* Set a file access and modification times */
514 struct set_file_time_request
515 {
516     IN  int          handle;        /* handle to the file */
517     IN  time_t       access_time;   /* last access time */
518     IN  time_t       write_time;    /* last write time */
519 };
520
521
522 /* Flush a file buffers */
523 struct flush_file_request
524 {
525     IN  int          handle;        /* handle to the file */
526 };
527
528
529 /* Get information about a file */
530 struct get_file_info_request
531 {
532     IN  int          handle;        /* handle to the file */
533     OUT int          type;          /* file type */
534     OUT int          attr;          /* file attributes */
535     OUT time_t       access_time;   /* last access time */
536     OUT time_t       write_time;    /* last write time */
537     OUT int          size_high;     /* file size */
538     OUT int          size_low;      /* file size */
539     OUT int          links;         /* number of links */
540     OUT int          index_high;    /* unique index */
541     OUT int          index_low;     /* unique index */
542     OUT unsigned int serial;        /* volume serial number */
543 };
544
545
546 /* Lock a region of a file */
547 struct lock_file_request
548 {
549     IN  int          handle;        /* handle to the file */
550     IN  unsigned int offset_low;    /* offset of start of lock */
551     IN  unsigned int offset_high;   /* offset of start of lock */
552     IN  unsigned int count_low;     /* count of bytes to lock */
553     IN  unsigned int count_high;    /* count of bytes to lock */
554 };
555
556
557 /* Unlock a region of a file */
558 struct unlock_file_request
559 {
560     IN  int          handle;        /* handle to the file */
561     IN  unsigned int offset_low;    /* offset of start of unlock */
562     IN  unsigned int offset_high;   /* offset of start of unlock */
563     IN  unsigned int count_low;     /* count of bytes to unlock */
564     IN  unsigned int count_high;    /* count of bytes to unlock */
565 };
566
567
568 /* Create an anonymous pipe */
569 struct create_pipe_request
570 {
571     IN  int          inherit;       /* inherit flag */
572     OUT int          handle_read;   /* handle to the read-side of the pipe */
573     OUT int          handle_write;  /* handle to the write-side of the pipe */
574 };
575
576
577 /* Create a socket */
578 struct create_socket_request
579 {
580     IN  unsigned int access;        /* wanted access rights */
581     IN  int          inherit;       /* inherit flag */
582     IN  int          family;        /* family, see socket manpage */
583     IN  int          type;          /* type, see socket manpage */
584     IN  int          protocol;      /* protocol, see socket manpage */
585     OUT int          handle;        /* handle to the new socket */
586 };
587
588
589 /* Accept a socket */
590 struct accept_socket_request
591 {
592     IN  int          lhandle;       /* handle to the listening socket */
593     IN  unsigned int access;        /* wanted access rights */
594     IN  int          inherit;       /* inherit flag */
595     OUT int          handle;        /* handle to the new socket */
596 };
597
598
599 /* Set socket event parameters */
600 struct set_socket_event_request
601 {
602     IN  int          handle;        /* handle to the socket */
603     IN  unsigned int mask;          /* event mask */
604     IN  int          event;         /* event object */
605 };
606
607
608 /* Get socket event parameters */
609 struct get_socket_event_request
610 {
611     IN  int          handle;        /* handle to the socket */
612     IN  int          service;       /* clear pending? */
613     IN  int          s_event;       /* "expected" event object */
614     IN  int          c_event;       /* event to clear */
615     OUT unsigned int mask;          /* event mask */
616     OUT unsigned int pmask;         /* pending events */
617     OUT unsigned int state;         /* status bits */
618     OUT int          errors[1];     /* event errors */
619 };
620
621
622 /* Reenable pending socket events */
623 struct enable_socket_event_request
624 {
625     IN  int          handle;        /* handle to the socket */
626     IN  unsigned int mask;          /* events to re-enable */
627     IN  unsigned int sstate;        /* status bits to set */
628     IN  unsigned int cstate;        /* status bits to clear */
629 };
630
631
632 /* Allocate a console for the current process */
633 struct alloc_console_request
634 {
635     IN  unsigned int access;        /* wanted access rights */
636     IN  int          inherit;       /* inherit flag */
637     OUT int          handle_in;     /* handle to console input */
638     OUT int          handle_out;    /* handle to console output */
639 };
640
641
642 /* Free the console of the current process */
643 struct free_console_request
644 {
645     IN  int dummy;
646 };
647
648
649 /* Open a handle to the process console */
650 struct open_console_request
651 {
652     IN  int          output;        /* input or output? */
653     IN  unsigned int access;        /* wanted access rights */
654     IN  int          inherit;       /* inherit flag */
655     OUT int          handle;        /* handle to the console */
656 };
657
658
659 /* Set a console file descriptor */
660 struct set_console_fd_request
661 {
662     IN  int          handle;        /* handle to the console */
663     IN  int          file_handle;   /* handle of file to use as file descriptor */
664     IN  int          pid;           /* pid of xterm (hack) */
665 };
666
667
668 /* Get a console mode (input or output) */
669 struct get_console_mode_request
670 {
671     IN  int          handle;        /* handle to the console */
672     OUT int          mode;          /* console mode */
673 };
674
675
676 /* Set a console mode (input or output) */
677 struct set_console_mode_request
678 {
679     IN  int          handle;        /* handle to the console */
680     IN  int          mode;          /* console mode */
681 };
682
683
684 /* Set info about a console (output only) */
685 struct set_console_info_request
686 {
687     IN  int          handle;        /* handle to the console */
688     IN  int          mask;          /* setting mask (see below) */
689     IN  int          cursor_size;   /* size of cursor (percentage filled) */
690     IN  int          cursor_visible;/* cursor visibility flag */
691     IN  char         title[1];      /* console title */
692 };
693 #define SET_CONSOLE_INFO_CURSOR 0x01
694 #define SET_CONSOLE_INFO_TITLE  0x02
695
696 /* Get info about a console (output only) */
697 struct get_console_info_request
698 {
699     IN  int          handle;        /* handle to the console */
700     OUT int          cursor_size;   /* size of cursor (percentage filled) */
701     OUT int          cursor_visible;/* cursor visibility flag */
702     OUT int          pid;           /* pid of xterm (hack) */
703     OUT char         title[1];      /* console title */
704 };
705
706
707 /* Add input records to a console input queue */
708 struct write_console_input_request
709 {
710     IN  int          handle;        /* handle to the console input */
711     IN  int          count;         /* number of input records */
712     OUT int          written;       /* number of records written */
713  /* INPUT_RECORD records[0]; */     /* input records */
714 };
715
716 /* Fetch input records from a console input queue */
717 struct read_console_input_request
718 {
719     IN  int          handle;        /* handle to the console input */
720     IN  int          count;         /* max number of records to retrieve */
721     IN  int          flush;         /* flush the retrieved records from the queue? */
722     OUT int          read;          /* number of records read */
723  /* INPUT_RECORD records[0]; */     /* input records */
724 };
725
726
727 /* Create a change notification */
728 struct create_change_notification_request
729 {
730     IN  int          subtree;       /* watch all the subtree */
731     IN  int          filter;        /* notification filter */
732     OUT int          handle;        /* handle to the change notification */
733 };
734
735
736 /* Create a file mapping */
737 struct create_mapping_request
738 {
739     IN  int          size_high;     /* mapping size */
740     IN  int          size_low;      /* mapping size */
741     IN  int          protect;       /* protection flags (see below) */
742     IN  int          inherit;       /* inherit flag */
743     IN  int          file_handle;   /* file handle */
744     OUT int          handle;        /* handle to the mapping */
745     IN  WCHAR        name[1];       /* object name */
746 };
747 /* protection flags */
748 #define VPROT_READ       0x01
749 #define VPROT_WRITE      0x02
750 #define VPROT_EXEC       0x04
751 #define VPROT_WRITECOPY  0x08
752 #define VPROT_GUARD      0x10
753 #define VPROT_NOCACHE    0x20
754 #define VPROT_COMMITTED  0x40
755
756
757 /* Open a mapping */
758 struct open_mapping_request
759 {
760     IN  unsigned int access;        /* wanted access rights */
761     IN  int          inherit;       /* inherit flag */
762     OUT int          handle;        /* handle to the mapping */
763     IN  WCHAR        name[1];       /* object name */
764 };
765
766
767 /* Get information about a file mapping */
768 struct get_mapping_info_request
769 {
770     IN  int          handle;        /* handle to the mapping */
771     OUT int          size_high;     /* mapping size */
772     OUT int          size_low;      /* mapping size */
773     OUT int          protect;       /* protection flags */
774 };
775
776
777 /* Create a device */
778 struct create_device_request
779 {
780     IN  unsigned int access;        /* wanted access rights */
781     IN  int          inherit;       /* inherit flag */
782     IN  int          id;            /* client private id */
783     OUT int          handle;        /* handle to the device */
784 };
785
786
787 /* Create a snapshot */
788 struct create_snapshot_request
789 {
790     IN  int          inherit;       /* inherit flag */
791     IN  int          flags;         /* snapshot flags (TH32CS_*) */
792     IN  void*        pid;           /* process id */
793     OUT int          handle;        /* handle to the snapshot */
794 };
795
796
797 /* Get the next process from a snapshot */
798 struct next_process_request
799 {
800     IN  int          handle;        /* handle to the snapshot */
801     IN  int          reset;         /* reset snapshot position? */
802     OUT int          count;         /* process usage count */
803     OUT void*        pid;           /* process id */
804     OUT int          threads;       /* number of threads */
805     OUT int          priority;      /* process priority */
806 };
807
808
809 /* Get the next thread from a snapshot */
810 struct next_thread_request
811 {
812     IN  int          handle;        /* handle to the snapshot */
813     IN  int          reset;         /* reset snapshot position? */
814     OUT int          count;         /* thread usage count */
815     OUT void*        pid;           /* process id */
816     OUT void*        tid;           /* thread id */
817     OUT int          base_pri;      /* base priority */
818     OUT int          delta_pri;     /* delta priority */
819 };
820
821
822 /* Get the next module from a snapshot */
823 struct next_module_request
824 {
825     IN  int          handle;        /* handle to the snapshot */
826     IN  int          reset;         /* reset snapshot position? */
827     OUT void*        pid;           /* process id */
828     OUT void*        base;          /* module base address */
829 };
830
831
832 /* Wait for a debug event */
833 struct wait_debug_event_request
834 {
835     IN  int           timeout;     /* timeout in ms */
836     OUT void*         pid;         /* process id */
837     OUT void*         tid;         /* thread id */
838     OUT debug_event_t event;       /* debug event data */
839 };
840
841
842 /* Send an exception event */
843 struct exception_event_request
844 {
845     IN  EXCEPTION_RECORD record;   /* exception record */
846     IN  int              first;    /* first chance exception? */
847     IN  CONTEXT          context;  /* thread context */
848     OUT int              status;   /* event continuation status */
849 };
850
851
852 /* Send an output string to the debugger */
853 struct output_debug_string_request
854 {
855     IN  void*         string;      /* string to display (in debugged process address space) */
856     IN  int           unicode;     /* is it Unicode? */
857     IN  int           length;      /* string length */
858 };
859
860
861 /* Continue a debug event */
862 struct continue_debug_event_request
863 {
864     IN  void*        pid;          /* process id to continue */
865     IN  void*        tid;          /* thread id to continue */
866     IN  int          status;       /* continuation status */
867 };
868
869
870 /* Start debugging an existing process */
871 struct debug_process_request
872 {
873     IN  void*        pid;          /* id of the process to debug */
874 };
875
876
877 /* Read data from a process address space */
878 struct read_process_memory_request
879 {
880     IN  int          handle;       /* process handle */
881     IN  void*        addr;         /* addr to read from (must be int-aligned) */
882     IN  int          len;          /* number of ints to read */
883     OUT unsigned int data[1];      /* result data */
884 };
885
886
887 /* Write data to a process address space */
888 struct write_process_memory_request
889 {
890     IN  int          handle;       /* process handle */
891     IN  void*        addr;         /* addr to write to (must be int-aligned) */
892     IN  int          len;          /* number of ints to write */
893     IN  unsigned int first_mask;   /* mask for first word */
894     IN  unsigned int last_mask;    /* mask for last word */
895     IN  unsigned int data[1];      /* data to write */
896 };
897
898
899 /* Create a registry key */
900 struct create_key_request
901 {
902     IN  int          parent;       /* handle to the parent key */
903     IN  unsigned int access;       /* desired access rights */
904     IN  unsigned int options;      /* creation options */
905     IN  time_t       modif;        /* last modification time */
906     OUT int          hkey;         /* handle to the created key */
907     OUT int          created;      /* has it been newly created? */
908     IN  path_t       name;         /* key name */
909     IN  WCHAR        class[1];     /* class name */
910 };
911
912
913 /* Open a registry key */
914 struct open_key_request
915 {
916     IN  int          parent;       /* handle to the parent key */
917     IN  unsigned int access;       /* desired access rights */
918     OUT int          hkey;         /* handle to the open key */
919     IN  path_t       name;         /* key name */
920 };
921
922
923 /* Delete a registry key */
924 struct delete_key_request
925 {
926     IN  int          hkey;         /* handle to the parent key */
927     IN  path_t       name;         /* key name */
928 };
929
930
931 /* Close a registry key */
932 struct close_key_request
933 {
934     IN  int          hkey;          /* key to close */
935 };
936
937
938 /* Enumerate registry subkeys */
939 struct enum_key_request
940 {
941     IN  int          hkey;         /* handle to registry key */
942     IN  int          index;        /* index of subkey */
943     OUT time_t       modif;        /* last modification time */
944     OUT path_t       name;         /* subkey name */
945     OUT WCHAR        class[1];     /* class name */
946 };
947
948
949 /* Query information about a registry key */
950 struct query_key_info_request
951 {
952     IN  int          hkey;         /* handle to registry key */
953     OUT int          subkeys;      /* number of subkeys */
954     OUT int          max_subkey;   /* longest subkey name */
955     OUT int          max_class;    /* longest class name */
956     OUT int          values;       /* number of values */
957     OUT int          max_value;    /* longest value name */
958     OUT int          max_data;     /* longest value data */
959     OUT time_t       modif;        /* last modification time */
960     OUT path_t       name;         /* key name */
961     OUT WCHAR        class[1];     /* class name */
962 };
963
964
965 /* Set a value of a registry key */
966 struct set_key_value_request
967 {
968     IN  int          hkey;         /* handle to registry key */
969     IN  int          type;         /* value type */
970     IN  int          len;          /* value data len */
971     IN  path_t       name;         /* value name */
972     IN  unsigned char data[1];     /* value data */
973 };
974
975
976 /* Retrieve the value of a registry key */
977 struct get_key_value_request
978 {
979     IN  int          hkey;         /* handle to registry key */
980     OUT int          type;         /* value type */
981     OUT int          len;          /* value data len */
982     IN  WCHAR        name[1];      /* value name */
983     OUT unsigned char data[1];     /* value data */
984 };
985
986
987 /* Enumerate a value of a registry key */
988 struct enum_key_value_request
989 {
990     IN  int          hkey;         /* handle to registry key */
991     IN  int          index;        /* value index */
992     OUT int          type;         /* value type */
993     OUT int          len;          /* value data len */
994     OUT path_t       name;         /* value name */
995     OUT unsigned char data[1];     /* value data */
996 };
997
998
999 /* Delete a value of a registry key */
1000 struct delete_key_value_request
1001 {
1002     IN  int          hkey;         /* handle to registry key */
1003     IN  path_t       name;         /* value name */
1004 };
1005
1006
1007 /* Load a registry branch from a file */
1008 struct load_registry_request
1009 {
1010     IN  int          hkey;         /* root key to load to */
1011     IN  int          file;         /* file to load from */
1012     IN  path_t       name;         /* subkey name */
1013 };
1014
1015
1016 /* Save a registry branch to a file */
1017 struct save_registry_request
1018 {
1019     IN  int          hkey;         /* key to save */
1020     IN  int          file;         /* file to save to */
1021 };
1022
1023
1024 /* Save a registry branch at server exit */
1025 struct save_registry_atexit_request
1026 {
1027     IN  int          hkey;         /* key to save */
1028     IN  char         file[1];      /* file to save to */
1029 };
1030
1031
1032 /* Set the current and saving level for the registry */
1033 struct set_registry_levels_request
1034 {
1035     IN  int          current;      /* new current level */
1036     IN  int          saving;       /* new saving level */
1037     IN  int          version;      /* file format version for saving */
1038     IN  int          period;       /* duration between periodic saves (milliseconds) */
1039 };
1040
1041
1042 /* Create a waitable timer */
1043 struct create_timer_request
1044 {
1045     IN  int          inherit;       /* inherit flag */
1046     IN  int          manual;        /* manual reset */
1047     OUT int          handle;        /* handle to the timer */
1048     IN  WCHAR        name[1];       /* timer name */
1049 };
1050
1051
1052 /* Open a waitable timer */
1053 struct open_timer_request
1054 {
1055     IN  unsigned int access;        /* wanted access rights */
1056     IN  int          inherit;       /* inherit flag */
1057     OUT int          handle;        /* handle to the timer */
1058     IN  WCHAR        name[1];       /* timer name */
1059 };
1060
1061 /* Set a waitable timer */
1062 struct set_timer_request
1063 {
1064     IN  int          handle;        /* handle to the timer */
1065     IN  int          sec;           /* next expiration absolute time */
1066     IN  int          usec;          /* next expiration absolute time */
1067     IN  int          period;        /* timer period in ms */
1068     IN  void*        callback;      /* callback function */
1069     IN  void*        arg;           /* callback argument */
1070 };
1071
1072 /* Cancel a waitable timer */
1073 struct cancel_timer_request
1074 {
1075     IN  int          handle;        /* handle to the timer */
1076 };
1077
1078
1079 /* Retrieve the current context of a thread */
1080 struct get_thread_context_request
1081 {
1082     IN  int          handle;       /* thread handle */
1083     IN  unsigned int flags;        /* context flags */
1084     OUT CONTEXT      context;      /* thread context */
1085 };
1086
1087
1088 /* Set the current context of a thread */
1089 struct set_thread_context_request
1090 {
1091     IN  int          handle;       /* thread handle */
1092     IN  unsigned int flags;        /* context flags */
1093     IN  CONTEXT      context;      /* thread context */
1094 };
1095
1096
1097 /* Fetch a selector entry for a thread */
1098 struct get_selector_entry_request
1099 {
1100     IN  int           handle;      /* thread handle */
1101     IN  int           entry;       /* LDT entry */
1102     OUT unsigned int  base;        /* selector base */
1103     OUT unsigned int  limit;       /* selector limit */
1104     OUT unsigned char flags;       /* selector flags */
1105 };
1106
1107
1108 /* Add a global atom */
1109 struct add_atom_request
1110 {
1111     OUT int           atom;        /* resulting atom */
1112     IN  WCHAR         name[1];     /* atom name */
1113 };
1114
1115
1116 /* Delete a global atom */
1117 struct delete_atom_request
1118 {
1119     IN  int           atom;        /* atom handle */
1120 };
1121
1122
1123 /* Find a global atom */
1124 struct find_atom_request
1125 {
1126     OUT int          atom;         /* atom handle */
1127     IN  WCHAR        name[1];      /* atom name */
1128 };
1129
1130
1131 /* Get a global atom name */
1132 struct get_atom_name_request
1133 {
1134     IN  int          atom;         /* atom handle */
1135     OUT int          count;        /* atom lock count */
1136     OUT WCHAR        name[1];      /* atom name */
1137 };
1138
1139 /* Everything below this line is generated automatically by tools/make_requests */
1140 /* ### make_requests begin ### */
1141
1142 enum request
1143 {
1144     REQ_NEW_PROCESS,
1145     REQ_NEW_THREAD,
1146     REQ_BOOT_DONE,
1147     REQ_INIT_PROCESS,
1148     REQ_INIT_PROCESS_DONE,
1149     REQ_INIT_THREAD,
1150     REQ_GET_THREAD_BUFFER,
1151     REQ_TERMINATE_PROCESS,
1152     REQ_TERMINATE_THREAD,
1153     REQ_GET_PROCESS_INFO,
1154     REQ_SET_PROCESS_INFO,
1155     REQ_GET_THREAD_INFO,
1156     REQ_SET_THREAD_INFO,
1157     REQ_SUSPEND_THREAD,
1158     REQ_RESUME_THREAD,
1159     REQ_LOAD_DLL,
1160     REQ_UNLOAD_DLL,
1161     REQ_QUEUE_APC,
1162     REQ_GET_APCS,
1163     REQ_CLOSE_HANDLE,
1164     REQ_GET_HANDLE_INFO,
1165     REQ_SET_HANDLE_INFO,
1166     REQ_DUP_HANDLE,
1167     REQ_OPEN_PROCESS,
1168     REQ_SELECT,
1169     REQ_CREATE_EVENT,
1170     REQ_EVENT_OP,
1171     REQ_OPEN_EVENT,
1172     REQ_CREATE_MUTEX,
1173     REQ_RELEASE_MUTEX,
1174     REQ_OPEN_MUTEX,
1175     REQ_CREATE_SEMAPHORE,
1176     REQ_RELEASE_SEMAPHORE,
1177     REQ_OPEN_SEMAPHORE,
1178     REQ_CREATE_FILE,
1179     REQ_ALLOC_FILE_HANDLE,
1180     REQ_GET_READ_FD,
1181     REQ_GET_WRITE_FD,
1182     REQ_SET_FILE_POINTER,
1183     REQ_TRUNCATE_FILE,
1184     REQ_SET_FILE_TIME,
1185     REQ_FLUSH_FILE,
1186     REQ_GET_FILE_INFO,
1187     REQ_LOCK_FILE,
1188     REQ_UNLOCK_FILE,
1189     REQ_CREATE_PIPE,
1190     REQ_CREATE_SOCKET,
1191     REQ_ACCEPT_SOCKET,
1192     REQ_SET_SOCKET_EVENT,
1193     REQ_GET_SOCKET_EVENT,
1194     REQ_ENABLE_SOCKET_EVENT,
1195     REQ_ALLOC_CONSOLE,
1196     REQ_FREE_CONSOLE,
1197     REQ_OPEN_CONSOLE,
1198     REQ_SET_CONSOLE_FD,
1199     REQ_GET_CONSOLE_MODE,
1200     REQ_SET_CONSOLE_MODE,
1201     REQ_SET_CONSOLE_INFO,
1202     REQ_GET_CONSOLE_INFO,
1203     REQ_WRITE_CONSOLE_INPUT,
1204     REQ_READ_CONSOLE_INPUT,
1205     REQ_CREATE_CHANGE_NOTIFICATION,
1206     REQ_CREATE_MAPPING,
1207     REQ_OPEN_MAPPING,
1208     REQ_GET_MAPPING_INFO,
1209     REQ_CREATE_DEVICE,
1210     REQ_CREATE_SNAPSHOT,
1211     REQ_NEXT_PROCESS,
1212     REQ_NEXT_THREAD,
1213     REQ_NEXT_MODULE,
1214     REQ_WAIT_DEBUG_EVENT,
1215     REQ_EXCEPTION_EVENT,
1216     REQ_OUTPUT_DEBUG_STRING,
1217     REQ_CONTINUE_DEBUG_EVENT,
1218     REQ_DEBUG_PROCESS,
1219     REQ_READ_PROCESS_MEMORY,
1220     REQ_WRITE_PROCESS_MEMORY,
1221     REQ_CREATE_KEY,
1222     REQ_OPEN_KEY,
1223     REQ_DELETE_KEY,
1224     REQ_CLOSE_KEY,
1225     REQ_ENUM_KEY,
1226     REQ_QUERY_KEY_INFO,
1227     REQ_SET_KEY_VALUE,
1228     REQ_GET_KEY_VALUE,
1229     REQ_ENUM_KEY_VALUE,
1230     REQ_DELETE_KEY_VALUE,
1231     REQ_LOAD_REGISTRY,
1232     REQ_SAVE_REGISTRY,
1233     REQ_SAVE_REGISTRY_ATEXIT,
1234     REQ_SET_REGISTRY_LEVELS,
1235     REQ_CREATE_TIMER,
1236     REQ_OPEN_TIMER,
1237     REQ_SET_TIMER,
1238     REQ_CANCEL_TIMER,
1239     REQ_GET_THREAD_CONTEXT,
1240     REQ_SET_THREAD_CONTEXT,
1241     REQ_GET_SELECTOR_ENTRY,
1242     REQ_ADD_ATOM,
1243     REQ_DELETE_ATOM,
1244     REQ_FIND_ATOM,
1245     REQ_GET_ATOM_NAME,
1246     REQ_NB_REQUESTS
1247 };
1248
1249 #define SERVER_PROTOCOL_VERSION 9
1250
1251 /* ### make_requests end ### */
1252 /* Everything above this line is generated automatically by tools/make_requests */
1253
1254
1255 /* client-side functions */
1256
1257 #ifndef __WINE_SERVER__
1258
1259 #include "thread.h"
1260 #include "ntddk.h"
1261
1262 /* client communication functions */
1263
1264 extern unsigned int server_call_noerr( enum request req );
1265 extern unsigned int server_call_fd( enum request req, int fd_out, int *fd_in );
1266 extern void server_protocol_error( const char *err, ... ) WINE_NORETURN;
1267 extern const char *get_config_dir(void);
1268
1269 /* get a pointer to the request buffer */
1270 static inline void * WINE_UNUSED get_req_buffer(void)
1271 {
1272     return NtCurrentTeb()->buffer;
1273 }
1274
1275 /* maximum remaining size in the server buffer */
1276 static inline int WINE_UNUSED server_remaining( const void *ptr )
1277 {
1278     return (char *)NtCurrentTeb()->buffer + NtCurrentTeb()->buffer_size - (char *)ptr;
1279 }
1280
1281 /* do a server call and set the last error code */
1282 static inline int server_call( enum request req )
1283 {
1284     unsigned int res = server_call_noerr( req );
1285     if (res) SetLastError( RtlNtStatusToDosError(res) );
1286     return res;
1287 }
1288
1289 /* copy a Unicode string to the server buffer */
1290 static inline void server_strcpyW( WCHAR *dst, const WCHAR *src )
1291 {
1292     if (src)
1293     {
1294         WCHAR *end = (WCHAR *)((char *)NtCurrentTeb()->buffer + NtCurrentTeb()->buffer_size) - 1;
1295         while ((dst < end) && *src) *dst++ = *src++;
1296     }
1297     *dst = 0;
1298 }
1299
1300 /* copy and convert an ASCII string to the server buffer */
1301 static inline void server_strcpyAtoW( WCHAR *dst, const char *src )
1302 {
1303     if (src)
1304     {
1305         WCHAR *end = (WCHAR *)((char *)NtCurrentTeb()->buffer + NtCurrentTeb()->buffer_size) - 1;
1306         while ((dst < end) && *src) *dst++ = (WCHAR)(unsigned char)*src++;
1307     }
1308     *dst = 0;
1309 }
1310
1311 extern int CLIENT_InitServer(void);
1312 extern int CLIENT_BootDone( int debug_level );
1313 extern int CLIENT_IsBootThread(void);
1314 extern int CLIENT_InitThread(void);
1315 #endif  /* __WINE_SERVER__ */
1316
1317 #endif  /* __WINE_SERVER_H */