[PATCH] Trap SIGBUS to handle truncated shared memory segments

Keith Packard keithp at keithp.com
Sun Nov 3 23:05:26 CET 2013


Mark Kettenis <mark.kettenis at xs4all.nl> writes:

> Any reason why you're not using MAP_FIXED instead of doing this
> munmap/mmap dance?

Nope, I just forgot about that flag. Thanks!

Here's a diff from the posted version; I've also sent an updated version
of the patch.

diff --git a/os/busfault.c b/os/busfault.c
index 05f610e..45ee074 100644
--- a/os/busfault.c
+++ b/os/busfault.c
@@ -121,15 +121,10 @@ busfault_sigaction(int sig, siginfo_t *info, void *param)
      * /dev/zero over that area and keep going
      */
 
-    if (munmap(busfault->addr, busfault->size) < 0)
-        goto panic;
-
-    new_addr = mmap(busfault->addr, busfault->size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+    new_addr = mmap(busfault->addr, busfault->size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, -1, 0);
 
-    if (new_addr != busfault->addr) {
-        munmap(new_addr, busfault->size);
+    if (new_addr == MAP_FAILED)
         goto panic;
-    }
 
     return;
 panic:


-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20131103/5b5acd08/attachment.pgp>


More information about the xorg-devel mailing list