source: rtems/cpukit/posix/include/rtems/posix/shm.h @ 87de70a2

5
Last change on this file since 87de70a2 was 87de70a2, checked in by Gedare Bloom <gedare@…>, on 03/15/17 at 18:31:00

posix/mman: add mmap support for shm objects

Update #2859.

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