Added support for dumping variable-size data of server replies.
[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
13 /* message header as sent on the wire */
14 struct header
15 {
16     unsigned int  len;     /* total msg length (including this header) */
17     unsigned int  type;    /* msg type */
18     unsigned int  seq;     /* sequence number */
19 };
20
21 /* max msg length (not including the header) */
22 #define MAX_MSG_LENGTH (16384 - sizeof(struct header))
23
24 /* data structure used to pass an fd with sendmsg/recvmsg */
25 struct cmsg_fd
26 {
27     int len;   /* sizeof structure */
28     int level; /* SOL_SOCKET */
29     int type;  /* SCM_RIGHTS */
30     int fd;    /* fd to pass */
31 };
32
33 /* request handler definition */
34 #define DECL_HANDLER(name) \
35     void req_##name( struct name##_request *req, void *data, int len, int fd )
36
37 /* Request structures */
38
39 /* following are the definitions of all the client<->server  */
40 /* communication format; requests are from client to server, */
41 /* replies are from server to client. All requests must have */
42 /* a corresponding structure; the replies can be empty in    */
43 /* which case it isn't necessary to define a structure.      */
44
45
46 /* Create a new process from the context of the parent */
47 struct new_process_request
48 {
49     int          inherit;      /* inherit flag */
50     int          inherit_all;  /* inherit all handles from parent */
51     int          create_flags; /* creation flags */
52     int          start_flags;  /* flags from startup info */
53     int          hstdin;       /* handle for stdin */
54     int          hstdout;      /* handle for stdout */
55     int          hstderr;      /* handle for stderr */
56     int          cmd_show;     /* main window show mode */
57     void*        env_ptr;      /* pointer to environment (FIXME: hack) */
58     char         cmd_line[0];  /* command line */
59 };
60 struct new_process_reply
61 {
62     void*        pid;          /* process id */
63     int          handle;       /* process handle (in the current process) */
64 };
65
66
67 /* Create a new thread from the context of the parent */
68 struct new_thread_request
69 {
70     void*        pid;          /* process id for the new thread */
71     int          suspend;      /* new thread should be suspended on creation */ 
72     int          inherit;      /* inherit flag */
73 };
74 struct new_thread_reply
75 {
76     void*        tid;          /* thread id */
77     int          handle;       /* thread handle (in the current process) */
78 };
79
80
81 /* Set the server debug level */
82 struct set_debug_request
83 {
84     int          level;        /* New debug level */
85 };
86
87
88 /* Initialize a process; called from the new process context */
89 struct init_process_request
90 {
91     int          dummy;
92 };
93 struct init_process_reply
94 {
95     int          start_flags;  /* flags from startup info */
96     int          hstdin;       /* handle for stdin */
97     int          hstdout;      /* handle for stdout */
98     int          hstderr;      /* handle for stderr */
99     int          cmd_show;     /* main window show mode */
100     void*        env_ptr;      /* pointer to environment (FIXME: hack) */
101     char         cmdline[0];   /* command line */
102 };
103
104
105 /* Initialize a thread; called from the child after fork()/clone() */
106 struct init_thread_request
107 {
108     int          unix_pid;     /* Unix pid of new thread */
109     void*        teb;          /* TEB of new thread (in thread address space) */
110 };
111 struct init_thread_reply
112 {
113     void*        pid;          /* process id of the new thread's process */
114     void*        tid;          /* thread id of the new thread */
115 };
116
117
118 /* Terminate a process */
119 struct terminate_process_request
120 {
121     int          handle;       /* process handle to terminate */
122     int          exit_code;    /* process exit code */
123 };
124
125
126 /* Terminate a thread */
127 struct terminate_thread_request
128 {
129     int          handle;       /* thread handle to terminate */
130     int          exit_code;    /* thread exit code */
131 };
132
133
134 /* Retrieve information about a process */
135 struct get_process_info_request
136 {
137     int          handle;       /* process handle */
138 };
139 struct get_process_info_reply
140 {
141     void*        pid;              /* server process id */
142     int          exit_code;        /* process exit code */
143     int          priority;         /* priority class */
144     int          process_affinity; /* process affinity mask */
145     int          system_affinity;  /* system affinity mask */
146 };
147
148
149 /* Set a process informations */
150 struct set_process_info_request
151 {
152     int          handle;       /* process handle */
153     int          mask;         /* setting mask (see below) */
154     int          priority;     /* priority class */
155     int          affinity;     /* affinity mask */
156 };
157 #define SET_PROCESS_INFO_PRIORITY 0x01
158 #define SET_PROCESS_INFO_AFFINITY 0x02
159
160
161 /* Retrieve information about a thread */
162 struct get_thread_info_request
163 {
164     int          handle;       /* thread handle */
165 };
166 struct get_thread_info_reply
167 {
168     void*        tid;          /* server thread id */
169     int          exit_code;    /* thread exit code */
170     int          priority;     /* thread priority level */
171 };
172
173
174 /* Set a thread informations */
175 struct set_thread_info_request
176 {
177     int          handle;       /* thread handle */
178     int          mask;         /* setting mask (see below) */
179     int          priority;     /* priority class */
180     int          affinity;     /* affinity mask */
181 };
182 #define SET_THREAD_INFO_PRIORITY 0x01
183 #define SET_THREAD_INFO_AFFINITY 0x02
184
185
186 /* Suspend a thread */
187 struct suspend_thread_request
188 {
189     int          handle;       /* thread handle */
190 };
191 struct suspend_thread_reply
192 {
193     int          count;        /* new suspend count */
194 };
195
196
197 /* Resume a thread */
198 struct resume_thread_request
199 {
200     int          handle;       /* thread handle */
201 };
202 struct resume_thread_reply
203 {
204     int          count;        /* new suspend count */
205 };
206
207
208 /* Debugger support: freeze / unfreeze */
209 struct debugger_request
210 {
211     int          op;           /* operation type */
212 };
213
214 enum debugger_op { DEBUGGER_FREEZE_ALL, DEBUGGER_UNFREEZE_ALL };
215
216
217 /* Queue an APC for a thread */
218 struct queue_apc_request
219 {
220     int          handle;       /* thread handle */
221     void*        func;         /* function to call */
222     void*        param;        /* param for function to call */
223 };
224
225
226 /* Close a handle for the current process */
227 struct close_handle_request
228 {
229     int          handle;       /* handle to close */
230 };
231
232
233 /* Get information about a handle */
234 struct get_handle_info_request
235 {
236     int          handle;       /* handle we are interested in */
237 };
238 struct get_handle_info_reply
239 {
240     int          flags;        /* handle flags */
241 };
242
243
244 /* Set a handle information */
245 struct set_handle_info_request
246 {
247     int          handle;       /* handle we are interested in */
248     int          flags;        /* new handle flags */
249     int          mask;         /* mask for flags to set */
250 };
251
252
253 /* Duplicate a handle */
254 struct dup_handle_request
255 {
256     int          src_process;  /* src process handle */
257     int          src_handle;   /* src handle to duplicate */
258     int          dst_process;  /* dst process handle */
259     unsigned int access;       /* wanted access rights */
260     int          inherit;      /* inherit flag */
261     int          options;      /* duplicate options (see below) */
262 };
263 #define DUP_HANDLE_CLOSE_SOURCE  DUPLICATE_CLOSE_SOURCE
264 #define DUP_HANDLE_SAME_ACCESS   DUPLICATE_SAME_ACCESS
265 #define DUP_HANDLE_MAKE_GLOBAL   0x80000000  /* Not a Windows flag */
266 struct dup_handle_reply
267 {
268     int          handle;       /* duplicated handle in dst process */
269 };
270
271
272 /* Open a handle to a process */
273 struct open_process_request
274 {
275     void*        pid;          /* process id to open */
276     unsigned int access;       /* wanted access rights */
277     int          inherit;      /* inherit flag */
278 };
279 struct open_process_reply
280 {
281     int          handle;       /* handle to the process */
282 };
283
284
285 /* Wait for handles */
286 struct select_request
287 {
288     int          count;        /* handles count */
289     int          flags;        /* wait flags (see below) */
290     int          timeout;      /* timeout in ms */
291     int          handles[0];   /* handles to select on */
292 };
293 struct select_reply
294 {
295     int          signaled;     /* signaled handle */
296     void*        apcs[0];      /* async procedures to call */
297 };
298 #define SELECT_ALL       1
299 #define SELECT_ALERTABLE 2
300 #define SELECT_TIMEOUT   4
301
302
303 /* Create an event */
304 struct create_event_request
305 {
306     int          manual_reset;  /* manual reset event */
307     int          initial_state; /* initial state of the event */
308     int          inherit;       /* inherit flag */
309     char         name[0];       /* event name */
310 };
311 struct create_event_reply
312 {
313     int          handle;        /* handle to the event */
314 };
315
316 /* Event operation */
317 struct event_op_request
318 {
319     int           handle;       /* handle to event */
320     int           op;           /* event operation (see below) */
321 };
322 enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
323
324
325 /* Open an event */
326 struct open_event_request
327 {
328     unsigned int access;        /* wanted access rights */
329     int          inherit;       /* inherit flag */
330     char         name[0];       /* object name */
331 };
332 struct open_event_reply
333 {
334     int          handle;        /* handle to the event */
335 };
336
337
338 /* Create a mutex */
339 struct create_mutex_request
340 {
341     int          owned;         /* initially owned? */
342     int          inherit;       /* inherit flag */
343     char         name[0];       /* mutex name */
344 };
345 struct create_mutex_reply
346 {
347     int          handle;        /* handle to the mutex */
348 };
349
350
351 /* Release a mutex */
352 struct release_mutex_request
353 {
354     int          handle;        /* handle to the mutex */
355 };
356
357
358 /* Open a mutex */
359 struct open_mutex_request
360 {
361     unsigned int access;        /* wanted access rights */
362     int          inherit;       /* inherit flag */
363     char         name[0];       /* object name */
364 };
365 struct open_mutex_reply
366 {
367     int          handle;        /* handle to the mutex */
368 };
369
370
371 /* Create a semaphore */
372 struct create_semaphore_request
373 {
374     unsigned int initial;       /* initial count */
375     unsigned int max;           /* maximum count */
376     int          inherit;       /* inherit flag */
377     char         name[0];       /* semaphore name */
378 };
379 struct create_semaphore_reply
380 {
381     int          handle;        /* handle to the semaphore */
382 };
383
384
385 /* Release a semaphore */
386 struct release_semaphore_request
387 {
388     int          handle;        /* handle to the semaphore */
389     unsigned int count;         /* count to add to semaphore */
390 };
391 struct release_semaphore_reply
392 {
393     unsigned int prev_count;    /* previous semaphore count */
394 };
395
396
397 /* Open a semaphore */
398 struct open_semaphore_request
399 {
400     unsigned int access;        /* wanted access rights */
401     int          inherit;       /* inherit flag */
402     char         name[0];       /* object name */
403 };
404 struct open_semaphore_reply
405 {
406     int          handle;        /* handle to the semaphore */
407 };
408
409
410 /* Create a file */
411 struct create_file_request
412 {
413     unsigned int access;        /* wanted access rights */
414     int          inherit;       /* inherit flag */
415     unsigned int sharing;       /* sharing flags */
416     int          create;        /* file create action */
417     unsigned int attrs;         /* file attributes for creation */
418     char         name[0];       /* file name */
419 };
420 struct create_file_reply
421 {
422     int          handle;        /* handle to the file */
423 };
424
425
426 /* Get a Unix fd to read from a file */
427 struct get_read_fd_request
428 {
429     int          handle;        /* handle to the file */
430 };
431
432
433 /* Get a Unix fd to write to a file */
434 struct get_write_fd_request
435 {
436     int          handle;        /* handle to the file */
437 };
438
439
440 /* Set a file current position */
441 struct set_file_pointer_request
442 {
443     int          handle;        /* handle to the file */
444     int          low;           /* position low word */
445     int          high;          /* position high word */
446     int          whence;        /* whence to seek */
447 };
448 struct set_file_pointer_reply
449 {
450     int          low;           /* new position low word */
451     int          high;          /* new position high word */
452 };
453
454
455 /* Truncate (or extend) a file */
456 struct truncate_file_request
457 {
458     int          handle;        /* handle to the file */
459 };
460
461
462 /* Set a file access and modification times */
463 struct set_file_time_request
464 {
465     int          handle;        /* handle to the file */
466     time_t       access_time;   /* last access time */
467     time_t       write_time;    /* last write time */
468 };
469
470
471 /* Flush a file buffers */
472 struct flush_file_request
473 {
474     int          handle;        /* handle to the file */
475 };
476
477
478 /* Get information about a file */
479 struct get_file_info_request
480 {
481     int          handle;        /* handle to the file */
482 };
483 struct get_file_info_reply
484 {
485     int          type;          /* file type */
486     int          attr;          /* file attributes */
487     time_t       access_time;   /* last access time */
488     time_t       write_time;    /* last write time */
489     int          size_high;     /* file size */
490     int          size_low;      /* file size */
491     int          links;         /* number of links */
492     int          index_high;    /* unique index */
493     int          index_low;     /* unique index */
494     unsigned int serial;        /* volume serial number */
495 };
496
497
498 /* Lock a region of a file */
499 struct lock_file_request
500 {
501     int          handle;        /* handle to the file */
502     unsigned int offset_low;    /* offset of start of lock */
503     unsigned int offset_high;   /* offset of start of lock */
504     unsigned int count_low;     /* count of bytes to lock */
505     unsigned int count_high;    /* count of bytes to lock */
506 };
507
508
509 /* Unlock a region of a file */
510 struct unlock_file_request
511 {
512     int          handle;        /* handle to the file */
513     unsigned int offset_low;    /* offset of start of unlock */
514     unsigned int offset_high;   /* offset of start of unlock */
515     unsigned int count_low;     /* count of bytes to unlock */
516     unsigned int count_high;    /* count of bytes to unlock */
517 };
518
519
520 /* Create an anonymous pipe */
521 struct create_pipe_request
522 {
523     int          inherit;       /* inherit flag */
524 };
525 struct create_pipe_reply
526 {
527     int          handle_read;   /* handle to the read-side of the pipe */
528     int          handle_write;  /* handle to the write-side of the pipe */
529 };
530
531
532 /* Allocate a console for the current process */
533 struct alloc_console_request
534 {
535     int dummy;
536 };
537
538
539 /* Free the console of the current process */
540 struct free_console_request
541 {
542     int dummy;
543 };
544
545
546 /* Open a handle to the process console */
547 struct open_console_request
548 {
549     int          output;        /* input or output? */
550     unsigned int access;        /* wanted access rights */
551     int          inherit;       /* inherit flag */
552 };
553 struct open_console_reply
554 {
555     int          handle;        /* handle to the console */
556 };
557
558
559 /* Set a console file descriptor */
560 struct set_console_fd_request
561 {
562     int          handle;        /* handle to the console */
563     int          pid;           /* pid of xterm (hack) */
564 };
565
566
567 /* Get a console mode (input or output) */
568 struct get_console_mode_request
569 {
570     int          handle;        /* handle to the console */
571 };
572 struct get_console_mode_reply
573 {
574     int          mode;          /* console mode */
575 };
576
577
578 /* Set a console mode (input or output) */
579 struct set_console_mode_request
580 {
581     int          handle;        /* handle to the console */
582     int          mode;          /* console mode */
583 };
584
585
586 /* Set info about a console (output only) */
587 struct set_console_info_request
588 {
589     int          handle;        /* handle to the console */
590     int          mask;          /* setting mask (see below) */
591     int          cursor_size;   /* size of cursor (percentage filled) */
592     int          cursor_visible;/* cursor visibility flag */
593     char         title[0];      /* console title */
594 };
595 #define SET_CONSOLE_INFO_CURSOR 0x01
596 #define SET_CONSOLE_INFO_TITLE  0x02
597
598 /* Get info about a console (output only) */
599 struct get_console_info_request
600 {
601     int          handle;        /* handle to the console */
602 };
603 struct get_console_info_reply
604 {
605     int          cursor_size;   /* size of cursor (percentage filled) */
606     int          cursor_visible;/* cursor visibility flag */
607     int          pid;           /* pid of xterm (hack) */
608 /*  char         title[0]; */   /* console title */
609 };
610
611
612 /* Add input records to a console input queue */
613 struct write_console_input_request
614 {
615     int          handle;        /* handle to the console input */
616     int          count;         /* number of input records */
617 /*  INPUT_RECORD records[0]; */ /* input records */
618 };
619 struct write_console_input_reply
620 {
621     int          written;       /* number of records written */
622 };
623
624 /* Fetch input records from a console input queue */
625 struct read_console_input_request
626 {
627     int          handle;        /* handle to the console input */
628     int          count;         /* max number of records to retrieve */
629     int          flush;         /* flush the retrieved records from the queue? */
630 };
631 struct read_console_input_reply
632 {
633     int dummy;
634 /*  INPUT_RECORD records[0]; */ /* input records */
635 };
636
637
638 /* Create a change notification */
639 struct create_change_notification_request
640 {
641     int          subtree;       /* watch all the subtree */
642     int          filter;        /* notification filter */
643 };
644 struct create_change_notification_reply
645 {
646     int          handle;        /* handle to the change notification */
647 };
648
649
650 /* Create a file mapping */
651 struct create_mapping_request
652 {
653     int          size_high;     /* mapping size */
654     int          size_low;      /* mapping size */
655     int          protect;       /* protection flags (see below) */
656     int          inherit;       /* inherit flag */
657     int          handle;        /* file handle */
658     char         name[0];       /* object name */
659 };
660 struct create_mapping_reply
661 {
662     int          handle;        /* handle to the mapping */
663 };
664 /* protection flags */
665 #define VPROT_READ       0x01
666 #define VPROT_WRITE      0x02
667 #define VPROT_EXEC       0x04
668 #define VPROT_WRITECOPY  0x08
669 #define VPROT_GUARD      0x10
670 #define VPROT_NOCACHE    0x20
671 #define VPROT_COMMITTED  0x40
672
673
674 /* Open a mapping */
675 struct open_mapping_request
676 {
677     unsigned int access;        /* wanted access rights */
678     int          inherit;       /* inherit flag */
679     char         name[0];       /* object name */
680 };
681 struct open_mapping_reply
682 {
683     int          handle;        /* handle to the mapping */
684 };
685
686
687 /* Get information about a file mapping */
688 struct get_mapping_info_request
689 {
690     int          handle;        /* handle to the mapping */
691 };
692 struct get_mapping_info_reply
693 {
694     int          size_high;     /* mapping size */
695     int          size_low;      /* mapping size */
696     int          protect;       /* protection flags */
697 };
698
699
700 /* Create a device */
701 struct create_device_request
702 {
703     unsigned int access;        /* wanted access rights */
704     int          inherit;       /* inherit flag */
705     int          id;            /* client private id */
706 };
707 struct create_device_reply
708 {
709     int          handle;        /* handle to the device */
710 };
711
712
713 /* Create a snapshot */
714 struct create_snapshot_request
715 {
716     int          inherit;       /* inherit flag */
717     int          flags;         /* snapshot flags (TH32CS_*) */
718 };
719 struct create_snapshot_reply
720 {
721     int          handle;        /* handle to the snapshot */
722 };
723
724
725 /* Get the next process from a snapshot */
726 struct next_process_request
727 {
728     int          handle;        /* handle to the snapshot */
729     int          reset;         /* reset snapshot position? */
730 };
731 struct next_process_reply
732 {
733     void*        pid;          /* process id */
734     int          threads;      /* number of threads */
735     int          priority;     /* process priority */
736 };
737
738
739 /* Wait for a debug event */
740 struct wait_debug_event_request
741 {
742     int          timeout;      /* timeout in ms */
743 };
744 struct wait_debug_event_reply
745 {
746     int          code;         /* event code */
747     void*        pid;          /* process id */
748     void*        tid;          /* thread id */
749     /* followed by the event data (see below) */
750 };
751
752
753 /* Send a debug event */
754 struct send_debug_event_request
755 {
756     int          code;         /* event code */
757     /* followed by the event data (see below) */
758 };
759 struct send_debug_event_reply
760 {
761     int          status;       /* event continuation status */
762 };
763
764
765 /* definitions of the event data depending on the event code */
766 struct debug_event_exception
767 {
768     int        code;           /* exception code */
769     int        flags;          /* exception flags */
770     void      *record;         /* exception record ptr */
771     void      *addr;           /* exception address */
772     int        nb_params;      /* exceptions parameters */
773     int        params[15];
774     int        first_chance;   /* first chance to handle it? */
775 };
776 struct debug_event_create_thread
777 {
778     int         handle;     /* handle to the new thread */
779     void       *teb;        /* thread teb (in debugged process address space) */
780     void       *start;      /* thread startup routine */
781 };
782 struct debug_event_create_process
783 {
784     int         file;       /* handle to the process exe file */
785     int         process;    /* handle to the new process */
786     int         thread;     /* handle to the new thread */
787     void       *base;       /* base of executable image */
788     int         dbg_offset; /* offset of debug info in file */
789     int         dbg_size;   /* size of debug info */
790     void       *teb;        /* thread teb (in debugged process address space) */
791     void       *start;      /* thread startup routine */
792     void       *name;       /* image name (optional) */
793     int         unicode;    /* is it Unicode? */
794 };
795 struct debug_event_exit
796 {
797     int         exit_code;  /* thread or process exit code */
798 };
799 struct debug_event_load_dll
800 {
801     int         handle;     /* file handle for the dll */
802     void       *base;       /* base address of the dll */
803     int         dbg_offset; /* offset of debug info in file */
804     int         dbg_size;   /* size of debug info */
805     void       *name;       /* image name (optional) */
806     int         unicode;    /* is it Unicode? */
807 };
808 struct debug_event_unload_dll
809 {
810     void       *base;       /* base address of the dll */
811 };
812 struct debug_event_output_string
813 {
814     void       *string;     /* string to display (in debugged process address space) */
815     int         unicode;    /* is it Unicode? */
816     int         length;     /* string length */
817 };
818 struct debug_event_rip_info
819 {
820     int         error;      /* ??? */
821     int         type;       /* ??? */
822 };
823 union debug_event_data
824 {
825     struct debug_event_exception      exception;
826     struct debug_event_create_thread  create_thread;
827     struct debug_event_create_process create_process;
828     struct debug_event_exit           exit;
829     struct debug_event_load_dll       load_dll;
830     struct debug_event_unload_dll     unload_dll;
831     struct debug_event_output_string  output_string;
832     struct debug_event_rip_info       rip_info;
833 };
834
835
836 /* Continue a debug event */
837 struct continue_debug_event_request
838 {
839     void*        pid;          /* process id to continue */
840     void*        tid;          /* thread id to continue */
841     int          status;       /* continuation status */
842 };
843
844
845 /* Start debugging an existing process */
846 struct debug_process_request
847 {
848     void*        pid;          /* id of the process to debug */
849 };
850
851
852 /* requests definitions */
853 #include "server/request.h"
854
855 /* client-side functions */
856
857 #ifndef __WINE_SERVER__
858
859 /* client communication functions */
860 extern void CLIENT_ProtocolError( const char *err, ... );
861 extern void CLIENT_SendRequest( enum request req, int pass_fd,
862                                 int n, ... /* arg_1, len_1, etc. */ );
863 extern unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
864                                       int n, ... /* arg_1, len_1, etc. */ );
865 extern unsigned int CLIENT_WaitSimpleReply( void *reply, int len, int *passed_fd );
866 extern int CLIENT_InitServer(void);
867 extern int CLIENT_SetDebug( int level );
868 extern int CLIENT_DebuggerRequest( int op );
869 extern int CLIENT_InitThread(void);
870 #endif  /* __WINE_SERVER__ */
871
872 #endif  /* __WINE_SERVER_H */