]> git.saurik.com Git - apple/libc.git/blob - mach.subproj/headers.subproj/port_obj.h
Libc-186.tar.gz
[apple/libc.git] / mach.subproj / headers.subproj / port_obj.h
1 /*
2 * @OSF_COPYRIGHT@
3 */
4
5 /*
6 * Define a service to map from a kernel-generated port name
7 * to server-defined "type" and "value" data to be associated
8 * with the port.
9 */
10
11 #ifndef PORT_OBJ_H
12 #define PORT_OBJ_H
13
14 #include <mach/port.h>
15
16 struct port_obj_tentry {
17 void *pos_value;
18 int pos_type;
19 };
20
21 extern void port_obj_init(int);
22 extern struct port_obj_tentry *port_obj_table;
23 extern int port_obj_table_size;
24
25 #ifndef PORT_OBJ_ASSERT
26
27 #define port_set_obj_value_type(pname, value, type) \
28 do { \
29 int ndx; \
30 \
31 if (!port_obj_table) \
32 port_obj_init(port_obj_table_size); \
33 ndx = MACH_PORT_INDEX(pname); \
34 port_obj_table[ndx].pos_value = (value); \
35 port_obj_table[ndx].pos_type = (type); \
36 } while (0)
37
38 #define port_get_obj_value(pname) \
39 (port_obj_table[MACH_PORT_INDEX(pname)].pos_value)
40
41 #define port_get_obj_type(pname) \
42 (port_obj_table[MACH_PORT_INDEX(pname)].pos_type)
43
44 #else /* PORT_OBJ_ASSERT */
45
46 #define port_set_obj_value_type(pname, value, type) \
47 do { \
48 int ndx; \
49 \
50 if (!port_obj_table) \
51 port_obj_init(port_obj_table_size); \
52 ndx = MACH_PORT_INDEX(pname); \
53 assert(ndx > 0); \
54 assert(ndx < port_obj_table_size); \
55 port_obj_table[ndx].pos_value = (value); \
56 port_obj_table[ndx].pos_type = (type); \
57 } while (0)
58
59 #define port_get_obj_value(pname) \
60 ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \
61 port_obj_table[MACH_PORT_INDEX(pname)].pos_value : \
62 (panic("port_get_obj_value: index too big"), (void *)-1))
63
64 #define port_get_obj_type(pname) \
65 ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \
66 port_obj_table[MACH_PORT_INDEX(pname)].pos_type : \
67 (panic("port_get_obj_type: index too big"), -1))
68
69 #endif /* PORT_OBJ_ASSERT */
70
71 #endif /* PORT_OBJ_H */