1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 * @brief APR Shared Memory Routines
26 #include "apr_pools.h"
27 #include "apr_errno.h"
31 #endif /* __cplusplus */
34 * @defgroup apr_shm Shared Memory Routines
40 * Private, platform-specific data struture representing a shared memory
43 typedef struct apr_shm_t apr_shm_t;
46 * Create and make accessible a shared memory segment with default
48 * @param m The shared memory structure to create.
49 * @param reqsize The desired size of the segment.
50 * @param filename The file to use for shared memory on platforms that
52 * @param pool the pool from which to allocate the shared memory
54 * @remark A note about Anonymous vs. Named shared memory segments:
55 * Not all plaforms support anonymous shared memory segments, but in
56 * some cases it is prefered over other types of shared memory
57 * implementations. Passing a NULL 'file' parameter to this function
58 * will cause the subsystem to use anonymous shared memory segments.
59 * If such a system is not available, APR_ENOTIMPL is returned.
60 * @remark A note about allocation sizes:
61 * On some platforms it is necessary to store some metainformation
62 * about the segment within the actual segment. In order to supply
63 * the caller with the requested size it may be necessary for the
64 * implementation to request a slightly greater segment length
65 * from the subsystem. In all cases, the apr_shm_baseaddr_get()
66 * function will return the first usable byte of memory.
69 APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
75 * Special processing flags for apr_shm_create_ex() and apr_shm_attach_ex().
77 #define APR_SHM_NS_LOCAL 1 /* Create or attach to named shared memory
78 * segment in the "Local" namespace on
79 * Windows. (Ignored on other platforms.)
80 * By default, the "Global" namespace is
81 * used for privileged processes and the
82 * "Local" namespace is used otherwise.
84 #define APR_SHM_NS_GLOBAL 2 /* Create or attach to named shared memory
85 * segment in the "Global" namespace on
86 * Windows. (Ignored on other platforms.)
90 * Create and make accessible a shared memory segment with platform-
91 * specific processing.
92 * @param m The shared memory structure to create.
93 * @param reqsize The desired size of the segment.
94 * @param filename The file to use for shared memory on platforms that
96 * @param pool the pool from which to allocate the shared memory
98 * @param flags mask of APR_SHM_* (defined above)
99 * @remark A note about Anonymous vs. Named shared memory segments:
100 * Not all plaforms support anonymous shared memory segments, but in
101 * some cases it is prefered over other types of shared memory
102 * implementations. Passing a NULL 'file' parameter to this function
103 * will cause the subsystem to use anonymous shared memory segments.
104 * If such a system is not available, APR_ENOTIMPL is returned.
105 * @remark A note about allocation sizes:
106 * On some platforms it is necessary to store some metainformation
107 * about the segment within the actual segment. In order to supply
108 * the caller with the requested size it may be necessary for the
109 * implementation to request a slightly greater segment length
110 * from the subsystem. In all cases, the apr_shm_baseaddr_get()
111 * function will return the first usable byte of memory.
114 APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
116 const char *filename,
121 * Remove named resource associated with a shared memory segment,
122 * preventing attachments to the resource, but not destroying it.
123 * @param filename The filename associated with shared-memory segment which
124 * needs to be removed
125 * @param pool The pool used for file operations
126 * @remark This function is only supported on platforms which support
127 * name-based shared memory segments, and will return APR_ENOTIMPL on
128 * platforms without such support. Removing the file while the shm
129 * is in use is not entirely portable, caller may use this to enhance
130 * obscurity of the resource, but be prepared for the call to fail,
131 * and for concurrent attempts to create a resource of the same name
132 * to also fail. The pool cleanup of apr_shm_create (apr_shm_destroy)
133 * also removes the named resource.
135 APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
139 * Destroy a shared memory segment and associated memory.
140 * @param m The shared memory segment structure to destroy.
142 APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m);
145 * Attach to a shared memory segment that was created
146 * by another process.
147 * @param m The shared memory structure to create.
148 * @param filename The file used to create the original segment.
149 * (This MUST match the original filename.)
150 * @param pool the pool from which to allocate the shared memory
151 * structure for this process.
153 APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
154 const char *filename,
158 * Attach to a shared memory segment that was created
159 * by another process, with platform-specific processing.
160 * @param m The shared memory structure to create.
161 * @param filename The file used to create the original segment.
162 * (This MUST match the original filename.)
163 * @param pool the pool from which to allocate the shared memory
164 * structure for this process.
165 * @param flags mask of APR_SHM_* (defined above)
167 APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
168 const char *filename,
173 * Detach from a shared memory segment without destroying it.
174 * @param m The shared memory structure representing the segment
177 APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m);
180 * Retrieve the base address of the shared memory segment.
181 * NOTE: This address is only usable within the callers address
182 * space, since this API does not guarantee that other attaching
183 * processes will maintain the same address mapping.
184 * @param m The shared memory segment from which to retrieve
186 * @return address, aligned by APR_ALIGN_DEFAULT.
188 APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m);
191 * Retrieve the length of a shared memory segment in bytes.
192 * @param m The shared memory segment from which to retrieve
193 * the segment length.
195 APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m);
198 * Get the pool used by this shared memory segment.
200 APR_POOL_DECLARE_ACCESSOR(shm);
208 #endif /* APR_SHM_T */