apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1533979 - in /apr/apr/trunk: CHANGES include/apr_shm.h shmem/beos/shm.c shmem/os2/shm.c shmem/unix/shm.c shmem/win32/shm.c
Date Sun, 20 Oct 2013 20:50:11 GMT
Author: trawick
Date: Sun Oct 20 20:50:11 2013
New Revision: 1533979

URL: http://svn.apache.org/r1533979
Log:
Follow-up to r1531768:

Add apr_shm_create_ex() and apr_shm_attach_ex(), which
provide the ability to select the Global or Local
namespace on Windows.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_shm.h
    apr/apr/trunk/shmem/beos/shm.c
    apr/apr/trunk/shmem/os2/shm.c
    apr/apr/trunk/shmem/unix/shm.c
    apr/apr/trunk/shmem/win32/shm.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sun Oct 20 20:50:11 2013
@@ -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]

Modified: apr/apr/trunk/include/apr_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_shm.h?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_shm.h (original)
+++ apr/apr/trunk/include/apr_shm.h Sun Oct 20 20:50:11 2013
@@ -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_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_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.

Modified: apr/apr/trunk/shmem/beos/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/beos/shm.c?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/shmem/beos/shm.c (original)
+++ apr/apr/trunk/shmem/beos/shm.c Sun Oct 20 20:50:11 2013
@@ -71,6 +71,15 @@ APR_DECLARE(apr_status_t) apr_shm_create
     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
     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);

Modified: apr/apr/trunk/shmem/os2/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/os2/shm.c?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/shmem/os2/shm.c (original)
+++ apr/apr/trunk/shmem/os2/shm.c Sun Oct 20 20:50:11 2013
@@ -56,6 +56,15 @@ APR_DECLARE(apr_status_t) apr_shm_create
     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
     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;

Modified: apr/apr/trunk/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/unix/shm.c?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/shmem/unix/shm.c (original)
+++ apr/apr/trunk/shmem/unix/shm.c Sun Oct 20 20:50:11 2013
@@ -365,6 +365,15 @@ APR_DECLARE(apr_status_t) apr_shm_create
     }
 }
 
+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_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);

Modified: apr/apr/trunk/shmem/win32/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/win32/shm.c?rev=1533979&r1=1533978&r2=1533979&view=diff
==============================================================================
--- apr/apr/trunk/shmem/win32/shm.c (original)
+++ apr/apr/trunk/shmem/win32/shm.c Sun Oct 20 20:50:11 2013
@@ -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
         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
          * 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
     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(
     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
     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);



Mime
View raw message