[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Patch for mmap problem in KConfigBackEnd, Bug #72586
From:       Waldo Bastian <bastian () kde ! org>
Date:       2004-01-15 22:15:15
Message-ID: 200401152315.16067.bastian () kde ! org
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu January 15 2004 14:20, Dr. Juergen Pfennig wrote:
> About the current implementation in kconfigbackend.cpp: mmap() is used
> always to read conf files. Interrestingly the author was aware of a SIGBUS
> problem and tried to recover from the SIGBUS. BUT THIS DOES NOT WORK. Maybe
> it never worked? Or maybe it's a compiler optimization problem.

Ok, after reading up on "how to recover from SIGBUS on mmap" I now have a 
better patch :-)

Please test.

Darwin, Solaris and BSD developers: Does this patch compile for you?

Cheers,
Waldo
- -- 
bastian@kde.org -=|[ KDE: K Desktop for the Enterprise ]|=- bastian@suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFABxDzN4pvrENfboIRAuuoAKCUHW4DDEC/xyg+8i7FHE+6DSFiegCfTmcO
ptbIKTNbC+wq5WWRKxVWzy4=
=/szJ
-----END PGP SIGNATURE-----

["kconfig_sigbus.patch" (text/x-diff)]

Index: kconfigbackend.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigbackend.cpp,v
retrieving revision 1.89
diff -u -r1.89 kconfigbackend.cpp
--- kconfigbackend.cpp	29 Nov 2003 14:46:55 -0000	1.89
+++ kconfigbackend.cpp	15 Jan 2004 22:08:36 -0000
@@ -32,6 +32,7 @@
 #endif
 #include <fcntl.h>
 #include <signal.h>
+#include <setjmp.h>
 
 #include <qdir.h>
 #include <qfileinfo.h>
@@ -366,14 +367,21 @@
 }
 
 #ifdef HAVE_MMAP
+static const char *mmap_map;
 #ifdef SIGBUS
-static const char **mmap_pEof;
+static sigjmp_buf jmpbuf;
+static volatile sig_atomic_t mmap_can_jump = 0;
+static void (*mmap_old_sighandler)(int) = 0;
 
-static void mmap_sigbus_handler(int)
+static void mmap_sigbus_handler (int sig)
 {
-   *mmap_pEof = 0;
-   write(2, "SIGBUS\n", 7);
-   signal(SIGBUS, mmap_sigbus_handler);
+   if (!mmap_can_jump)
+   {
+      signal (sig, SIG_DFL);
+      raise (sig);
+   }
+   mmap_can_jump = 0;
+   siglongjmp (jmpbuf, 1);
 }
 #endif
 #endif
@@ -382,7 +390,9 @@
 					      KEntryMap *pWriteBackMap,
 					      bool bGlobal, bool bDefault)
 {
-   void (*old_sighandler)(int) = 0;
+   const char *s; // May get clobbered by sigsetjump, but we don't use them afterwards.
+   const char *eof; // May get clobbered by sigsetjump, but we don't use them afterwards.
+   QByteArray data;
 
    if (!rFile.isOpen()) // come back, if you have real work for us ;->
       return;
@@ -394,23 +404,26 @@
 
    QCString aCurrentGroup("<default>");
 
-   const char *s, *eof;
-   QByteArray data;
-
    unsigned int ll = localeString.length();
 
 #ifdef HAVE_MMAP
-   const char *map = ( const char* ) mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE,
+   mmap_map = ( const char* ) mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE,
                                           rFile.handle(), 0);
 
-   if (map)
+   if (mmap_map)
    {
-      s = map;
+      s = mmap_map;
       eof = s + rFile.size();
 
 #ifdef SIGBUS
-      mmap_pEof = &eof;
-      old_sighandler = signal(SIGBUS, mmap_sigbus_handler);
+      mmap_old_sighandler = signal(SIGBUS, mmap_sigbus_handler);
+      mmap_can_jump = 1;
+      if (sigsetjmp (jmpbuf, 1))
+      {
+         munmap(( char* )mmap_map, rFile.size());
+         signal (SIGBUS, mmap_old_sighandler);
+         return;
+      }
 #endif
    }
    else
@@ -641,11 +654,11 @@
       bFileImmutable = true;
 
 #ifdef HAVE_MMAP
-   if (map)
+   if (mmap_map)
    {
-      munmap(( char* )map, rFile.size());
+      munmap(( char* )mmap_map, rFile.size());
 #ifdef SIGBUS
-      signal(SIGBUS, old_sighandler);
+      signal(SIGBUS, mmap_old_sighandler);
 #endif
    }
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic