Module: xenomai-2.5 Branch: master Commit: 7575440bef2387511236f86b8d0abc94a4e8ea02 URL: http://git.xenomai.org/?p=xenomai-2.5.git;a=commit;h=7575440bef2387511236f86b8d0abc94a4e8ea02
Author: Gilles Chanteperdrix <[email protected]> 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 23678cd..5cc27fc 100644 --- a/src/skins/common/sem_heap.c +++ b/src/skins/common/sem_heap.c @@ -82,15 +82,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 [email protected] https://mail.gna.org/listinfo/xenomai-git
