summaryrefslogtreecommitdiff
path: root/shmem
diff options
context:
space:
mode:
authoraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2002-01-10 00:20:06 +0000
committeraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2002-01-10 00:20:06 +0000
commit13a2f15109de2463a6cb661eaac7930734b0b451 (patch)
tree87f1f5d12c47ba1dfc46993a40ab8fecfa733b30 /shmem
parentabce3b319a68d71ef6c2b183987d59ea334a255f (diff)
downloadlibapr-13a2f15109de2463a6cb661eaac7930734b0b451.tar.gz
This is the new apr_shm_t API. It completely replaces the old shared
memory API, which was unusable on Win32 and other platforms that do not have inherited shared memory segments since it only supported anonymous memory. We now support both anonymous and name-based shared memory. Anonymous shmem tested to work on the following platforms: Linux 2.2, Linux 2.4, Solaris 8, FreeBSD 5.0-CURRENT Name-based shmem is _not_ fully functional on UNIX, but this API replaces all of the preexisting apr_shmem_t functionality. Stubs were provided for Beos and OS/2, and as much relevant code as possible was preserved, but no guarantees of correctness. Reviewed by: Justin Erenkrantz, Will Rowe git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62735 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'shmem')
-rw-r--r--shmem/beos/shm.c128
-rw-r--r--shmem/beos/shmem.c321
-rw-r--r--shmem/os2/shm.c (renamed from shmem/os2/shmem.c)64
-rw-r--r--shmem/unix/Makefile.in6
-rw-r--r--shmem/unix/shm.c459
-rw-r--r--shmem/unix/shmem.c331
6 files changed, 602 insertions, 707 deletions
diff --git a/shmem/beos/shm.c b/shmem/beos/shm.c
new file mode 100644
index 000000000..a73d36206
--- /dev/null
+++ b/shmem/beos/shm.c
@@ -0,0 +1,128 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "apr_general.h"
+#include "apr_shmem.h"
+#include "apr_errno.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <kernel/OS.h>
+
+struct apr_shm_t {
+ apr_pool_t *p;
+ void *memblock;
+ void *ptr;
+ apr_size_t avail;
+ area_id aid;
+};
+
+APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, const char *file,
+ apr_pool_t *p)
+{
+ apr_size_t pagesize;
+ area_id newid;
+ char *addr;
+
+ (*m) = (apr_shmem_t *)apr_pcalloc(p, sizeof(apr_shmem_t));
+ /* we MUST allocate in pages, so calculate how big an area we need... */
+ pagesize = ((reqsize + B_PAGE_SIZE - 1) / B_PAGE_SIZE) * B_PAGE_SIZE;
+
+ newid = create_area("apr_shm", (void*)&addr, B_ANY_ADDRESS,
+ pagesize, B_CONTIGUOUS, B_READ_AREA|B_WRITE_AREA);
+
+ if (newid < 0)
+ return errno;
+
+ (*m)->p = p;
+ (*m)->aid = newid;
+ (*m)->memblock = addr;
+ (*m)->ptr = (void*)addr;
+ (*m)->avail = pagesize; /* record how big an area we actually created... */
+
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
+{
+ delete_area(m->aid);
+ m->avail = 0;
+ m->memblock = NULL;
+ return APR_SUCCESS;
+}
+
+
+APR_DECLARE(apr_status_t) apr_shm_attach(apr_shmem_t **m,
+ const char *filename,
+ apr_pool_t *pool)
+{
+ return APR_ENOTIMPL;
+}
+
+APR_DECLARE(apr_status_t) apr_shm_detach(apr_shmem_t *m)
+{
+ return APR_ENOTIMPL;
+}
+
+APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m)
+{
+ return APR_ENOTIMPL;
+}
+
+APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
+{
+ return APR_ENOTIMPL;
+}
+
diff --git a/shmem/beos/shmem.c b/shmem/beos/shmem.c
deleted file mode 100644
index faa8f07b9..000000000
--- a/shmem/beos/shmem.c
+++ /dev/null
@@ -1,321 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr_general.h"
-#include "apr_shmem.h"
-#include "apr_errno.h"
-#include "apr_lib.h"
-#include "apr_strings.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <kernel/OS.h>
-
-struct block_t {
- apr_pool_t *p;
- void *addr;
- apr_size_t size;
- void *nxt;
- void *prev;
-};
-
-struct apr_shmem_t {
- apr_pool_t *p;
- void *memblock;
- void *ptr;
- apr_size_t avail;
- area_id aid;
- struct block_t *uselist;
- struct block_t *freelist;
-};
-
-#define MIN_BLK_SIZE 128
-
-
-void add_block(struct block_t **list, struct block_t *blk);
-void split_block(struct block_t **list, struct block_t *blk, apr_size_t size);
-
-static struct block_t * find_block_by_addr(struct block_t *list, void *addr)
-{
- struct block_t *b = list;
- do {
- if (b->addr == addr)
- return b;
- }
- while ((b = b->nxt) != NULL);
-
- return NULL;
-}
-
-static struct block_t *find_block_of_size(struct block_t *list, apr_size_t size)
-{
- struct block_t *b = list, *rv = NULL;
- apr_ssize_t diff = -1;
-
- if (!list)
- return NULL;
-
- do {
- if (b->size == size)
- return b;
- if (b->size > size){
- if (diff == -1)
- diff = b->size;
- if ((b->size - size) < diff){
- diff = b->size - size;
- rv = b;
- }
- }
- }
- while ((b = b->nxt) != list);
-
- if (diff > MIN_BLK_SIZE) {
- split_block(&list, rv, size);
- }
-
- if (rv)
- return rv;
-
- return NULL;
-}
-
-void add_block(struct block_t **list, struct block_t *blk)
-{
- if ((*list) == NULL)
- *list = blk;
-
- if (blk == (*list)){
- blk->prev = blk;
- blk->nxt = blk;
- } else {
- ((struct block_t*)(*list)->prev)->nxt = blk;
- blk->prev = ((struct block_t *)(*list))->prev;
- blk->nxt = (*list);
- (*list)->prev = blk;
- }
-}
-
-void split_block(struct block_t **list, struct block_t *blk, apr_size_t size)
-{
- apr_size_t nsz = blk->size - size;
- struct block_t *b = (struct block_t*)apr_pcalloc(blk->p, sizeof(struct block_t));
- b->p = blk->p;
- b->size = nsz;
- blk->size = size;
- b->addr = blk->addr + size;
- add_block(list, b);
-}
-
-static void remove_block(struct block_t **list, struct block_t *blk)
-{
- if (((*list) == blk) && (blk->nxt == blk) && (blk == blk->prev)){
- *list = NULL;
- blk->nxt = NULL;
- blk->prev = NULL;
- } else {
- ((struct block_t*)(blk->nxt))->prev = blk->prev;
- ((struct block_t*)(blk->prev))->nxt = blk->nxt;
- if (*list == blk)
- *list = blk->nxt;
- blk->nxt = NULL;
- blk->prev = NULL;
- }
-}
-
-/* puts a used block onto the free list for it to be reused... */
-static void free_block(apr_shmem_t *m, void *entity)
-{
- struct block_t *b;
- if ((b = find_block_by_addr(m->uselist, entity)) != NULL){
- remove_block(&(m->uselist), b);
- add_block(&(m->freelist), b);
- m->avail += b->size;
- }
-}
-
-/* assigns a block of our memory and puts an entry on the uselist */
-static struct block_t *alloc_block(apr_shmem_t *m, apr_size_t size)
-{
- struct block_t *b = NULL;
- if (m->avail < size)
- return NULL;
-
- if ((b = find_block_of_size(m->freelist, size)) != NULL){
- remove_block(&(m->freelist), b);
- } else {
- b = (struct block_t*)apr_pcalloc(m->p, sizeof(struct block_t));
- b->p = m->p;
- b->addr = m->ptr;
- b->size = size;
- m->ptr += size;
- }
- m->avail -= b->size; /* actual size may be different if we're reusing a block */
- add_block(&(m->uselist), b);
-
- return b;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, const char *file,
- apr_pool_t *p)
-{
- apr_size_t pagesize;
- area_id newid;
- char *addr;
-
- (*m) = (apr_shmem_t *)apr_pcalloc(p, sizeof(apr_shmem_t));
- /* we MUST allocate in pages, so calculate how big an area we need... */
- pagesize = ((reqsize + B_PAGE_SIZE - 1) / B_PAGE_SIZE) * B_PAGE_SIZE;
-
- newid = create_area("apr_shm", (void*)&addr, B_ANY_ADDRESS,
- pagesize, B_CONTIGUOUS, B_READ_AREA|B_WRITE_AREA);
-
- if (newid < 0)
- return errno;
-
- (*m)->p = p;
- (*m)->aid = newid;
- (*m)->memblock = addr;
- (*m)->ptr = (void*)addr;
- (*m)->avail = pagesize; /* record how big an area we actually created... */
- (*m)->uselist = NULL;
- (*m)->freelist = NULL;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
-{
- delete_area(m->aid);
- m->avail = 0;
- m->freelist = NULL;
- m->uselist = NULL;
- m->memblock = NULL;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(void *) apr_shm_malloc(apr_shmem_t *m, apr_size_t reqsize)
-{
- struct block_t *b;
- if ((b = alloc_block(m, reqsize)) != NULL)
- return b->addr;
- return NULL;
-}
-
-APR_DECLARE(void *) apr_shm_calloc(apr_shmem_t *m, apr_size_t reqsize)
-{
- struct block_t *b;
- if ((b = alloc_block(m, reqsize)) != NULL){
- memset(b->addr, 0, reqsize);
- return b->addr;
- }
- return NULL;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_free(apr_shmem_t *m, void *entity)
-{
- free_block(m, entity);
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, apr_shm_name_t **name)
-{
- *name = NULL;
- return APR_ANONYMOUS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, apr_shm_name_t *name)
-{
- return APR_ANONYMOUS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_open(apr_shmem_t *m)
-{
- /* If we've forked we need a clone of the original area or we
- * will only have access to a one time copy of the data made when
- * the fork occurred. This strange bit of code fixes that problem!
- */
- thread_info ti;
- area_info ai;
- area_id deleteme = area_for(m->memblock);
-
- /* we need to check which team we're in, so we need to get
- * the appropriate info structures for the current thread and
- * the area we're using.
- */
- get_area_info(m->aid, &ai);
- get_thread_info(find_thread(NULL), &ti);
-
- if (ti.team != ai.team){
- area_id nai;
- /* if we are in a child then we need to delete the system
- * created area as it's a one time copy and won't be a clone
- * which is not good.
- */
- delete_area(deleteme);
- /* now we make our own clone and use that from now on! */
- nai = clone_area(ai.name, &(ai.address), B_CLONE_ADDRESS,
- B_READ_AREA | B_WRITE_AREA, ai.area);
- get_area_info(nai, &ai);
- m->memblock = ai.address;
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_avail(apr_shmem_t *m, apr_size_t *size)
-{
- *size = m->avail;
- if (m->avail == 0)
- return APR_ENOSHMAVAIL;
- return APR_SUCCESS;
-
-}
diff --git a/shmem/os2/shmem.c b/shmem/os2/shm.c
index 009b5a968..9adf40358 100644
--- a/shmem/os2/shmem.c
+++ b/shmem/os2/shm.c
@@ -65,9 +65,7 @@ struct apr_shmem_t {
Heap_t heap;
};
-
-
-APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, const char *file, apr_pool_t *cont)
+APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, const char *filename, apr_pool_t *cont)
{
int rc;
apr_shmem_t *newm = (apr_shmem_t *)apr_palloc(cont, sizeof(apr_shmem_t));
@@ -92,8 +90,6 @@ APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, cons
return APR_SUCCESS;
}
-
-
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
{
_uclose(m->heap);
@@ -102,62 +98,24 @@ APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
return APR_SUCCESS;
}
-
-
-APR_DECLARE(void *) apr_shm_malloc(apr_shmem_t *m, apr_size_t reqsize)
-{
- return _umalloc(m->heap, reqsize);
-}
-
-
-
-APR_DECLARE(void *) apr_shm_calloc(apr_shmem_t *m, apr_size_t size)
+APR_DECLARE(apr_status_t) apr_shm_attach(apr_shmem_t **m,
+ const char *filename,
+ apr_pool_t *pool)
{
- return _ucalloc(m->heap, size, 1);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_shm_free(apr_shmem_t *m, void *entity)
-{
- free(entity);
- return APR_SUCCESS;
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, apr_shm_name_t **name)
-{
- *name = NULL;
- return APR_ANONYMOUS;
+ return APR_ENOTIMPL;
}
-
-
-APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, apr_shm_name_t *name)
+APR_DECLARE(apr_status_t) apr_shm_detach(apr_shmem_t *m)
{
- return APR_ANONYMOUS;
+ return APR_ENOTIMPL;
}
-
-
-APR_DECLARE(apr_status_t) apr_shm_open(apr_shmem_t *m)
+APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m)
{
- int rc;
-
- rc = DosGetSharedMem(m->memblock, PAG_READ|PAG_WRITE);
-
- if (rc)
- return APR_OS2_STATUS(rc);
-
- _uopen(m->heap);
- return APR_SUCCESS;
+ return APR_ENOTIMPL;
}
-
-
-APR_DECLARE(apr_status_t) apr_shm_avail(apr_shmem_t *c, apr_size_t *size)
+APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
{
-
return APR_ENOTIMPL;
-}
+
diff --git a/shmem/unix/Makefile.in b/shmem/unix/Makefile.in
index 7b8e96223..fdf5956c7 100644
--- a/shmem/unix/Makefile.in
+++ b/shmem/unix/Makefile.in
@@ -1,10 +1,12 @@
-TARGETS = shmem.lo
+TARGETS = shm.lo
# bring in rules.mk for standard functionality
@INCLUDE_RULES@
INCDIR=../../include
-INCLUDES=-I$(INCDIR)
+INCDIR2=$(INCDIR)/arch
+INCDIR3=$(INCDIR)/arch/unix
+INCLUDES=-I$(INCDIR) -I$(INCDIR2) -I$(INCDIR3)
# DO NOT REMOVE
diff --git a/shmem/unix/shm.c b/shmem/unix/shm.c
new file mode 100644
index 000000000..0b21449d8
--- /dev/null
+++ b/shmem/unix/shm.c
@@ -0,0 +1,459 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "shm.h"
+
+#include "apr_general.h"
+#include "apr_errno.h"
+#include "apr_user.h"
+#include "apr_strings.h"
+
+/*
+#define APR_WANT_MEMFUNC
+#include "apr_want.h"
+*/
+
+/*
+#include "apr_portable.h"
+*/
+
+#if 0
+#if APR_HAVE_SHMEM_SHMGET
+/* The metadata that is stored in the file that we use to rendevous
+ * with the segment in unrelated processes. */
+struct apr_shm_shmget_metadata {
+ apr_size_t reqsize; /* requested size of the segment */
+};
+#endif /* APR_HAVE_SHMEM_SHMGET */
+#endif
+
+APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *pool)
+{
+ apr_shm_t *new_m;
+ apr_status_t status;
+#if APR_USE_SHMEM_SHMGET
+ struct shmid_ds shmbuf;
+ apr_uid_t uid;
+ apr_gid_t gid;
+#endif
+#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || \
+ APR_USE_SHMEM_MMAP_ZERO
+ int tmpfd;
+#endif
+#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
+ apr_size_t nbytes;
+ apr_file_t *file; /* file where metadata is stored */
+ int shmid;
+#endif
+
+ /* FIXME: associate this thing with a pool and set up a destructor
+ * to call detach. */
+
+ /* Check if they want anonymous or name-based shared memory */
+ if (filename == NULL) {
+#if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
+ new_m = apr_palloc(pool, sizeof(apr_shm_t));
+ if (!new_m) {
+ return APR_ENOMEM;
+ }
+ new_m->pool = pool;
+ new_m->reqsize = reqsize;
+ new_m->realsize = reqsize + sizeof(apr_size_t); /* room for metadata */
+ new_m->filename = NULL;
+
+#if APR_USE_SHMEM_MMAP_ZERO
+ status = apr_file_open(&new_m->file, "/dev/zero", APR_READ | APR_WRITE,
+ APR_OS_DEFAULT, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ status = apr_os_file_get(&tmpfd, new_m->file);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ new_m->base = mmap(NULL, new_m->realsize, PROT_READ|PROT_WRITE,
+ MAP_SHARED, tmpfd, 0);
+ if (new_m->base == MAP_FAILED) {
+ return errno;
+ }
+
+ /* No need to keep the file open after we map it. */
+ close(tmpfd);
+
+ /* store the real size in the metadata */
+ *(apr_size_t*)(new_m->base) = new_m->realsize;
+ /* metadata isn't usable */
+ new_m->usable = new_m->base + sizeof(apr_size_t);
+
+ *m = new_m;
+ return APR_SUCCESS;
+
+#elif APR_USE_SHMEM_MMAP_ANON
+ new_m->base = mmap(NULL, reqsize, PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_SHARED, -1, 0);
+ if (new_m->base == MAP_FAILED) {
+ return errno;
+ }
+
+ /* store the real size in the metadata */
+ *(apr_size_t*)(new_m->base) = new_m->realsize;
+ /* metadata isn't usable */
+ new_m->usable = new_m->base + sizeof(apr_size_t);
+
+ *m = new_m;
+ return APR_SUCCESS;
+
+#endif /* APR_USE_SHMEM_MMAP_ZERO */
+#endif /* APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON */
+#if APR_USE_SHMEM_SHMGET_ANON
+
+ new_m = apr_palloc(pool, sizeof(apr_shm_t));
+ if (!new_m) {
+ return APR_ENOMEM;
+ }
+ new_m->pool = pool;
+ new_m->reqsize = reqsize;
+ new_m->realsize = reqsize;
+ new_m->filename = NULL;
+
+ if ((shmid = shmget(IPC_PRIVATE, new_m->realsize,
+ SHM_R | SHM_W | IPC_CREAT)) < 0) {
+ return errno;
+ }
+
+ if ((new_m->base = shmat(shmid, NULL, 0)) < 0) {
+ return errno;
+ }
+
+ new_m->usable = new_m->base;
+
+ if (shmctl(shmid, IPC_STAT, &shmbuf) == -1) {
+ return errno;
+ }
+ apr_current_userid(&uid, &gid, pool);
+ shmbuf.shm_perm.uid = uid;
+ shmbuf.shm_perm.gid = gid;
+ if (shmctl(shmid, IPC_SET, &shmbuf) == -1) {
+ return errno;
+ }
+
+ new_m->shmid = shmid;
+
+ *m = new_m;
+ return APR_SUCCESS;
+#endif /* APR_USE_SHMEM_SHMGET_ANON */
+ /* It is an error if they want anonymous memory but we don't have it. */
+ return APR_ENOTIMPL; /* requested anonymous but we don't have it */
+ }
+
+ /* Name-based shared memory */
+ else {
+ new_m = apr_palloc(pool, sizeof(apr_shm_t));
+ if (!new_m) {
+ return APR_ENOMEM;
+ }
+ new_m->pool = pool;
+ new_m->reqsize = reqsize;
+ new_m->filename = apr_pstrdup(pool, filename);
+
+#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM
+ new_m->realsize = reqsize + sizeof(apr_size_t); /* room for metadata */
+ /* FIXME: Ignore error for now. *
+ * status = apr_file_remove(file, pool);*/
+ status = APR_SUCCESS;
+
+#if APR_USE_SHMEM_MMAP_TMP
+ /* FIXME: Is APR_OS_DEFAULT sufficient? */
+ status = apr_file_open(&new_m->file, filename,
+ APR_READ | APR_WRITE | APR_CREATE,
+ APR_OS_DEFAULT, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ if ((status = apr_os_file_get(&tmpfd, new_m->file)) != APR_SUCCESS) {
+ return status;
+ }
+ status = apr_file_trunc(new_m->file, new_m->realsize);
+ if (status != APR_SUCCESS) {
+ /* FIXME: should we unlink the file here? */
+ /* FIXME: should we close the file here? */
+ return status;
+ }
+#elif APR_USE_SHMEM_MMAP_SHM
+ /* FIXME: Is APR_OS_DEFAULT sufficient? */
+ tmpfd = shm_open(filename, O_RDWR | O_CREAT, APR_OS_DEFAULT);
+ if (tmpfd == -1) {
+ return errno;
+ }
+
+ apr_os_file_put(&new_m->file, &tmpfd, pool);
+ /* FIXME: check for errors */
+
+ status = apr_file_trunc(new_m->file, new_m->realsize);
+ if (status != APR_SUCCESS) {
+ shm_unlink(filename); /* we're failing, remove the object */
+ return status;
+ }
+#endif /* APR_USE_SHMEM_MMAP_SHM */
+ new_m->base = mmap(NULL, reqsize, PROT_READ|PROT_WRITE,
+ MAP_SHARED, tmpfd, 0);
+
+ /* FIXME: check for error */
+
+ /* FIXME: close the file (can we close the file if we're using
+ * shm_open? */
+
+ /* store the real size in the metadata */
+ *(apr_size_t*)(new_m->base) = new_m->realsize;
+ /* metadata isn't usable */
+ new_m->usable = new_m->base + sizeof(apr_size_t);
+
+ *m = new_m;
+ return APR_SUCCESS;
+
+#endif /* APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM */
+
+#if APR_USE_SHMEM_SHMGET
+ new_m->realsize = reqsize;
+
+ if ((shmid = shmget(ftok(filename, 1), new_m->realsize,
+ SHM_R | SHM_W | IPC_CREAT)) < 0) {
+ return errno;
+ }
+
+ new_m->base = shmat(shmid, NULL, 0);
+ /* FIXME: Handle errors. */
+ new_m->usable = new_m->base;
+
+ if (shmctl(shmid, IPC_STAT, &shmbuf) == -1) {
+ return errno;
+ }
+ apr_current_userid(&uid, &gid, pool);
+ shmbuf.shm_perm.uid = uid;
+ shmbuf.shm_perm.gid = gid;
+ if (shmctl(shmid, IPC_SET, &shmbuf) == -1) {
+ return errno;
+ }
+
+ new_m->shmid = shmid;
+
+ /* FIXME: APR_OS_DEFAULT is too permissive, switch to 600 I think. */
+ status = apr_file_open(&file, filename,
+ APR_WRITE | APR_CREATE,
+ APR_OS_DEFAULT, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ nbytes = sizeof(reqsize);
+ status = apr_file_write(file, (const void *)&reqsize,
+ &nbytes);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ status = apr_file_close(file);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ /* Remove the segment once use count hits zero. */
+ if (shmctl(shmid, IPC_RMID, NULL) == -1) {
+ return errno;
+ }
+
+ *m = new_m;
+ return APR_SUCCESS;
+
+#endif /* APR_USE_SHMEM_SHMGET */
+ }
+
+ return APR_ENOTIMPL;
+}
+
+APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
+{
+ /* FIXME: do cleanups based on what was allocated, not what was
+ * defined at runtime. */
+#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
+ munmap(m->base, m->realsize);
+ apr_file_close(m->file);
+#elif APR_USE_SHMEM_MMAP_ANON
+ munmap(m->base, m->realsize);
+#elif APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
+ shmdt(m->base);
+#endif
+
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool)
+{
+ apr_status_t status;
+
+ if (filename == NULL) {
+#if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
+ /* If they want anonymous memory they shouldn't call attach. */
+ return APR_EGENERAL;
+#else
+ return APR_ENOTIMPL;
+#endif
+ }
+ else {
+#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM
+ int tmpfd;
+ struct stat buf;
+ apr_shm_t *new_m;
+
+ new_m = apr_palloc(pool, sizeof(apr_shm_t));
+ if (!new_m) {
+ return APR_ENOMEM;
+ }
+ new_m->pool = pool;
+ new_m->reqsize = reqsize;
+ new_m->realsize = reqsize + sizeof(apr_size_t); /* room for metadata */
+ new_m->filename = apr_pstrdup(pool, filename);
+
+ /* FIXME: open the file, read the length, mmap the segment,
+ * close the file, reconstruct the apr_shm_t. */
+ status = apr_file_open(&new_m->file, filename,
+ APR_READ | APR_WRITE | APR_CREATE,
+ APR_OS_DEFAULT, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ if ((status = apr_os_file_get(&tmpfd, new_m->file)) != APR_SUCCESS) {
+ return status;
+ }
+
+
+ return APR_ENOTIMPL;
+
+#elif APR_USE_SHMEM_SHMGET
+ apr_shm_t *new_m;
+ apr_file_t *file; /* file where metadata is stored */
+ apr_size_t nbytes;
+
+ new_m = apr_palloc(pool, sizeof(apr_shm_t));
+ if (!new_m) {
+ return APR_ENOMEM;
+ }
+
+ /* FIXME: does APR_OS_DEFAULT matter for reading? */
+ status = apr_file_open(&file, filename,
+ APR_READ, APR_OS_DEFAULT, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ nbytes = sizeof(new_m->reqsize);
+ status = apr_file_read(file, (void *)&(new_m->reqsize),
+ &nbytes);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ status = apr_file_close(file);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ new_m->pool = pool;
+ if ((new_m->shmid = shmget(ftok(filename, 1), 0,
+ SHM_R | SHM_W)) < 0) {
+ return errno;
+ }
+ new_m->base = shmat(new_m->shmid, NULL, 0);
+ /* FIXME: handle errors */
+ new_m->usable = new_m->base;
+ new_m->realsize = new_m->reqsize;
+
+ *m = new_m;
+ return APR_SUCCESS;
+
+#else
+ return APR_ENOTIMPL;
+#endif
+ }
+}
+
+APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
+{
+#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM
+ /* FIXME: munmap the segment. */
+ return APR_ENOTIMPL;
+#elif APR_USE_SHMEM_SHMGET
+ /* FIXME: shmdt. */
+ return APR_ENOTIMPL;
+#else
+ return APR_ENOTIMPL;
+#endif
+}
+
+APR_DECLARE(void *) apr_shm_baseaddr_get(const apr_shm_t *m)
+{
+ return m->usable;
+}
+
+APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
+{
+ return m->reqsize;
+}
+
+APR_POOL_IMPLEMENT_ACCESSOR(shm)
+
diff --git a/shmem/unix/shmem.c b/shmem/unix/shmem.c
deleted file mode 100644
index a4b09c82f..000000000
--- a/shmem/unix/shmem.c
+++ /dev/null
@@ -1,331 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr_general.h"
-#include "apr_shmem.h"
-#include "apr_lock.h"
-#include "apr_portable.h"
-#include "apr_errno.h"
-#define APR_WANT_MEMFUNC
-#include "apr_want.h"
-
-/*
- * This is the Unix implementation of shared memory.
- *
- * Currently, this code supports the following shared memory techniques:
- *
- * - mmap on a temporary file
- * - mmap/shm_open on a temporary file (POSIX.1)
- * - mmap with MAP_ANON (4.4BSD)
- * - mmap /dev/zero (SVR4)
- * - shmget (SysV)
- * - create_area (BeOS)
- */
-
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
-#include <sys/mman.h>
-#elif APR_USE_SHMEM_SHMGET
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#if !defined(SHM_R)
-#define SHM_R 0400
-#endif
-#if !defined(SHM_W)
-#define SHM_W 0200
-#endif
-#include <sys/file.h>
-#elif APR_USE_SHMEM_BEOS
-#include <kernel/OS.h>
-#endif
-
-struct apr_shmem_t {
- void *mem;
- void *curmem;
- apr_size_t length;
- apr_lock_t *lock;
- char *filename;
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
- apr_file_t *file;
-#elif APR_USE_SHMEM_MMAP_ANON
- /* Nothing else. */
-#elif APR_USE_SHMEM_SHMGET
- apr_os_file_t file;
-#elif APR_USE_SHMEM_BEOS
- area_id areaid;
-#endif
-};
-
-APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize,
- const char *filename, apr_pool_t *pool)
-{
- apr_shmem_t *new_m;
- void *mem;
-#if APR_USE_SHMEM_SHMGET
- struct shmid_ds shmbuf;
- apr_uid_t uid;
- apr_gid_t gid;
-#endif
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
- apr_status_t status;
-#endif
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || \
- APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_SHMGET
- int tmpfd;
-#endif
-
- new_m = apr_palloc(pool, sizeof(apr_shmem_t));
- if (!new_m)
- return APR_ENOMEM;
-
-/* These implementations are very similar except for opening the file. */
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
- /* FIXME: Ignore error for now. *
- * status = apr_file_remove(filename, pool);*/
- status = APR_SUCCESS;
-
-#if APR_USE_SHMEM_MMAP_TMP
- /* FIXME: Is APR_OS_DEFAULT sufficient? */
- status = apr_file_open(&new_m->file, filename,
- APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT,
- pool);
- if (status != APR_SUCCESS)
- return APR_EGENERAL;
-
- status = apr_os_file_get(&tmpfd, new_m->file);
- status = apr_file_trunc(new_m->file, reqsize);
- if (status != APR_SUCCESS)
- return APR_EGENERAL;
-
-#elif APR_USE_SHMEM_MMAP_SHM
- /* FIXME: Is APR_OS_DEFAULT sufficient? */
- tmpfd = shm_open(filename, O_RDWR | O_CREAT, APR_OS_DEFAULT);
- if (tmpfd == -1)
- return errno;
-
- apr_os_file_put(&new_m->file, &tmpfd, O_READ | O_WRITE | O_CREATE, pool);
- status = apr_file_trunc(new_m->file, reqsize);
- if (status != APR_SUCCESS)
- {
- shm_unlink(filename);
- return APR_EGENERAL;
- }
-#elif APR_USE_SHMEM_MMAP_ZERO
- status = apr_file_open(&new_m->file, "/dev/zero", APR_READ | APR_WRITE,
- APR_OS_DEFAULT, pool);
- if (status != APR_SUCCESS)
- return APR_EGENERAL;
- status = apr_os_file_get(&tmpfd, new_m->file);
-#endif
-
- mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_SHARED, tmpfd, 0);
-
-#elif APR_USE_SHMEM_MMAP_ANON
- mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
-#elif APR_USE_SHMEM_SHMGET
- tmpfd = shmget(IPC_PRIVATE, reqsize, (SHM_R|SHM_W|IPC_CREAT));
- if (tmpfd == -1)
- return errno;
-
- new_m->file = tmpfd;
-
- mem = shmat(new_m->file, NULL, 0);
-
- /* FIXME: Handle errors. */
- if (shmctl(new_m->file, IPC_STAT, &shmbuf) == -1)
- return errno;
-
- apr_current_userid(&uid, &gid, pool);
- shmbuf.shm_perm.uid = uid;
- shmbuf.shm_perm.gid = gid;
-
- if (shmctl(new_m->file, IPC_SET, &shmbuf) == -1)
- return errno;
-
- /* remove in future (once use count hits zero) */
- if (shmctl(new_m->file, IPC_RMID, NULL) == -1)
- return errno;
-
-#elif APR_USE_SHMEM_BEOS
- new_m->area_id = create_area("mm", (void*)&mem, B_ANY_ADDRESS, reqsize,
- B_LAZY_LOCK, B_READ_AREA|B_WRITE_AREA);
- /* FIXME: error code? */
- if (new_m->area_id < 0)
- return APR_EGENERAL;
-
-#endif
-
- new_m->mem = mem;
- new_m->curmem = mem;
- new_m->length = reqsize;
-
- apr_lock_create(&new_m->lock, APR_MUTEX, APR_CROSS_PROCESS,
- APR_LOCK_DEFAULT, NULL, pool);
- if (!new_m->lock)
- return APR_EGENERAL;
-
- *m = new_m;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
-{
-#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
- munmap(m->mem, m->length);
- apr_file_close(m->file);
-#elif APR_USE_SHMEM_MMAP_ANON
- munmap(m->mem, m->length);
-#elif APR_USE_SHMEM_SHMGET
- shmdt(m->mem);
-#elif APR_USE_SHMEM_BEOS
- delete_area(new_m->area_id);
-#endif
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(void *) apr_shm_malloc(apr_shmem_t *m, apr_size_t reqsize)
-{
- void *new;
- new = NULL;
-
- apr_lock_acquire(m->lock);
- /* Do we have enough space? */
- if (((char *)m->curmem - (char *)m->mem + reqsize) <= m->length)
- {
- new = m->curmem;
- m->curmem = (char *)m->curmem + reqsize;
- }
- apr_lock_release(m->lock);
- return new;
-}
-
-APR_DECLARE(void *) apr_shm_calloc(apr_shmem_t *m, apr_size_t reqsize)
-{
- void *new = apr_shm_malloc(m, reqsize);
- if (new)
- memset(new, '\0', reqsize);
- return new;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_free(apr_shmem_t *shared, void *entity)
-{
- /* Without a memory management scheme within our shared memory, it
- * is impossible to implement free. */
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c,
- apr_shm_name_t **name)
-{
-#if APR_USES_ANONYMOUS_SHM
- *name = NULL;
- return APR_ANONYMOUS;
-/* Currently, we are not supporting name based shared memory on Unix
- * systems. This may change in the future however, so I will leave
- * this in here for now. Plus, this gives other platforms a good idea
- * of how to proceed.
- */
-#elif APR_USES_FILEBASED_SHM
-#elif APR_USES_KEYBASED_SHM
-#endif
-}
-
-APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c,
- apr_shm_name_t *name)
-{
-#if APR_USES_ANONYMOUS_SHM
- return APR_ANONYMOUS;
-/* Currently, we are not supporting name based shared memory on Unix
- * systems. This may change in the future however, so I will leave
- * this in here for now. Plus, this gives other platforms a good idea
- * of how to proceed.
- */
-#elif APR_USES_FILEBASED_SHM
-#elif APR_USES_KEYBASED_SHM
-#endif
-}
-
-APR_DECLARE(apr_status_t) apr_shm_open(apr_shmem_t *c)
-{
-#if APR_USES_ANONYMOUS_SHM
-
-/* we don't need to open shared memory segments in child segments, so
- * just return immediately.
- */
- return APR_SUCCESS;
-/* Currently, we are not supporting name based shared memory on Unix
- * systems. This may change in the future however, so I will leave
- * this in here for now. Plus, this gives other platforms a good idea
- * of how to proceed.
- */
-#elif APR_USES_FILEBASED_SHM
-#elif APR_USES_KEYBASED_SHM
-#endif
-}
-
-APR_DECLARE(apr_status_t) apr_shm_avail(apr_shmem_t *m, apr_size_t *size)
-{
- apr_status_t status;
-
- status = APR_ENOSHMAVAIL;
-
- apr_lock_acquire(m->lock);
-
- *size = m->length - ((char *)m->curmem - (char *)m->mem);
- if (*size)
- status = APR_SUCCESS;
-
- apr_lock_release(m->lock);
- return status;
-}