source: rtems/cpukit/include/rtems/posix/shm.h @ 21275b58

5
Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/18 at 18:14:51

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 5.4 KB
Line 
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/objectdata.h>
19#include <rtems/score/threadq.h>
20
21#include <sys/types.h>
22
23#ifdef __cplusplus
24extern "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 */
35typedef struct POSIX_Shm_Object_operations POSIX_Shm_Object_operations;
36extern const POSIX_Shm_Object_operations _POSIX_Shm_Object_operations;
37
38/**
39 * @brief Encapsulation for the storage and manipulation of shm objects.
40 */
41typedef 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 */
62struct 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 */
111typedef 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/**
130 * @brief The POSIX Shared Memory objects information.
131 */
132extern Objects_Information _POSIX_Shm_Information;
133
134/**
135 * @brief Macro to define the objects information for the POSIX Shared Memory
136 * objects.
137 *
138 * This macro should only be used by <rtems/confdefs.h>.
139 *
140 * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag
141 * may be set).
142 */
143#define POSIX_SHM_INFORMATION_DEFINE( max ) \
144  OBJECTS_INFORMATION_DEFINE( \
145    _POSIX_Shm, \
146    OBJECTS_POSIX_API, \
147    OBJECTS_POSIX_SHMS, \
148    POSIX_Shm_Control, \
149    max, \
150    _POSIX_PATH_MAX, \
151    NULL \
152  )
153
154/**
155 * @brief object_create operation for shm objects stored in RTEMS Workspace.
156 */
157extern int _POSIX_Shm_Object_create_from_workspace(
158  POSIX_Shm_Object *shm_obj,
159  size_t size
160);
161
162/**
163 * @brief object_delete operation for shm objects stored in RTEMS Workspace.
164 */
165extern int _POSIX_Shm_Object_delete_from_workspace( POSIX_Shm_Object *shm_obj );
166
167/**
168 * @brief object_resize operation for shm objects stored in RTEMS Workspace.
169 */
170extern int _POSIX_Shm_Object_resize_from_workspace(
171  POSIX_Shm_Object *shm_obj,
172  size_t size
173);
174
175/**
176 * @brief object_read operation for shm objects stored in RTEMS Workspace.
177 */
178extern int _POSIX_Shm_Object_read_from_workspace(
179  POSIX_Shm_Object *shm_obj,
180  void *buf,
181  size_t count
182);
183
184/**
185 * @brief object_mmap operation for shm objects stored in RTEMS Workspace.
186 */
187extern void * _POSIX_Shm_Object_mmap_from_workspace(
188  POSIX_Shm_Object *shm_obj,
189  size_t len,
190  int prot,
191  off_t off
192);
193
194/**
195 * @brief object_create operation for shm objects stored in C program heap.
196 */
197extern int _POSIX_Shm_Object_create_from_heap(
198  POSIX_Shm_Object *shm_obj,
199  size_t size
200);
201
202/**
203 * @brief object_delete operation for shm objects stored in C program heap.
204 */
205extern int _POSIX_Shm_Object_delete_from_heap( POSIX_Shm_Object *shm_obj );
206
207/**
208 * @brief object_resize operation for shm objects stored in C program heap.
209 */
210extern int _POSIX_Shm_Object_resize_from_heap(
211  POSIX_Shm_Object *shm_obj,
212  size_t size
213);
214
215/**
216 * @brief object_read operation for shm objects stored in C program heap.
217 */
218extern int _POSIX_Shm_Object_read_from_heap(
219  POSIX_Shm_Object *shm_obj,
220  void *buf,
221  size_t count
222);
223
224/**
225 * @brief object_mmap operation for shm objects stored in C program heap.
226 */
227extern void * _POSIX_Shm_Object_mmap_from_heap(
228  POSIX_Shm_Object *shm_obj,
229  size_t len,
230  int prot,
231  off_t off
232);
233
234/** @} */
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif
Note: See TracBrowser for help on using the repository browser.