Added DebugBreak.
[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     unsigned int access;        /* wanted access rights */
536     int          inherit;       /* inherit flag */
537 };
538 struct alloc_console_reply
539 {
540     int          handle_in;     /* handle to console input */
541     int          handle_out;    /* handle to console output */
542 };
543
544
545 /* Free the console of the current process */
546 struct free_console_request
547 {
548     int dummy;
549 };
550
551
552 /* Open a handle to the process console */
553 struct open_console_request
554 {
555     int          output;        /* input or output? */
556     unsigned int access;        /* wanted access rights */
557     int          inherit;       /* inherit flag */
558 };
559 struct open_console_reply
560 {
561     int          handle;        /* handle to the console */
562 };
563
564
565 /* Set a console file descriptor */
566 struct set_console_fd_request
567 {
568     int          handle;        /* handle to the console */
569     int          pid;           /* pid of xterm (hack) */
570 };
571
572
573 /* Get a console mode (input or output) */
574 struct get_console_mode_request
575 {
576     int          handle;        /* handle to the console */
577 };
578 struct get_console_mode_reply
579 {
580     int          mode;          /* console mode */
581 };
582
583
584 /* Set a console mode (input or output) */
585 struct set_console_mode_request
586 {
587     int          handle;        /* handle to the console */
588     int          mode;          /* console mode */
589 };
590
591
592 /* Set info about a console (output only) */
593 struct set_console_info_request
594 {
595     int          handle;        /* handle to the console */
596     int          mask;          /* setting mask (see below) */
597     int          cursor_size;   /* size of cursor (percentage filled) */
598     int          cursor_visible;/* cursor visibility flag */
599     char         title[0];      /* console title */
600 };
601 #define SET_CONSOLE_INFO_CURSOR 0x01
602 #define SET_CONSOLE_INFO_TITLE  0x02
603
604 /* Get info about a console (output only) */
605 struct get_console_info_request
606 {
607     int          handle;        /* handle to the console */
608 };
609 struct get_console_info_reply
610 {
611     int          cursor_size;   /* size of cursor (percentage filled) */
612     int          cursor_visible;/* cursor visibility flag */
613     int          pid;           /* pid of xterm (hack) */
614     char         title[0];      /* console title */
615 };
616
617
618 /* Add input records to a console input queue */
619 struct write_console_input_request
620 {
621     int          handle;        /* handle to the console input */
622     int          count;         /* number of input records */
623 /*  INPUT_RECORD records[0]; */ /* input records */
624 };
625 struct write_console_input_reply
626 {
627     int          written;       /* number of records written */
628 };
629
630 /* Fetch input records from a console input queue */
631 struct read_console_input_request
632 {
633     int          handle;        /* handle to the console input */
634     int          count;         /* max number of records to retrieve */
635     int          flush;         /* flush the retrieved records from the queue? */
636 };
637 struct read_console_input_reply
638 {
639     int dummy;
640 /*  INPUT_RECORD records[0]; */ /* input records */
641 };
642
643
644 /* Create a change notification */
645 struct create_change_notification_request
646 {
647     int          subtree;       /* watch all the subtree */
648     int          filter;        /* notification filter */
649 };
650 struct create_change_notification_reply
651 {
652     int          handle;        /* handle to the change notification */
653 };
654
655
656 /* Create a file mapping */
657 struct create_mapping_request
658 {
659     int          size_high;     /* mapping size */
660     int          size_low;      /* mapping size */
661     int          protect;       /* protection flags (see below) */
662     int          inherit;       /* inherit flag */
663     int          handle;        /* file handle */
664     char         name[0];       /* object name */
665 };
666 struct create_mapping_reply
667 {
668     int          handle;        /* handle to the mapping */
669 };
670 /* protection flags */
671 #define VPROT_READ       0x01
672 #define VPROT_WRITE      0x02
673 #define VPROT_EXEC       0x04
674 #define VPROT_WRITECOPY  0x08
675 #define VPROT_GUARD      0x10
676 #define VPROT_NOCACHE    0x20
677 #define VPROT_COMMITTED  0x40
678
679
680 /* Open a mapping */
681 struct open_mapping_request
682 {
683     unsigned int access;        /* wanted access rights */
684     int          inherit;       /* inherit flag */
685     char         name[0];       /* object name */
686 };
687 struct open_mapping_reply
688 {
689     int          handle;        /* handle to the mapping */
690 };
691
692
693 /* Get information about a file mapping */
694 struct get_mapping_info_request
695 {
696     int          handle;        /* handle to the mapping */
697 };
698 struct get_mapping_info_reply
699 {
700     int          size_high;     /* mapping size */
701     int          size_low;      /* mapping size */
702     int          protect;       /* protection flags */
703 };
704
705
706 /* Create a device */
707 struct create_device_request
708 {
709     unsigned int access;        /* wanted access rights */
710     int          inherit;       /* inherit flag */
711     int          id;            /* client private id */
712 };
713 struct create_device_reply
714 {
715     int          handle;        /* handle to the device */
716 };
717
718
719 /* Create a snapshot */
720 struct create_snapshot_request
721 {
722     int          inherit;       /* inherit flag */
723     int          flags;         /* snapshot flags (TH32CS_*) */
724 };
725 struct create_snapshot_reply
726 {
727     int          handle;        /* handle to the snapshot */
728 };
729
730
731 /* Get the next process from a snapshot */
732 struct next_process_request
733 {
734     int          handle;        /* handle to the snapshot */
735     int          reset;         /* reset snapshot position? */
736 };
737 struct next_process_reply
738 {
739     void*        pid;          /* process id */
740     int          threads;      /* number of threads */
741     int          priority;     /* process priority */
742 };
743
744
745 /* Wait for a debug event */
746 struct wait_debug_event_request
747 {
748     int          timeout;      /* timeout in ms */
749 };
750 struct wait_debug_event_reply
751 {
752     int          code;         /* event code */
753     void*        pid;          /* process id */
754     void*        tid;          /* thread id */
755     /* followed by the event data (see below) */
756 };
757
758
759 /* Send a debug event */
760 struct send_debug_event_request
761 {
762     int          code;         /* event code */
763     /* followed by the event data (see below) */
764 };
765 struct send_debug_event_reply
766 {
767     int          status;       /* event continuation status */
768 };
769
770
771 /* definitions of the event data depending on the event code */
772 struct debug_event_exception
773 {
774     int        code;           /* exception code */
775     int        flags;          /* exception flags */
776     void      *record;         /* exception record ptr */
777     void      *addr;           /* exception address */
778     int        nb_params;      /* exceptions parameters */
779     int        params[15];
780     int        first_chance;   /* first chance to handle it? */
781 };
782 struct debug_event_create_thread
783 {
784     int         handle;     /* handle to the new thread */
785     void       *teb;        /* thread teb (in debugged process address space) */
786     void       *start;      /* thread startup routine */
787 };
788 struct debug_event_create_process
789 {
790     int         file;       /* handle to the process exe file */
791     int         process;    /* handle to the new process */
792     int         thread;     /* handle to the new thread */
793     void       *base;       /* base of executable image */
794     int         dbg_offset; /* offset of debug info in file */
795     int         dbg_size;   /* size of debug info */
796     void       *teb;        /* thread teb (in debugged process address space) */
797     void       *start;      /* thread startup routine */
798     void       *name;       /* image name (optional) */
799     int         unicode;    /* is it Unicode? */
800 };
801 struct debug_event_exit
802 {
803     int         exit_code;  /* thread or process exit code */
804 };
805 struct debug_event_load_dll
806 {
807     int         handle;     /* file handle for the dll */
808     void       *base;       /* base address of the dll */
809     int         dbg_offset; /* offset of debug info in file */
810     int         dbg_size;   /* size of debug info */
811     void       *name;       /* image name (optional) */
812     int         unicode;    /* is it Unicode? */
813 };
814 struct debug_event_unload_dll
815 {
816     void       *base;       /* base address of the dll */
817 };
818 struct debug_event_output_string
819 {
820     void       *string;     /* string to display (in debugged process address space) */
821     int         unicode;    /* is it Unicode? */
822     int         length;     /* string length */
823 };
824 struct debug_event_rip_info
825 {
826     int         error;      /* ??? */
827     int         type;       /* ??? */
828 };
829 union debug_event_data
830 {
831     struct debug_event_exception      exception;
832     struct debug_event_create_thread  create_thread;
833     struct debug_event_create_process create_process;
834     struct debug_event_exit           exit;
835     struct debug_event_load_dll       load_dll;
836     struct debug_event_unload_dll     unload_dll;
837     struct debug_event_output_string  output_string;
838     struct debug_event_rip_info       rip_info;
839 };
840
841
842 /* Continue a debug event */
843 struct continue_debug_event_request
844 {
845     void*        pid;          /* process id to continue */
846     void*        tid;          /* thread id to continue */
847     int          status;       /* continuation status */
848 };
849
850
851 /* Start debugging an existing process */
852 struct debug_process_request
853 {
854     void*        pid;          /* id of the process to debug */
855 };
856
857
858 /* requests definitions */
859 #include "server/request.h"
860
861 /* client-side functions */
862
863 #ifndef __WINE_SERVER__
864
865 /* client communication functions */
866 extern void CLIENT_ProtocolError( const char *err, ... );
867 extern void CLIENT_SendRequest( enum request req, int pass_fd,
868                                 int n, ... /* arg_1, len_1, etc. */ );
869 extern unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
870                                       int n, ... /* arg_1, len_1, etc. */ );
871 extern unsigned int CLIENT_WaitSimpleReply( void *reply, int len, int *passed_fd );
872 extern int CLIENT_InitServer(void);
873 extern int CLIENT_SetDebug( int level );
874 extern int CLIENT_DebuggerRequest( int op );
875 extern int CLIENT_InitThread(void);
876 #endif  /* __WINE_SERVER__ */
877
878 #endif  /* __WINE_SERVER_H */