1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1999-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | ** prshm.h -- NSPR Shared Memory
|
---|
40 | **
|
---|
41 | ** NSPR Named Shared Memory API provides a cross-platform named
|
---|
42 | ** shared-memory interface. NSPR Named Shared Memory is modeled on
|
---|
43 | ** similar constructs in Unix and Windows operating systems. Shared
|
---|
44 | ** memory allows multiple processes to access one or more common shared
|
---|
45 | ** memory regions, using it as an inter-process communication channel.
|
---|
46 | **
|
---|
47 | ** Notes on Platform Independence:
|
---|
48 | ** NSPR Named Shared Memory is built on the native services offered
|
---|
49 | ** by most platforms. The NSPR Named Shared Memory API tries to
|
---|
50 | ** provide a least common denominator interface so that it works
|
---|
51 | ** across all supported platforms. To ensure that it works everywhere,
|
---|
52 | ** some platform considerations must be accomodated and the protocol
|
---|
53 | ** for using NSPR Shared Memory API must be observed.
|
---|
54 | **
|
---|
55 | ** Protocol:
|
---|
56 | ** Multiple shared memories can be created using NSPR's Shared Memory
|
---|
57 | ** feature. For each named shared memory, as defined by the name
|
---|
58 | ** given in the PR_OpenSharedMemory() call, a protocol for using the
|
---|
59 | ** shared memory API is required to ensure desired behavior. Failing
|
---|
60 | ** to follow the protocol may yield unpredictable results.
|
---|
61 | **
|
---|
62 | ** PR_OpenSharedMemory() will create the shared memory segment, if it
|
---|
63 | ** does not already exist, or open a connection that the existing
|
---|
64 | ** shared memory segment if it already exists.
|
---|
65 | **
|
---|
66 | ** PR_AttachSharedMemory() should be called following
|
---|
67 | ** PR_OpenSharedMemory() to map the memory segment to an address in
|
---|
68 | ** the application's address space.
|
---|
69 | **
|
---|
70 | ** PR_AttachSharedMemory() may be called to re-map a shared memory
|
---|
71 | ** segment after detaching the same PRSharedMemory object. Be
|
---|
72 | ** sure to detach it when done.
|
---|
73 | **
|
---|
74 | ** PR_DetachSharedMemory() should be called to un-map the shared
|
---|
75 | ** memory segment from the application's address space.
|
---|
76 | **
|
---|
77 | ** PR_CloseSharedMemory() should be called when no further use of the
|
---|
78 | ** PRSharedMemory object is required within a process. Following a
|
---|
79 | ** call to PR_CloseSharedMemory() the PRSharedMemory object is
|
---|
80 | ** invalid and cannot be reused.
|
---|
81 | **
|
---|
82 | ** PR_DeleteSharedMemory() should be called before process
|
---|
83 | ** termination. After calling PR_DeleteSharedMemory() any further use
|
---|
84 | ** of the shared memory associated with the name may cause
|
---|
85 | ** unpredictable results.
|
---|
86 | **
|
---|
87 | ** Files:
|
---|
88 | ** The name passed to PR_OpenSharedMemory() should be a valid filename
|
---|
89 | ** for a unix platform. PR_OpenSharedMemory() creates file using the
|
---|
90 | ** name passed in. Some platforms may mangle the name before creating
|
---|
91 | ** the file and the shared memory.
|
---|
92 | **
|
---|
93 | ** The unix implementation may use SysV IPC shared memory, Posix
|
---|
94 | ** shared memory, or memory mapped files; the filename may used to
|
---|
95 | ** define the namespace. On Windows, the name is significant, but
|
---|
96 | ** there is no file associated with name.
|
---|
97 | **
|
---|
98 | ** No assumptions about the persistence of data in the named file
|
---|
99 | ** should be made. Depending on platform, the shared memory may be
|
---|
100 | ** mapped onto system paging space and be discarded at process
|
---|
101 | ** termination.
|
---|
102 | **
|
---|
103 | ** All names provided to PR_OpenSharedMemory() should be valid
|
---|
104 | ** filename syntax or name syntax for shared memory for the target
|
---|
105 | ** platform. Referenced directories should have permissions
|
---|
106 | ** appropriate for writing.
|
---|
107 | **
|
---|
108 | ** Limits:
|
---|
109 | ** Different platforms have limits on both the number and size of
|
---|
110 | ** shared memory resources. The default system limits on some
|
---|
111 | ** platforms may be smaller than your requirements. These limits may
|
---|
112 | ** be adjusted on some platforms either via boot-time options or by
|
---|
113 | ** setting the size of the system paging space to accomodate more
|
---|
114 | ** and/or larger shared memory segment(s).
|
---|
115 | **
|
---|
116 | ** Security:
|
---|
117 | ** On unix platforms, depending on implementation, contents of the
|
---|
118 | ** backing store for the shared memory can be exposed via the file
|
---|
119 | ** system. Set permissions and or access controls at create and attach
|
---|
120 | ** time to ensure you get the desired security.
|
---|
121 | **
|
---|
122 | ** On windows platforms, no special security measures are provided.
|
---|
123 | **
|
---|
124 | ** Example:
|
---|
125 | ** The test case pr/tests/nameshm1.c provides an example of use as
|
---|
126 | ** well as testing the operation of NSPR's Named Shared Memory.
|
---|
127 | **
|
---|
128 | ** lth. 18-Aug-1999.
|
---|
129 | */
|
---|
130 |
|
---|
131 | #ifndef prshm_h___
|
---|
132 | #define prshm_h___
|
---|
133 |
|
---|
134 | #include "prtypes.h"
|
---|
135 | #include "prio.h"
|
---|
136 |
|
---|
137 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
138 | #define PR_OpenSharedMemory VBoxNsprPR_OpenSharedMemory
|
---|
139 | #define PR_AttachSharedMemory VBoxNsprPR_AttachSharedMemory
|
---|
140 | #define PR_DetachSharedMemory VBoxNsprPR_DetachSharedMemory
|
---|
141 | #define PR_CloseSharedMemory VBoxNsprPR_CloseSharedMemory
|
---|
142 | #define PR_DeleteSharedMemory VBoxNsprPR_DeleteSharedMemory
|
---|
143 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
144 |
|
---|
145 | PR_BEGIN_EXTERN_C
|
---|
146 |
|
---|
147 | /*
|
---|
148 | ** Declare opaque type PRSharedMemory.
|
---|
149 | */
|
---|
150 | typedef struct PRSharedMemory PRSharedMemory;
|
---|
151 |
|
---|
152 | /*
|
---|
153 | ** FUNCTION: PR_OpenSharedMemory()
|
---|
154 | **
|
---|
155 | ** DESCRIPTION:
|
---|
156 | ** PR_OpenSharedMemory() creates a new shared-memory segment or
|
---|
157 | ** associates a previously created memory segment with name.
|
---|
158 | **
|
---|
159 | ** When parameter create is (PR_SHM_EXCL | PR_SHM_CREATE) and the
|
---|
160 | ** shared memory already exists, the function returns NULL with the
|
---|
161 | ** error set to PR_FILE_EXISTS_ERROR.
|
---|
162 | **
|
---|
163 | ** When parameter create is PR_SHM_CREATE and the shared memory
|
---|
164 | ** already exists, a handle to that memory segment is returned. If
|
---|
165 | ** the segment does not exist, it is created and a pointer to the
|
---|
166 | ** related PRSharedMemory structure is returned.
|
---|
167 | **
|
---|
168 | ** When parameter create is 0, and the shared memory exists, a
|
---|
169 | ** pointer to a PRSharedMemory is returned. If the shared memory does
|
---|
170 | ** not exist, NULL is returned with the error set to
|
---|
171 | ** PR_FILE_NOT_FOUND_ERROR.
|
---|
172 | **
|
---|
173 | ** INPUTS:
|
---|
174 | ** name -- the name the shared-memory segment is known as.
|
---|
175 | ** size -- the size of the shared memory segment.
|
---|
176 | ** flags -- Options for creating the shared memory
|
---|
177 | ** mode -- Same as is passed to PR_Open()
|
---|
178 | **
|
---|
179 | ** OUTPUTS:
|
---|
180 | ** The shared memory is allocated.
|
---|
181 | **
|
---|
182 | ** RETURNS: Pointer to opaque structure PRSharedMemory or NULL.
|
---|
183 | ** NULL is returned on error. The reason for the error can be
|
---|
184 | ** retrieved via PR_GetError() and PR_GetOSError();
|
---|
185 | **
|
---|
186 | */
|
---|
187 | NSPR_API( PRSharedMemory * )
|
---|
188 | PR_OpenSharedMemory(
|
---|
189 | const char *name,
|
---|
190 | PRSize size,
|
---|
191 | PRIntn flags,
|
---|
192 | PRIntn mode
|
---|
193 | );
|
---|
194 | /* Define values for PR_OpenShareMemory(...,create) */
|
---|
195 | #define PR_SHM_CREATE 0x1 /* create if not exist */
|
---|
196 | #define PR_SHM_EXCL 0x2 /* fail if already exists */
|
---|
197 |
|
---|
198 | /*
|
---|
199 | ** FUNCTION: PR_AttachSharedMemory()
|
---|
200 | **
|
---|
201 | ** DESCRIPTION:
|
---|
202 | ** PR_AttachSharedMemory() maps the shared-memory described by
|
---|
203 | ** shm to the current process.
|
---|
204 | **
|
---|
205 | ** INPUTS:
|
---|
206 | ** shm -- The handle returned from PR_OpenSharedMemory().
|
---|
207 | ** flags -- options for mapping the shared memory.
|
---|
208 | ** PR_SHM_READONLY causes the memory to be attached
|
---|
209 | ** read-only.
|
---|
210 | **
|
---|
211 | ** OUTPUTS:
|
---|
212 | ** On success, the shared memory segment represented by shm is mapped
|
---|
213 | ** into the process' address space.
|
---|
214 | **
|
---|
215 | ** RETURNS: Address where shared memory is mapped, or NULL.
|
---|
216 | ** NULL is returned on error. The reason for the error can be
|
---|
217 | ** retrieved via PR_GetError() and PR_GetOSError();
|
---|
218 | **
|
---|
219 | **
|
---|
220 | */
|
---|
221 | NSPR_API( void * )
|
---|
222 | PR_AttachSharedMemory(
|
---|
223 | PRSharedMemory *shm,
|
---|
224 | PRIntn flags
|
---|
225 | );
|
---|
226 | /* Define values for PR_AttachSharedMemory(...,flags) */
|
---|
227 | #define PR_SHM_READONLY 0x01
|
---|
228 |
|
---|
229 | /*
|
---|
230 | ** FUNCTION: PR_DetachSharedMemory()
|
---|
231 | **
|
---|
232 | ** DESCRIPTION:
|
---|
233 | ** PR_DetachSharedMemory() detaches the shared-memory described
|
---|
234 | ** by shm.
|
---|
235 | **
|
---|
236 | ** INPUTS:
|
---|
237 | ** shm -- The handle returned from PR_OpenSharedMemory().
|
---|
238 | ** addr -- The address at which the memory was attached.
|
---|
239 | **
|
---|
240 | ** OUTPUTS:
|
---|
241 | ** The shared memory mapped to an address via a previous call to
|
---|
242 | ** PR_AttachSharedMemory() is unmapped.
|
---|
243 | **
|
---|
244 | ** RETURNS: PRStatus
|
---|
245 | **
|
---|
246 | */
|
---|
247 | NSPR_API( PRStatus )
|
---|
248 | PR_DetachSharedMemory(
|
---|
249 | PRSharedMemory *shm,
|
---|
250 | void *addr
|
---|
251 | );
|
---|
252 |
|
---|
253 | /*
|
---|
254 | ** FUNCTION: PR_CloseSharedMemory()
|
---|
255 | **
|
---|
256 | ** DESCRIPTION:
|
---|
257 | ** PR_CloseSharedMemory() closes the shared-memory described by
|
---|
258 | ** shm.
|
---|
259 | **
|
---|
260 | ** INPUTS:
|
---|
261 | ** shm -- The handle returned from PR_OpenSharedMemory().
|
---|
262 | **
|
---|
263 | ** OUTPUTS:
|
---|
264 | ** the shared memory represented by shm is closed
|
---|
265 | **
|
---|
266 | ** RETURNS: PRStatus
|
---|
267 | **
|
---|
268 | */
|
---|
269 | NSPR_API( PRStatus )
|
---|
270 | PR_CloseSharedMemory(
|
---|
271 | PRSharedMemory *shm
|
---|
272 | );
|
---|
273 |
|
---|
274 | /*
|
---|
275 | ** FUNCTION: PR_DeleteSharedMemory()
|
---|
276 | **
|
---|
277 | ** DESCRIPTION:
|
---|
278 | ** The shared memory resource represented by name is released.
|
---|
279 | **
|
---|
280 | ** INPUTS:
|
---|
281 | ** name -- the name the shared-memory segment
|
---|
282 | **
|
---|
283 | ** OUTPUTS:
|
---|
284 | ** depending on platform, resources may be returned to the underlying
|
---|
285 | ** operating system.
|
---|
286 | **
|
---|
287 | ** RETURNS: PRStatus
|
---|
288 | **
|
---|
289 | */
|
---|
290 | NSPR_API( PRStatus )
|
---|
291 | PR_DeleteSharedMemory(
|
---|
292 | const char *name
|
---|
293 | );
|
---|
294 |
|
---|
295 | PR_END_EXTERN_C
|
---|
296 |
|
---|
297 | #endif /* prshm_h___ */
|
---|