Gentoo Archives: gentoo-commits

From: "Chi-Thanh Christopher Nguyen (chithanh)" <chithanh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in www-plugins/gnash/files: gnash-0.8.10-jemalloc-aslr-fix.patch
Date: Wed, 29 Feb 2012 19:13:37
Message-Id: 20120229191322.C70B42004C@flycatcher.gentoo.org
chithanh    12/02/29 19:13:22

  Added:                gnash-0.8.10-jemalloc-aslr-fix.patch
  Log:
  Add patch to fix broken jemalloc, bug #405993.
  
  (Portage version: 2.2.0_alpha89/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  www-plugins/gnash/files/gnash-0.8.10-jemalloc-aslr-fix.patch

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-plugins/gnash/files/gnash-0.8.10-jemalloc-aslr-fix.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-plugins/gnash/files/gnash-0.8.10-jemalloc-aslr-fix.patch?rev=1.1&content-type=text/plain

Index: gnash-0.8.10-jemalloc-aslr-fix.patch
===================================================================
diff -Naur gnash-0.8.10.alt/libbase/jemalloc.c gnash-0.8.10/libbase/jemalloc.c
--- gnash-0.8.10.alt/libbase/jemalloc.c	2012-02-07 09:39:41.000000000 +0100
+++ gnash-0.8.10/libbase/jemalloc.c	2012-02-24 18:36:47.000000000 +0100
@@ -429,7 +429,7 @@
 static const bool __isthreaded = true;
 #endif
 
-#if defined(MOZ_MEMORY_SOLARIS) && defined(MAP_ALIGN) && !defined(JEMALLOC_NEVER_USES_MAP_ALIGN)
+#if defined(MOZ_MEMORY_SOLARIS) && defined(MAP_ALIGN) && !defined(JEMALLOC_NEVER_USES_MAP_ALIGN) || defined(MOZ_MEMORY_LINUX)
 #define JEMALLOC_USES_MAP_ALIGN	 /* Required on Solaris 10. Might improve performance elsewhere. */
 #endif
 
@@ -2238,6 +2238,7 @@
 	 * We don't use MAP_FIXED here, because it can cause the *replacement*
 	 * of existing mappings, and we only want to create new mappings.
 	 */
+#ifdef MOZ_MEMORY_SOLARIS
 #ifdef MALLOC_PAGEFILE
 	if (pfd != -1) {
 		ret = mmap((void *)alignment, size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
@@ -2252,6 +2253,31 @@
 
 	if (ret == MAP_FAILED)
 		ret = NULL;
+#else /* !MOZ_MEMORY_SOLARIS */
+#ifdef MALLOC_PAGEFILE
+	if (pfd != -1) {
+		ret = mmap((void *)alignment, size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
+		    MAP_NOSYNC, pfd, 0);
+	} else
+#endif
+	       {
+		ret = mmap(NULL, size + alignment, PROT_READ | PROT_WRITE, MAP_PRIVATE |
+		    MAP_NOSYNC | MAP_ANON, -1, 0);
+	}
+	assert(ret != NULL);
+
+	if (ret == MAP_FAILED)
+		return NULL;
+	
+	uintptr_t aligned_ret;
+	size_t extra_size;
+	aligned_ret = (uintptr_t)ret + alignment - 1;
+	aligned_ret &= ~(alignment - 1);
+	extra_size = aligned_ret - (uintptr_t)ret;
+	munmap(ret, extra_size);
+	munmap(ret + extra_size + size, alignment - extra_size);
+	ret = (void*)aligned_ret;
+#endif /* ifdef MOZ_MEMORY_SOLARIS*/
 	return (ret);
 }
 #endif