]>
Commit | Line | Data |
---|---|---|
9385eb3d A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
59e0d9fe A |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
7 | * | |
9385eb3d A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
e9ce8d39 A |
25 | /* |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | ||
29 | /* | |
30 | * Define a service to map from a kernel-generated port name | |
31 | * to server-defined "type" and "value" data to be associated | |
32 | * with the port. | |
33 | */ | |
34 | ||
35 | #ifndef PORT_OBJ_H | |
36 | #define PORT_OBJ_H | |
37 | ||
38 | #include <mach/port.h> | |
39 | ||
40 | struct port_obj_tentry { | |
41 | void *pos_value; | |
42 | int pos_type; | |
43 | }; | |
44 | ||
9385eb3d A |
45 | #include <sys/cdefs.h> |
46 | ||
47 | __BEGIN_DECLS | |
e9ce8d39 A |
48 | extern void port_obj_init(int); |
49 | extern struct port_obj_tentry *port_obj_table; | |
50 | extern int port_obj_table_size; | |
9385eb3d | 51 | __END_DECLS |
e9ce8d39 A |
52 | |
53 | #ifndef PORT_OBJ_ASSERT | |
54 | ||
55 | #define port_set_obj_value_type(pname, value, type) \ | |
56 | do { \ | |
57 | int ndx; \ | |
58 | \ | |
59 | if (!port_obj_table) \ | |
60 | port_obj_init(port_obj_table_size); \ | |
61 | ndx = MACH_PORT_INDEX(pname); \ | |
62 | port_obj_table[ndx].pos_value = (value); \ | |
63 | port_obj_table[ndx].pos_type = (type); \ | |
64 | } while (0) | |
65 | ||
66 | #define port_get_obj_value(pname) \ | |
67 | (port_obj_table[MACH_PORT_INDEX(pname)].pos_value) | |
68 | ||
69 | #define port_get_obj_type(pname) \ | |
70 | (port_obj_table[MACH_PORT_INDEX(pname)].pos_type) | |
71 | ||
72 | #else /* PORT_OBJ_ASSERT */ | |
73 | ||
74 | #define port_set_obj_value_type(pname, value, type) \ | |
75 | do { \ | |
76 | int ndx; \ | |
77 | \ | |
78 | if (!port_obj_table) \ | |
79 | port_obj_init(port_obj_table_size); \ | |
80 | ndx = MACH_PORT_INDEX(pname); \ | |
81 | assert(ndx > 0); \ | |
82 | assert(ndx < port_obj_table_size); \ | |
83 | port_obj_table[ndx].pos_value = (value); \ | |
84 | port_obj_table[ndx].pos_type = (type); \ | |
85 | } while (0) | |
86 | ||
87 | #define port_get_obj_value(pname) \ | |
88 | ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ | |
89 | port_obj_table[MACH_PORT_INDEX(pname)].pos_value : \ | |
90 | (panic("port_get_obj_value: index too big"), (void *)-1)) | |
91 | ||
92 | #define port_get_obj_type(pname) \ | |
93 | ((MACH_PORT_INDEX(pname) < (unsigned)port_obj_table_size) ? \ | |
94 | port_obj_table[MACH_PORT_INDEX(pname)].pos_type : \ | |
95 | (panic("port_get_obj_type: index too big"), -1)) | |
96 | ||
97 | #endif /* PORT_OBJ_ASSERT */ | |
98 | ||
99 | #endif /* PORT_OBJ_H */ |