1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* File: ipc/ipc_object.h
* Author: Rich Draves
* Date: 1989
*
* Definitions for IPC objects, for which tasks have capabilities.
*/
#ifndef _IPC_IPC_OBJECT_H_
#define _IPC_IPC_OBJECT_H_
#include <mach/kern_return.h>
#include <mach/message.h>
#include <ipc/ipc_types.h>
#include <kern/lock.h>
#include <kern/macros.h>
#include <kern/slab.h>
typedef unsigned int ipc_object_refs_t;
typedef unsigned int ipc_object_bits_t;
typedef unsigned int ipc_object_type_t;
typedef struct ipc_object {
struct lock io_lock_data;
ipc_object_refs_t io_references;
ipc_object_bits_t io_bits;
} *ipc_object_t;
#define IO_NULL ((ipc_object_t) 0)
#define IO_DEAD ((ipc_object_t) -1)
#define IO_VALID(io) (((io) != IO_NULL) && ((io) != IO_DEAD))
#define IO_BITS_KOTYPE 0x0000ffff /* used by the object */
#define IO_BITS_OTYPE 0x3fff0000 /* determines a cache */
/* The following masks are used to store attributes of ipc ports. */
#define IO_BITS_PROTECTED_PAYLOAD 0x40000000 /* pp set? */
#define IO_BITS_ACTIVE 0x80000000U /* is object alive? */
#define io_active(io) ((int)(io)->io_bits < 0) /* hack */
#define io_otype(io) (((io)->io_bits & IO_BITS_OTYPE) >> 16)
#define io_kotype(io) ((io)->io_bits & IO_BITS_KOTYPE)
#define io_makebits(active, otype, kotype) \
(((active) ? IO_BITS_ACTIVE : 0) | ((otype) << 16) | (kotype))
/*
* Object types: ports, port sets, kernel-loaded ports
*/
#define IOT_PORT 0
#define IOT_PORT_SET 1
#define IOT_NUMBER 2 /* number of types used */
extern struct kmem_cache ipc_object_caches[IOT_NUMBER];
#define io_alloc(otype) \
((ipc_object_t) kmem_cache_alloc(&ipc_object_caches[(otype)]))
#define io_free(otype, io) \
kmem_cache_free(&ipc_object_caches[(otype)], (vm_offset_t) (io))
#define io_lock_init(io) lock_init(&(io)->io_lock_data, TRUE)
#define io_lock(io) lock_write(&(io)->io_lock_data)
#define io_lock_try(io) lock_try_write(&(io)->io_lock_data)
#define io_unlock(io) lock_write_done(&(io)->io_lock_data)
#define io_check_unlock(io) \
MACRO_BEGIN \
ipc_object_refs_t _refs = (io)->io_references; \
\
io_unlock(io); \
if (_refs == 0) \
io_free(io_otype(io), io); \
MACRO_END
#define io_reference(io) \
MACRO_BEGIN \
(io)->io_references++; \
MACRO_END
#define io_release(io) \
MACRO_BEGIN \
(io)->io_references--; \
MACRO_END
extern void
ipc_object_reference(ipc_object_t);
extern void
ipc_object_release(ipc_object_t);
extern kern_return_t
ipc_object_translate(ipc_space_t, mach_port_t,
mach_port_right_t, ipc_object_t *);
extern kern_return_t
ipc_object_alloc_dead(ipc_space_t, mach_port_t *);
extern kern_return_t
ipc_object_alloc_dead_name(ipc_space_t, mach_port_t);
extern kern_return_t
ipc_object_alloc(ipc_space_t, ipc_object_type_t,
mach_port_type_t, mach_port_urefs_t,
mach_port_t *, ipc_object_t *);
extern kern_return_t
ipc_object_alloc_name(ipc_space_t, ipc_object_type_t,
mach_port_type_t, mach_port_urefs_t,
mach_port_t, ipc_object_t *);
extern mach_msg_type_name_t
ipc_object_copyin_type(mach_msg_type_name_t);
extern kern_return_t
ipc_object_copyin(ipc_space_t, mach_port_t,
mach_msg_type_name_t, ipc_object_t *);
extern void
ipc_object_copyin_from_kernel(ipc_object_t, mach_msg_type_name_t);
extern void
ipc_object_destroy(ipc_object_t, mach_msg_type_name_t);
extern kern_return_t
ipc_object_copyout(ipc_space_t, ipc_object_t,
mach_msg_type_name_t, boolean_t, mach_port_t *);
extern kern_return_t
ipc_object_copyout_name(ipc_space_t, ipc_object_t,
mach_msg_type_name_t, boolean_t, mach_port_t);
extern void
ipc_object_copyout_dest(ipc_space_t, ipc_object_t,
mach_msg_type_name_t, mach_port_t *);
extern kern_return_t
ipc_object_rename(ipc_space_t, mach_port_t, mach_port_t);
extern void
ipc_object_print(ipc_object_t);
#endif /* _IPC_IPC_OBJECT_H_ */
|