summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--include/apr_shm.h64
-rw-r--r--shmem/beos/shm.c17
-rw-r--r--shmem/os2/shm.c17
-rw-r--r--shmem/unix/shm.c17
-rw-r--r--shmem/win32/shm.c69
6 files changed, 173 insertions, 17 deletions
diff --git a/CHANGES b/CHANGES
index ffe6cce1a..45637ab2e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,11 @@ Changes for APR 2.0.0
*) Windows: Create named shared memory segments under the "Local"
namespace if the caller is unprivileged, fixing an inability of
unprivileged callers to use apr_shm_create() with named shared
- memory segments under recent Windows. [Jeff Trawick]
+ memory segments under recent Windows. As before, shared memory
+ segments are created under the "Global" namespace for privileged
+ callers. Add apr_shm_create_ex() and apr_shm_attach_ex(), which
+ provide the ability to override the normal namespace selection.
+ [Jeff Trawick]
*) Add apr_pbase64_encode() and apr_pbase64_decode() to encode to/from
the pool. [Graham Leggett]
diff --git a/include/apr_shm.h b/include/apr_shm.h
index cf4d6ea26..2ed86e219 100644
--- a/include/apr_shm.h
+++ b/include/apr_shm.h
@@ -44,7 +44,8 @@ extern "C" {
typedef struct apr_shm_t apr_shm_t;
/**
- * Create and make accessible a shared memory segment.
+ * Create and make accessible a shared memory segment with default
+ * properties.
* @param m The shared memory structure to create.
* @param reqsize The desired size of the segment.
* @param filename The file to use for shared memory on platforms that
@@ -72,6 +73,52 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
apr_pool_t *pool);
/**
+ * Special processing flags for apr_shm_create_ex() and apr_shm_attach_ex().
+ */
+#define APR_SHM_NS_LOCAL 1 /* Create or attach to named shared memory
+ * segment in the "Local" namespace on
+ * Windows. (Ignored on other platforms.)
+ * By default, the "Global" namespace is
+ * used for privileged processes and the
+ * "Local" namespace is used otherwise.
+ */
+#define APR_SHM_NS_GLOBAL 2 /* Create or attach to named shared memory
+ * segment in the "Global" namespace on
+ * Windows. (Ignored on other platforms.)
+ */
+
+/**
+ * Create and make accessible a shared memory segment with platform-
+ * specific processing.
+ * @param m The shared memory structure to create.
+ * @param reqsize The desired size of the segment.
+ * @param filename The file to use for shared memory on platforms that
+ * require it.
+ * @param pool the pool from which to allocate the shared memory
+ * structure.
+ * @param flags mask of APR_SHM_* (defined above)
+ * @remark A note about Anonymous vs. Named shared memory segments:
+ * Not all plaforms support anonymous shared memory segments, but in
+ * some cases it is prefered over other types of shared memory
+ * implementations. Passing a NULL 'file' parameter to this function
+ * will cause the subsystem to use anonymous shared memory segments.
+ * If such a system is not available, APR_ENOTIMPL is returned.
+ * @remark A note about allocation sizes:
+ * On some platforms it is necessary to store some metainformation
+ * about the segment within the actual segment. In order to supply
+ * the caller with the requested size it may be necessary for the
+ * implementation to request a slightly greater segment length
+ * from the subsystem. In all cases, the apr_shm_baseaddr_get()
+ * function will return the first usable byte of memory.
+ *
+ */
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags);
+
+/**
* Remove named resource associated with a shared memory segment,
* preventing attachments to the resource, but not destroying it.
* @param filename The filename associated with shared-memory segment which
@@ -109,6 +156,21 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
apr_pool_t *pool);
/**
+ * Attach to a shared memory segment that was created
+ * by another process, with platform-specific processing.
+ * @param m The shared memory structure to create.
+ * @param filename The file used to create the original segment.
+ * (This MUST match the original filename.)
+ * @param pool the pool from which to allocate the shared memory
+ * structure for this process.
+ * @param flags mask of APR_SHM_* (defined above)
+ */
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags);
+
+/**
* Detach from a shared memory segment without destroying it.
* @param m The shared memory structure representing the segment
* to detach from.
diff --git a/shmem/beos/shm.c b/shmem/beos/shm.c
index d6b888b08..db94dce32 100644
--- a/shmem/beos/shm.c
+++ b/shmem/beos/shm.c
@@ -71,6 +71,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
delete_area(m->aid);
@@ -133,6 +142,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
delete_area(m->aid);
diff --git a/shmem/os2/shm.c b/shmem/os2/shm.c
index f2c1b7dfb..81de941c2 100644
--- a/shmem/os2/shm.c
+++ b/shmem/os2/shm.c
@@ -56,6 +56,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
DosFreeMem(m->memblock);
@@ -90,6 +99,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
int rc = 0;
diff --git a/shmem/unix/shm.c b/shmem/unix/shm.c
index f1259e232..f907000c8 100644
--- a/shmem/unix/shm.c
+++ b/shmem/unix/shm.c
@@ -365,6 +365,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
}
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
apr_pool_t *pool)
{
@@ -569,6 +578,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
}
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup_attach(m);
diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c
index 930a25c74..af0115e44 100644
--- a/shmem/win32/shm.c
+++ b/shmem/win32/shm.c
@@ -114,10 +114,11 @@ static int can_create_global_maps(void)
}
#endif /* SE_CREATE_GLOBAL_NAME */
-APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
- apr_size_t reqsize,
- const char *file,
- apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *file,
+ apr_pool_t *pool,
+ apr_int32_t flags)
{
static apr_size_t memblock = 0;
HANDLE hMap, hFile;
@@ -154,6 +155,8 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
mapkey = NULL;
}
else {
+ int global;
+
/* Do file backed, which is not an inherited handle
* While we could open APR_EXCL, it doesn't seem that Unix
* ever did. Ignore that error here, but fail later when
@@ -172,7 +175,16 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
* without slashes or backslashes, and prepends the \global
* or \local prefix on Win2K and later
*/
- mapkey = res_name_from_filename(file, can_create_global_maps(), pool);
+ if (flags & APR_SHM_NS_GLOBAL) {
+ global = 1;
+ }
+ else if (flags & APR_SHM_NS_LOCAL) {
+ global = 0;
+ }
+ else {
+ global = can_create_global_maps();
+ }
+ mapkey = res_name_from_filename(file, global, pool);
}
#if APR_HAS_UNICODE_FS
@@ -228,6 +240,14 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *file,
+ apr_pool_t *pool)
+{
+ return apr_shm_create_ex(m, reqsize, file, pool, 0);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup(m);
@@ -318,24 +338,36 @@ static apr_status_t shm_attach_internal(apr_shm_t **m,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
- const char *file,
- apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *file,
+ apr_pool_t *pool,
+ apr_int32_t flags)
{
apr_status_t rv;
- int can_create_global = can_create_global_maps();
- int try_global_local[3] = {1, /* first try to find shm under global namespace */
- 0, /* next try to find it under local namespace */
- -1}; /* nothing more to try */
+ int can_create_global;
+ int try_global_local[3] = {-1, -1, -1};
int cur;
if (!file) {
return APR_EINVAL;
}
- if (!can_create_global) { /* unprivileged process */
- try_global_local[0] = 0; /* search local before global */
- try_global_local[1] = 1;
+ if (flags & APR_SHM_NS_LOCAL) {
+ try_global_local[0] = 0; /* only search local */
+ }
+ else if (flags & APR_SHM_NS_GLOBAL) {
+ try_global_local[0] = 1; /* only search global */
+ }
+ else {
+ can_create_global = can_create_global_maps();
+ if (!can_create_global) { /* unprivileged process */
+ try_global_local[0] = 0; /* search local before global */
+ try_global_local[1] = 1;
+ }
+ else {
+ try_global_local[0] = 1; /* search global before local */
+ try_global_local[1] = 0;
+ }
}
for (cur = 0; try_global_local[cur] != -1; cur++) {
@@ -348,6 +380,13 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return rv;
}
+APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
+ const char *file,
+ apr_pool_t *pool)
+{
+ return apr_shm_attach_ex(m, file, pool, 0);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup(m);