Apache Portable Runtime
apr_shm.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APR_SHM_H
00018 #define APR_SHM_H
00019 
00020 /**
00021  * @file apr_shm.h
00022  * @brief APR Shared Memory Routines
00023  */
00024 
00025 #include "apr.h"
00026 #include "apr_pools.h"
00027 #include "apr_errno.h"
00028 #include "apr_perms_set.h"
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif /* __cplusplus */
00033 
00034 /**
00035  * @defgroup apr_shm Shared Memory Routines
00036  * @ingroup APR 
00037  * @{
00038  */
00039 
00040 /**
00041  * Private, platform-specific data struture representing a shared memory
00042  * segment.
00043  */
00044 typedef struct apr_shm_t apr_shm_t;
00045 
00046 /**
00047  * Create and make accessable a shared memory segment.
00048  * @param m The shared memory structure to create.
00049  * @param reqsize The desired size of the segment.
00050  * @param filename The file to use for shared memory on platforms that
00051  *        require it.
00052  * @param pool the pool from which to allocate the shared memory
00053  *        structure.
00054  * @remark A note about Anonymous vs. Named shared memory segments:
00055  *         Not all plaforms support anonymous shared memory segments, but in
00056  *         some cases it is prefered over other types of shared memory
00057  *         implementations. Passing a NULL 'file' parameter to this function
00058  *         will cause the subsystem to use anonymous shared memory segments.
00059  *         If such a system is not available, APR_ENOTIMPL is returned.
00060  * @remark A note about allocation sizes:
00061  *         On some platforms it is necessary to store some metainformation
00062  *         about the segment within the actual segment. In order to supply
00063  *         the caller with the requested size it may be necessary for the
00064  *         implementation to request a slightly greater segment length
00065  *         from the subsystem. In all cases, the apr_shm_baseaddr_get()
00066  *         function will return the first usable byte of memory.
00067  * 
00068  */
00069 APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
00070                                          apr_size_t reqsize,
00071                                          const char *filename,
00072                                          apr_pool_t *pool);
00073 
00074 /**
00075  * Remove named resource associated with a shared memory segment,
00076  * preventing attachments to the resource, but not destroying it.
00077  * @param filename The filename associated with shared-memory segment which
00078  *        needs to be removed
00079  * @param pool The pool used for file operations
00080  * @remark This function is only supported on platforms which support
00081  * name-based shared memory segments, and will return APR_ENOTIMPL on
00082  * platforms without such support.  Removing the file while the shm
00083  * is in use is not entirely portable, caller may use this to enhance
00084  * obscurity of the resource, but be prepared for the call to fail,
00085  * and for concurrent attempts to create a resource of the same name
00086  * to also fail.  The pool cleanup of apr_shm_create (apr_shm_destroy)
00087  * also removes the named resource.
00088  */
00089 APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
00090                                          apr_pool_t *pool);
00091 
00092 /**
00093  * Destroy a shared memory segment and associated memory.
00094  * @param m The shared memory segment structure to destroy.
00095  */
00096 APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m);
00097 
00098 /**
00099  * Attach to a shared memory segment that was created
00100  * by another process.
00101  * @param m The shared memory structure to create.
00102  * @param filename The file used to create the original segment.
00103  *        (This MUST match the original filename.)
00104  * @param pool the pool from which to allocate the shared memory
00105  *        structure for this process.
00106  */
00107 APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
00108                                          const char *filename,
00109                                          apr_pool_t *pool);
00110 
00111 /**
00112  * Detach from a shared memory segment without destroying it.
00113  * @param m The shared memory structure representing the segment
00114  *        to detach from.
00115  */
00116 APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m);
00117 
00118 /**
00119  * Retrieve the base address of the shared memory segment.
00120  * NOTE: This address is only usable within the callers address
00121  * space, since this API does not guarantee that other attaching
00122  * processes will maintain the same address mapping.
00123  * @param m The shared memory segment from which to retrieve
00124  *        the base address.
00125  * @return address, aligned by APR_ALIGN_DEFAULT.
00126  */
00127 APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m);
00128 
00129 /**
00130  * Retrieve the length of a shared memory segment in bytes.
00131  * @param m The shared memory segment from which to retrieve
00132  *        the segment length.
00133  */
00134 APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m);
00135 
00136 /**
00137  * Set shared memory permissions.
00138  */
00139 APR_PERMS_SET_IMPLEMENT(shm);
00140 
00141 /**
00142  * Get the pool used by this shared memory segment.
00143  */
00144 APR_POOL_DECLARE_ACCESSOR(shm);
00145 
00146 /** @} */ 
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151 
00152 #endif  /* APR_SHM_T */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines