1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Internal Support for POSIX Shared Memory |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Copyright (c) 2016 Gedare Bloom. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef _RTEMS_POSIX_SHM_H |
---|
16 | #define _RTEMS_POSIX_SHM_H |
---|
17 | |
---|
18 | #include <rtems/score/object.h> |
---|
19 | #include <rtems/score/threadq.h> |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif |
---|
26 | |
---|
27 | /** |
---|
28 | * @defgroup POSIXShmPrivate POSIX Shared Memory Private Support |
---|
29 | * |
---|
30 | * @ingroup POSIXAPI |
---|
31 | * |
---|
32 | * Internal implementation support for POSIX shared memory. |
---|
33 | * @{ |
---|
34 | */ |
---|
35 | typedef struct POSIX_Shm_Object_operations POSIX_Shm_Object_operations; |
---|
36 | extern const POSIX_Shm_Object_operations _POSIX_Shm_Object_operations; |
---|
37 | |
---|
38 | /** |
---|
39 | * @brief Encapsulation for the storage and manipulation of shm objects. |
---|
40 | */ |
---|
41 | typedef struct { |
---|
42 | /** |
---|
43 | * @brief The handle is private for finding object storage. |
---|
44 | */ |
---|
45 | void *handle; |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief The number of bytes allocated to the object. A size of 0 with |
---|
49 | * a handle of NULL means no object is allocated. |
---|
50 | */ |
---|
51 | size_t size; |
---|
52 | |
---|
53 | /** |
---|
54 | * @brief Implementation-specific operations on shm objects. |
---|
55 | */ |
---|
56 | const POSIX_Shm_Object_operations *ops; |
---|
57 | } POSIX_Shm_Object; |
---|
58 | |
---|
59 | /** |
---|
60 | * @brief Operations on POSIX Shared Memory Objects. |
---|
61 | */ |
---|
62 | struct POSIX_Shm_Object_operations { |
---|
63 | /** |
---|
64 | * @brief Allocates a new @a shm_obj with initial @a size. |
---|
65 | * |
---|
66 | * New shared memory is initialized to zeroes. |
---|
67 | * |
---|
68 | * Returns 0 for success. |
---|
69 | */ |
---|
70 | int ( *object_create ) ( POSIX_Shm_Object *shm_obj, size_t size ); |
---|
71 | |
---|
72 | /** |
---|
73 | * @brief Changes the @a shm_obj size to @a size. |
---|
74 | * |
---|
75 | * Zeroes out the portion of the shared memory object that shrinks or grows. |
---|
76 | * |
---|
77 | * Returns 0 for success. |
---|
78 | */ |
---|
79 | int ( *object_resize ) ( POSIX_Shm_Object *shm_obj, size_t size ); |
---|
80 | |
---|
81 | /** |
---|
82 | * @brief Deletes the @a shm_obj. |
---|
83 | * |
---|
84 | * Zeroes out the memory. |
---|
85 | * |
---|
86 | * Returns 0 for success. |
---|
87 | */ |
---|
88 | int ( *object_delete ) ( POSIX_Shm_Object *shm_obj ); |
---|
89 | |
---|
90 | /** |
---|
91 | * @brief Copies up to @count bytes of the @a shm_obj data into @a buf. |
---|
92 | * |
---|
93 | * Returns the number of bytes read (copied) into @a buf. |
---|
94 | */ |
---|
95 | int ( *object_read ) ( POSIX_Shm_Object *shm_obj, void *buf, size_t count ); |
---|
96 | |
---|
97 | /** |
---|
98 | * @brief Maps a shared memory object. |
---|
99 | * |
---|
100 | * Establishes a memory mapping between the shared memory object and the |
---|
101 | * caller. |
---|
102 | * |
---|
103 | * Returns the mapped address of the object. |
---|
104 | */ |
---|
105 | void * ( *object_mmap ) ( POSIX_Shm_Object *shm_obj, size_t len, int prot, off_t off); |
---|
106 | }; |
---|
107 | |
---|
108 | /** |
---|
109 | * @brief Control for a POSIX Shared Memory Object |
---|
110 | */ |
---|
111 | typedef struct { |
---|
112 | Objects_Control Object; |
---|
113 | Thread_queue_Control Wait_queue; |
---|
114 | |
---|
115 | int reference_count; |
---|
116 | |
---|
117 | POSIX_Shm_Object shm_object; |
---|
118 | |
---|
119 | uid_t uid; |
---|
120 | gid_t gid; |
---|
121 | mode_t mode; |
---|
122 | int oflag; |
---|
123 | |
---|
124 | time_t atime; |
---|
125 | time_t mtime; |
---|
126 | time_t ctime; |
---|
127 | } POSIX_Shm_Control; |
---|
128 | |
---|
129 | extern const uint32_t _Configuration_POSIX_Maximum_shms; |
---|
130 | |
---|
131 | /** |
---|
132 | * @brief object_create operation for shm objects stored in RTEMS Workspace. |
---|
133 | */ |
---|
134 | extern int _POSIX_Shm_Object_create_from_workspace( |
---|
135 | POSIX_Shm_Object *shm_obj, |
---|
136 | size_t size |
---|
137 | ); |
---|
138 | |
---|
139 | /** |
---|
140 | * @brief object_delete operation for shm objects stored in RTEMS Workspace. |
---|
141 | */ |
---|
142 | extern int _POSIX_Shm_Object_delete_from_workspace( POSIX_Shm_Object *shm_obj ); |
---|
143 | |
---|
144 | /** |
---|
145 | * @brief object_resize operation for shm objects stored in RTEMS Workspace. |
---|
146 | */ |
---|
147 | extern int _POSIX_Shm_Object_resize_from_workspace( |
---|
148 | POSIX_Shm_Object *shm_obj, |
---|
149 | size_t size |
---|
150 | ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief object_read operation for shm objects stored in RTEMS Workspace. |
---|
154 | */ |
---|
155 | extern int _POSIX_Shm_Object_read_from_workspace( |
---|
156 | POSIX_Shm_Object *shm_obj, |
---|
157 | void *buf, |
---|
158 | size_t count |
---|
159 | ); |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief object_mmap operation for shm objects stored in RTEMS Workspace. |
---|
163 | */ |
---|
164 | extern void * _POSIX_Shm_Object_mmap_from_workspace( |
---|
165 | POSIX_Shm_Object *shm_obj, |
---|
166 | size_t len, |
---|
167 | int prot, |
---|
168 | off_t off |
---|
169 | ); |
---|
170 | |
---|
171 | /** |
---|
172 | * @brief object_create operation for shm objects stored in C program heap. |
---|
173 | */ |
---|
174 | extern int _POSIX_Shm_Object_create_from_heap( |
---|
175 | POSIX_Shm_Object *shm_obj, |
---|
176 | size_t size |
---|
177 | ); |
---|
178 | |
---|
179 | /** |
---|
180 | * @brief object_delete operation for shm objects stored in C program heap. |
---|
181 | */ |
---|
182 | extern int _POSIX_Shm_Object_delete_from_heap( POSIX_Shm_Object *shm_obj ); |
---|
183 | |
---|
184 | /** |
---|
185 | * @brief object_resize operation for shm objects stored in C program heap. |
---|
186 | */ |
---|
187 | extern int _POSIX_Shm_Object_resize_from_heap( |
---|
188 | POSIX_Shm_Object *shm_obj, |
---|
189 | size_t size |
---|
190 | ); |
---|
191 | |
---|
192 | /** |
---|
193 | * @brief object_read operation for shm objects stored in C program heap. |
---|
194 | */ |
---|
195 | extern int _POSIX_Shm_Object_read_from_heap( |
---|
196 | POSIX_Shm_Object *shm_obj, |
---|
197 | void *buf, |
---|
198 | size_t count |
---|
199 | ); |
---|
200 | |
---|
201 | /** |
---|
202 | * @brief object_mmap operation for shm objects stored in C program heap. |
---|
203 | */ |
---|
204 | extern void * _POSIX_Shm_Object_mmap_from_heap( |
---|
205 | POSIX_Shm_Object *shm_obj, |
---|
206 | size_t len, |
---|
207 | int prot, |
---|
208 | off_t off |
---|
209 | ); |
---|
210 | |
---|
211 | /** @} */ |
---|
212 | |
---|
213 | #ifdef __cplusplus |
---|
214 | } |
---|
215 | #endif |
---|
216 | |
---|
217 | #endif |
---|