Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 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> |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 15 | #include "server.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 16 | |
Alexandre Julliard | 1bdd154 | 1999-06-04 19:47:04 +0000 | [diff] [blame] | 17 | #define DEBUG_OBJECTS |
| 18 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 19 | /* kernel objects */ |
| 20 | |
| 21 | struct object; |
| 22 | struct object_name; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 23 | struct thread; |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 24 | struct process; |
Alexandre Julliard | a8b8d9c | 1999-01-01 16:59:27 +0000 | [diff] [blame] | 25 | struct file; |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 26 | struct wait_queue_entry; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 28 | /* operations valid on all objects */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 29 | struct object_ops |
| 30 | { |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 31 | /* size of this object type */ |
| 32 | size_t size; |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 33 | /* dump the object (for debugging) */ |
| 34 | void (*dump)(struct object *,int); |
| 35 | /* add a thread to the object wait queue */ |
Alexandre Julliard | a8b8d9c | 1999-01-01 16:59:27 +0000 | [diff] [blame] | 36 | int (*add_queue)(struct object *,struct wait_queue_entry *); |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 37 | /* remove a thread from the object wait queue */ |
| 38 | void (*remove_queue)(struct object *,struct wait_queue_entry *); |
| 39 | /* is object signaled? */ |
| 40 | int (*signaled)(struct object *,struct thread *); |
| 41 | /* wait satisfied; return 1 if abandoned */ |
| 42 | int (*satisfied)(struct object *,struct thread *); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 43 | /* return a Unix fd that can be used to read from the object */ |
| 44 | int (*get_read_fd)(struct object *); |
| 45 | /* return a Unix fd that can be used to write to the object */ |
| 46 | int (*get_write_fd)(struct object *); |
| 47 | /* flush the object buffers */ |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 48 | int (*flush)(struct object *); |
| 49 | /* get file information */ |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 50 | int (*get_file_info)(struct object *,struct get_file_info_request *); |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 51 | /* destroy on refcount == 0 */ |
| 52 | void (*destroy)(struct object *); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct object |
| 56 | { |
| 57 | unsigned int refcount; |
| 58 | const struct object_ops *ops; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 59 | struct wait_queue_entry *head; |
| 60 | struct wait_queue_entry *tail; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 61 | struct object_name *name; |
Alexandre Julliard | 1bdd154 | 1999-06-04 19:47:04 +0000 | [diff] [blame] | 62 | #ifdef DEBUG_OBJECTS |
| 63 | struct object *prev; |
| 64 | struct object *next; |
| 65 | #endif |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 68 | extern void *mem_alloc( size_t size ); /* malloc wrapper */ |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 69 | extern char *mem_strdup( const char *str ); |
| 70 | extern void *alloc_object( const struct object_ops *ops ); |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 71 | extern const char *get_object_name( struct object *obj ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 72 | extern void *create_named_object( const struct object_ops *ops, const char *name, size_t len ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 77 | extern struct object *find_object( const char *name, size_t len ); |
Alexandre Julliard | a8b8d9c | 1999-01-01 16:59:27 +0000 | [diff] [blame] | 78 | extern int no_add_queue( struct object *obj, struct wait_queue_entry *entry ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 83 | extern int no_get_file_info( struct object *obj, struct get_file_info_request *info ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 84 | extern void no_destroy( struct object *obj ); |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 85 | extern void default_select_event( int event, void *private ); |
Alexandre Julliard | 1bdd154 | 1999-06-04 19:47:04 +0000 | [diff] [blame] | 86 | #ifdef DEBUG_OBJECTS |
| 87 | extern void dump_objects(void); |
| 88 | #endif |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 89 | |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 90 | /* select functions */ |
| 91 | |
| 92 | #define READ_EVENT 1 |
| 93 | #define WRITE_EVENT 2 |
| 94 | |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 95 | struct select_user |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 96 | { |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 97 | int fd; /* user fd */ |
| 98 | void (*func)(int event, void *private); /* callback function */ |
| 99 | void *private; /* callback private data */ |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 102 | extern void register_select_user( struct select_user *user ); |
| 103 | extern void unregister_select_user( struct select_user *user ); |
| 104 | extern void set_select_events( struct select_user *user, int events ); |
| 105 | extern int check_select_events( struct select_user *user, int events ); |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 106 | extern void select_loop(void); |
| 107 | |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 108 | /* timeout functions */ |
| 109 | |
| 110 | struct timeout_user; |
| 111 | |
| 112 | typedef void (*timeout_callback)( void *private ); |
| 113 | |
| 114 | extern struct timeout_user *add_timeout_user( struct timeval *when, |
| 115 | timeout_callback func, void *private ); |
| 116 | extern void remove_timeout_user( struct timeout_user *user ); |
| 117 | extern void make_timeout( struct timeval *when, int timeout ); |
| 118 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 119 | /* socket functions */ |
| 120 | |
Alexandre Julliard | 88de35c | 1999-05-16 16:57:49 +0000 | [diff] [blame] | 121 | struct client; |
| 122 | |
| 123 | extern struct client *add_client( int client_fd, struct thread *self ); |
| 124 | extern void remove_client( struct client *client, int exit_code ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 125 | extern void client_pass_fd( struct client *client, int pass_fd ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 126 | extern void client_reply( struct client *client, unsigned int res ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 127 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 128 | /* mutex functions */ |
| 129 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 130 | extern void abandon_mutexes( struct thread *thread ); |
| 131 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 132 | /* file functions */ |
| 133 | |
Alexandre Julliard | a8b8d9c | 1999-01-01 16:59:27 +0000 | [diff] [blame] | 134 | extern struct file *get_file_obj( struct process *process, int handle, |
| 135 | unsigned int access ); |
| 136 | extern int file_get_mmap_fd( struct file *file ); |
Alexandre Julliard | cb28bdc | 1999-02-28 10:13:59 +0000 | [diff] [blame] | 137 | extern int grow_file( struct file *file, int size_high, int size_low ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 138 | extern int create_anonymous_file(void); |
Alexandre Julliard | cb28bdc | 1999-02-28 10:13:59 +0000 | [diff] [blame] | 139 | extern struct file *create_temp_file( int access ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 140 | extern void file_set_error(void); |
| 141 | |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 142 | /* console functions */ |
| 143 | |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 144 | extern int alloc_console( struct process *process ); |
| 145 | extern int free_console( struct process *process ); |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 146 | |
Alexandre Julliard | e712e07 | 1999-05-23 19:53:30 +0000 | [diff] [blame] | 147 | /* debugger functions */ |
| 148 | |
| 149 | extern int debugger_attach( struct process *process, struct thread *debugger ); |
| 150 | extern void debug_exit_thread( struct thread *thread, int exit_code ); |
| 151 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 152 | extern int debug_level; |
| 153 | |
| 154 | #endif /* __WINE_SERVER_OBJECT_H */ |