summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/apr_portable.h28
-rw-r--r--shmem/win32/shm.c32
2 files changed, 60 insertions, 0 deletions
diff --git a/include/apr_portable.h b/include/apr_portable.h
index 11ef5d91d..bda6aec73 100644
--- a/include/apr_portable.h
+++ b/include/apr_portable.h
@@ -78,6 +78,7 @@
#include "apr_proc_mutex.h"
#include "apr_time.h"
#include "apr_dso.h"
+#include "apr_shm.h"
#if APR_HAVE_DIRENT_H
#include <dirent.h>
@@ -107,6 +108,7 @@ typedef DWORD apr_os_threadkey_t;
typedef FILETIME apr_os_imp_time_t;
typedef SYSTEMTIME apr_os_exp_time_t;
typedef HANDLE apr_os_dso_handle_t;
+typedef HANDLE apr_os_shm_t;
#elif defined(OS2)
typedef HFILE apr_os_file_t;
@@ -121,6 +123,7 @@ typedef PULONG apr_os_threadkey_t;
typedef struct timeval apr_os_imp_time_t;
typedef struct tm apr_os_exp_time_t;
typedef HMODULE apr_os_dso_handle_t;
+typedef void* apr_os_shm_t;
#elif defined(__BEOS__)
#include <kernel/OS.h>
@@ -143,6 +146,7 @@ typedef int apr_os_threadkey_t;
typedef struct timeval apr_os_imp_time_t;
typedef struct tm apr_os_exp_time_t;
typedef image_id apr_os_dso_handle_t;
+typedef void* apr_os_shm_t;
#elif defined(NETWARE)
typedef int apr_os_file_t;
@@ -157,6 +161,7 @@ typedef NXKey_t apr_os_threadkey_t;
typedef struct timeval apr_os_imp_time_t;
typedef struct tm apr_os_exp_time_t;
typedef void * apr_os_dso_handle_t;
+typedef void* apr_os_shm_t;
#else
/* Any other OS should go above this one. This is the lowest common
@@ -201,6 +206,7 @@ typedef NSModule apr_os_dso_handle_t;
#else
typedef void * apr_os_dso_handle_t;
#endif
+typedef void* apr_os_shm_t;
#endif
@@ -280,6 +286,14 @@ APR_DECLARE(apr_status_t) apr_os_exp_time_get(apr_os_exp_time_t **ostime,
APR_DECLARE(apr_status_t) apr_os_imp_time_get(apr_os_imp_time_t **ostime,
apr_time_t *aprtime);
+/**
+ * convert the shm from apr type to os specific type.
+ * @param osshm The os specific shm representation
+ * @param shm The apr shm to convert.
+ */
+APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
+ apr_shm_t *shm);
+
#if APR_HAS_THREADS || defined(DOXYGEN)
/**
* @defgroup APR_PORT_Thread Thread portability Routines
@@ -423,6 +437,19 @@ APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_exploded_time_t *aprtime,
apr_os_exp_time_t **ostime,
apr_pool_t *cont);
+/**
+ * convert the shared memory from os specific type to apr type.
+ * @param shm The apr shm representation of osshm
+ * @param osshm The os specific shm identity
+ * @param cont The pool to use if it is needed.
+ * @remark On fork()ed architectures, this is typically nothing more than
+ * the memory block mapped. On non-fork architectures, this is typically
+ * some internal handle to pass the mapping from process to process.
+ */
+APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **shm,
+ apr_os_shm_t *osshm,
+ apr_pool_t *cont);
+
#if APR_HAS_DSO || defined(DOXYGEN)
/**
@@ -449,6 +476,7 @@ APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso,
/** @} */
#endif /* APR_HAS_DSO */
+
#ifdef __cplusplus
}
#endif
diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c
index 754049067..8f9b2b7aa 100644
--- a/shmem/win32/shm.c
+++ b/shmem/win32/shm.c
@@ -264,3 +264,35 @@ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m)
{
return m->length;
}
+
+APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
+ apr_shm_t *shm)
+{
+ *osshm = shm->hMap;
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **m,
+ apr_os_shm_t *osshm,
+ apr_pool_t *pool)
+{
+ void* base;
+ base = MapViewOfFile(*osshm, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
+ if (!base) {
+ return apr_get_os_error();
+ }
+
+ *m = (apr_shm_t *) apr_palloc(pool, sizeof(apr_shm_t));
+ (*m)->pool = pool;
+ (*m)->hMap = *osshm;
+ (*m)->memblk = base;
+ (*m)->usrmem = (char*)base + sizeof(memblock_t);
+ /* Real (*m)->mem->size could be recovered with VirtualQuery */
+ (*m)->size = (*m)->memblk->size;
+ (*m)->length = (*m)->memblk->length;
+
+ apr_pool_cleanup_register((*m)->pool, *m,
+ shm_cleanup, apr_pool_cleanup_null);
+ return APR_SUCCESS;
+}
+