Module: xenomai-head
Branch: master
Commit: b2ea4145342b4d89b55f83b4d8f264c295ad2cf6
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=b2ea4145342b4d89b55f83b4d8f264c295ad2cf6

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Aug 29 15:06:39 2010 +0200

sem_heap: map an inaccessible heap upon fork.

This prevents private mutexes from corrupting memory if they are
used after fork.

---

 src/skins/common/sem_heap.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/skins/common/sem_heap.c b/src/skins/common/sem_heap.c
index 189272e..2355dd8 100644
--- a/src/skins/common/sem_heap.c
+++ b/src/skins/common/sem_heap.c
@@ -75,15 +75,21 @@ static void unmap_on_fork(void)
           Otherwise the global heap would be used instead, which
           leads to unwanted effects.
 
-          We set xeno_sem_heap[PRIVATE] to NULL. On machines with an
-          MMU, any reference to the private heap prior to
-          re-binding will cause a segmentation fault.
-
           On machines without an MMU, there is no such thing as fork.
-       */
 
-       munmap((void *)xeno_sem_heap[PRIVATE], private_hdesc.size);
-       xeno_sem_heap[PRIVATE] = NULL;
+          As a protection against access to the heaps by the fastsync
+          code, we set up an inaccessible mapping where the heap was, so
+          that access to these addresses will cause a segmentation
+          fault.
+       */
+#if defined(CONFIG_XENO_FASTSYNCH)
+       void *addr = mmap((void *)xeno_sem_heap[PRIVATE],
+                         private_hdesc.size, PROT_NONE,
+                         MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+       if (addr != (void *)xeno_sem_heap[PRIVATE])
+#endif /* CONFIG_XENO_FASTSYNCH */
+               munmap((void *)xeno_sem_heap[PRIVATE], private_hdesc.size);
+       xeno_sem_heap[PRIVATE] = 0UL;
        init_private_heap = PTHREAD_ONCE_INIT;
 }
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to