[Mono-dev] [PATCH] Don't depend on madvise

Andreas Färber andreas.faerber at web.de
Fri Nov 20 12:28:27 EST 2009


Hello,

Mono appears to check for presence of the madvise function but uses it  
unconditionally in mono-mmap.c.

If madvise was not detected, the attached patch assumes POSIX- 
compliant posix_madvise to be present instead.
Note that posix_madvise does not seem to have an equivalent to  
MADV_FREE.
http://www.opengroup.org/onlinepubs/000095399/functions/posix_madvise.html

This patch has been in my queue for some months - it's necessary for  
Haiku and didn't seem to break the Unices I tested at the time (OSX,  
Solaris). Please review.

Regards,

Andreas

-- 
diff --git a/mono/utils/mono-mmap.c b/mono/utils/mono-mmap.c
index 7976ce1..daed69a 100644
--- a/mono/utils/mono-mmap.c
+++ b/mono/utils/mono-mmap.c
@@ -380,8 +380,12 @@ mono_mprotect (void *addr, size_t length, int  
flags)
  			memset (addr, 0, length);
  #else
  		memset (addr, 0, length);
+#ifdef HAVE_MADVISE
  		madvise (addr, length, MADV_DONTNEED);
  		madvise (addr, length, MADV_FREE);
+#else
+		posix_madvise (addr, length, POSIX_MADV_DONTNEED);
+#endif
  #endif
  	}
  	return mprotect (addr, length, prot);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: madvise.diff
Type: application/octet-stream
Size: 511 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20091120/a97a61b5/attachment.obj 
-------------- next part --------------



More information about the Mono-devel-list mailing list