Added DebugBreak.
[wine] / server / object.h
1 /*
2  * Wine server objects
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_SERVER_OBJECT_H
8 #define __WINE_SERVER_OBJECT_H
9
10 #ifndef __WINE_SERVER__
11 #error This file can only be used in the Wine server
12 #endif
13
14 #include <sys/time.h>
15 #include "server.h"
16 #include "server/request.h"
17
18 #define DEBUG_OBJECTS
19
20 /* kernel objects */
21
22 struct object;
23 struct object_name;
24 struct thread;
25 struct process;
26 struct file;
27 struct wait_queue_entry;
28
29 /* operations valid on all objects */
30 struct object_ops
31 {
32     /* dump the object (for debugging) */
33     void (*dump)(struct object *,int);
34     /* add a thread to the object wait queue */
35     int  (*add_queue)(struct object *,struct wait_queue_entry *);
36     /* remove a thread from the object wait queue */
37     void (*remove_queue)(struct object *,struct wait_queue_entry *);
38     /* is object signaled? */
39     int  (*signaled)(struct object *,struct thread *);
40     /* wait satisfied; return 1 if abandoned */
41     int  (*satisfied)(struct object *,struct thread *);
42     /* return a Unix fd that can be used to read from the object */
43     int  (*get_read_fd)(struct object *);
44     /* return a Unix fd that can be used to write to the object */
45     int  (*get_write_fd)(struct object *);
46     /* flush the object buffers */
47     int  (*flush)(struct object *);
48     /* get file information */
49     int  (*get_file_info)(struct object *,struct get_file_info_reply *);
50     /* destroy on refcount == 0 */
51     void (*destroy)(struct object *);
52 };
53
54 struct object
55 {
56     unsigned int              refcount;
57     const struct object_ops  *ops;
58     struct wait_queue_entry  *head;
59     struct wait_queue_entry  *tail;
60     struct object_name       *name;
61 #ifdef DEBUG_OBJECTS
62     struct object            *prev;
63     struct object            *next;
64 #endif
65 };
66
67 extern void *mem_alloc( size_t size );  /* malloc wrapper */
68 extern void *alloc_object( size_t size, const struct object_ops *ops, const char *name );
69 extern struct object *create_named_object( const char *name, const struct object_ops *ops,
70                                            size_t size );
71 extern int init_object( struct object *obj, const struct object_ops *ops, const char *name );
72 extern const char *get_object_name( struct object *obj );
73 /* grab/release_object can take any pointer, but you better make sure */
74 /* that the thing pointed to starts with a struct object... */
75 extern struct object *grab_object( void *obj );
76 extern void release_object( void *obj );
77 extern struct object *find_object( const char *name );
78 extern int no_add_queue( struct object *obj, struct wait_queue_entry *entry );
79 extern int no_satisfied( struct object *obj, struct thread *thread );
80 extern int no_read_fd( struct object *obj );
81 extern int no_write_fd( struct object *obj );
82 extern int no_flush( struct object *obj );
83 extern int no_get_file_info( struct object *obj, struct get_file_info_reply *info );
84 extern void default_select_event( int event, void *private );
85 #ifdef DEBUG_OBJECTS
86 extern void dump_objects(void);
87 #endif
88
89 /* request handlers */
90
91 struct iovec;
92 struct thread;
93
94 extern void fatal_protocol_error( const char *err, ... );
95 extern void call_req_handler( struct thread *thread, enum request req,
96                               void *data, int len, int fd );
97 extern void call_timeout_handler( void *thread );
98 extern void call_kill_handler( struct thread *thread, int exit_code );
99
100 extern void trace_request( enum request req, void *data, int len, int fd );
101 extern void trace_timeout(void);
102 extern void trace_kill( int exit_code );
103 extern void trace_reply( struct thread *thread, int type, int pass_fd,
104                          struct iovec *vec, int veclen );
105 /* check that the string is NULL-terminated and that the len is correct */
106 #define CHECK_STRING(func,str,len) \
107   do { if (((str)[(len)-1] || strlen(str) != (len)-1)) \
108          fatal_protocol_error( "%s: invalid string '%.*s'\n", (func), (len), (str) ); \
109      } while(0)
110
111 /* select functions */
112
113 #define READ_EVENT    1
114 #define WRITE_EVENT   2
115
116 struct select_user
117 {
118     int    fd;                              /* user fd */
119     void (*func)(int event, void *private); /* callback function */
120     void  *private;                         /* callback private data */
121 };
122
123 extern void register_select_user( struct select_user *user );
124 extern void unregister_select_user( struct select_user *user );
125 extern void set_select_events( struct select_user *user, int events );
126 extern int check_select_events( struct select_user *user, int events );
127 extern void select_loop(void);
128
129 /* timeout functions */
130
131 struct timeout_user;
132
133 typedef void (*timeout_callback)( void *private );
134
135 extern struct timeout_user *add_timeout_user( struct timeval *when,
136                                               timeout_callback func, void *private );
137 extern void remove_timeout_user( struct timeout_user *user );
138 extern void make_timeout( struct timeval *when, int timeout );
139
140 /* socket functions */
141
142 struct client;
143
144 extern struct client *add_client( int client_fd, struct thread *self );
145 extern void remove_client( struct client *client, int exit_code );
146 extern int send_reply_v( struct client *client, int type, int pass_fd,
147                          struct iovec *vec, int veclen );
148
149 /* mutex functions */
150
151 extern void abandon_mutexes( struct thread *thread );
152
153 /* file functions */
154
155 extern struct file *get_file_obj( struct process *process, int handle,
156                                   unsigned int access );
157 extern int file_get_mmap_fd( struct file *file );
158 extern int grow_file( struct file *file, int size_high, int size_low );
159 extern struct file *create_temp_file( int access );
160 extern void file_set_error(void);
161
162 /* console functions */
163
164 extern int alloc_console( struct process *process );
165 extern int free_console( struct process *process );
166
167 /* debugger functions */
168
169 extern int debugger_attach( struct process *process, struct thread *debugger );
170 extern void debug_exit_thread( struct thread *thread, int exit_code );
171
172 extern int debug_level;
173
174 #endif  /* __WINE_SERVER_OBJECT_H */