Boost logo

Boost-Commit :

From: igaztanaga_at_[hidden]
Date: 2007-08-25 14:04:14


Author: igaztanaga
Date: 2007-08-25 14:04:13 EDT (Sat, 25 Aug 2007)
New Revision: 38946
URL: http://svn.boost.org/trac/boost/changeset/38946

Log:
#1211: Interprocess tests hang when run in parallel
#1080 boost::interprocess win32 global file mapping issue
Text files modified:
   trunk/boost/interprocess/detail/win32_api.hpp | 50 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 47 insertions(+), 3 deletions(-)

Modified: trunk/boost/interprocess/detail/win32_api.hpp
==============================================================================
--- trunk/boost/interprocess/detail/win32_api.hpp (original)
+++ trunk/boost/interprocess/detail/win32_api.hpp 2007-08-25 14:04:13 EDT (Sat, 25 Aug 2007)
@@ -22,8 +22,11 @@
 # include <stddef.h>
 # include <stdarg.h>
 # include <boost/detail/interlocked.hpp>
+# if !defined(__MINGW32__)
+# pragma comment( lib, "advapi32.lib" )//auto-unlink security features
+# endif
 #else
-# error "This file can only be included in Windows OS"
+# error "This file can only be included in Windows OS"
 #endif
 
 //The structures used in Interprocess with the
@@ -109,6 +112,7 @@
 static const unsigned long lockfile_fail_immediately = 1;
 static const unsigned long lockfile_exclusive_lock = 2;
 static const unsigned long error_lock_violation = 33;
+static const unsigned long security_descriptor_revision = 1;
 
 } //namespace winapi {
 } //namespace interprocess {
@@ -178,7 +182,28 @@
    unsigned long Type;
 };
 
+typedef struct _interprocess_acl
+{
+ unsigned char AclRevision;
+ unsigned char Sbz1;
+ unsigned short AclSize;
+ unsigned short AceCount;
+ unsigned short Sbz2;
+} interprocess_acl;
+
+typedef struct _interprocess_security_descriptor
+{
+ unsigned char Revision;
+ unsigned char Sbz1;
+ unsigned short Control;
+ void *Owner;
+ void *Group;
+ interprocess_acl *Sacl;
+ interprocess_acl *Dacl;
+} interprocess_security_descriptor;
+
 //Some windows API declarations
+extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
 extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
 extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
 extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError();
@@ -223,7 +248,10 @@
 extern "C" __declspec(dllimport) int __stdcall LockFileEx(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);
 extern "C" __declspec(dllimport) int __stdcall UnlockFileEx(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);
 extern "C" __declspec(dllimport) int __stdcall WriteFile(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped);
-
+extern "C" __declspec(dllimport) int __stdcall InitializeSecurityDescriptor
+ (void *pSecurityDescriptor, unsigned long dwRevision);
+extern "C" __declspec(dllimport) int __stdcall SetSecurityDescriptorDacl
+ ( void *pSecurityDescriptor, int bDaclPresent, interprocess_acl *pDacl, int bDaclDefaulted);
 /*
 extern "C" __declspec(dllimport) long __stdcall InterlockedIncrement( long volatile * );
 extern "C" __declspec(dllimport) long __stdcall InterlockedDecrement( long volatile * );
@@ -266,6 +294,9 @@
 static inline unsigned long get_current_thread_id()
 { return GetCurrentThreadId(); }
 
+static inline unsigned long get_current_process_id()
+{ return GetCurrentProcessId(); }
+
 static inline unsigned int close_handle(void* handle)
 { return CloseHandle(handle); }
 
@@ -313,7 +344,20 @@
 { return OpenSemaphoreA(semaphore_all_access, 1, name); }
 
 static inline void * create_file_mapping (void * handle, unsigned long access, unsigned long high_size, unsigned long low_size, const char * name)
-{ return CreateFileMappingA (handle, 0, access, high_size, low_size, name); }
+{
+ interprocess_security_attributes sa;
+ interprocess_security_descriptor sd;
+
+ if(!InitializeSecurityDescriptor(&sd, security_descriptor_revision))
+ return 0;
+ if(!SetSecurityDescriptorDacl(&sd, true, 0, false))
+ return 0;
+ sa.lpSecurityDescriptor = &sd;
+ sa.nLength = sizeof(interprocess_security_attributes);
+ sa.bInheritHandle = false;
+ return CreateFileMappingA (handle, &sa, access, high_size, low_size, name);
+ //return CreateFileMappingA (handle, 0, access, high_size, low_size, name);
+}
 
 static inline void * open_file_mapping (unsigned long access, const char *name)
 { return OpenFileMappingA (access, 0, name); }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk