[kde-solaris] kdesupport/qca/src
Adriaan de Groot
groot at kde.org
Wed Aug 15 22:01:33 CEST 2007
SVN commit 700540 by adridg:
Some benighted systems pass a char * to mlock; there
may be a -D to switch behavior (-D_XDG_4_2 seems like a candidate, but
fails in other system include headers) which I can't find right now.
So check the type of the first argument of mlock(2) and #define
types and casts in the few cases where mlock(2) is used.
CCMAIL: bradh at frogmouth.net
CCMAIL: kde-solaris at kde.org
M +11 -0 CMakeLists.txt
M +8 -3 botantools/botan/alloc_mmap/mmap_mem.cpp
M +9 -1 qca_tools.cpp
--- trunk/kdesupport/qca/src/CMakeLists.txt #700539:700540
@@ -3,6 +3,17 @@
ADD_DEFINITIONS(-DHAVE_SYS_FILIO_H)
ENDIF(HAVE_SYS_FILIO_H)
+INCLUDE(CheckCXXSourceCompiles)
+CHECK_CXX_SOURCE_COMPILES("
+# include <stdlib.h>
+# include <sys/mman.h>
+int main() { void *f = 0; return mlock(f,8); }
+" MLOCK_TAKES_VOID)
+if(NOT MLOCK_TAKES_VOID)
+ MESSAGE(STATUS "mlock(2) does not take a void *")
+ ADD_DEFINITIONS(-DMLOCK_NOT_VOID_PTR)
+endif(NOT MLOCK_TAKES_VOID)
+
# base source files
--- trunk/kdesupport/qca/src/botantools/botan/alloc_mmap/mmap_mem.cpp #700539:700540
@@ -145,6 +145,11 @@
void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n)
{
if(ptr == 0) return;
+#ifdef MLOCK_NOT_VOID_PTR
+# define MLOCK_TYPE_CAST (char *)
+#else
+# define MLOCK_TYPE_CAST
+#endif
const u32bit OVERWRITE_PASSES = 12;
const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0,
@@ -153,14 +158,14 @@
for(u32bit j = 0; j != OVERWRITE_PASSES; j++)
{
std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n);
- if(msync(ptr, n, MS_SYNC))
+ if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
throw MemoryMapping_Failed("Sync operation failed");
}
std::memset(ptr, 0, n);
- if(msync(ptr, n, MS_SYNC))
+ if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
throw MemoryMapping_Failed("Sync operation failed");
- if(munmap(ptr, n))
+ if(munmap(MLOCK_TYPE_CAST ptr, n))
throw MemoryMapping_Failed("Could not unmap file");
}
--- trunk/kdesupport/qca/src/qca_tools.cpp #700539:700540
@@ -34,7 +34,15 @@
{
#ifdef Q_OS_UNIX
bool ok = false;
- void *d = malloc(256);
+#ifdef MLOCK_NOT_VOID_PTR
+# define MLOCK_TYPE char *
+# define MLOCK_TYPE_CAST (MLOCK_TYPE)
+#else
+# define MLOCK_TYPE void *
+# define MLOCK_TYPE_CAST
+#endif
+
+ MLOCK_TYPE d = MLOCK_TYPE_CAST malloc(256);
if(mlock(d, 256) == 0)
{
munlock(d, 256);
More information about the kde-solaris
mailing list