Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 firefox (50.0.2-1) unstable; urgency=medium
 .
   * New upstream release.
   * Fixes for mfsa2016-{91-92}, also known as:
     CVE-2016-9078, CVE-2016-9079.
 .
   * widget/gtk/mozgtk/mozgtk.c: work around race in system Cairo's XShm usage.
     bz#1271100.
Author: Mike Hommey <glandium@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2016-12-11

Index: firefox-50.0.2/memory/mozjemalloc/jemalloc.c
===================================================================
--- firefox-50.0.2.orig/memory/mozjemalloc/jemalloc.c
+++ firefox-50.0.2/memory/mozjemalloc/jemalloc.c
@@ -2432,7 +2432,34 @@ pages_map(void *addr, size_t size)
 		check_placement = false;
 	}
 #endif
-
+#if defined(__sparc__) && defined(__arch64__)
+    const uintptr_t start = UINT64_C(0x0000070000000000);
+    const uintptr_t end   = UINT64_C(0x0000800000000000);
+    const uintptr_t step  = 8 << 20;
+   /*
+    * Optimization options if there are too many retries in practice:
+    * 1. Examine /proc/self/maps to find an available address. This file is
+    *    not always available, however. In addition, even if we examine
+    *    /proc/self/maps, we may still need to retry several times due to
+    *    racing with other threads.
+    * 2. Use a global/static variable with lock to track the addresses we have
+    *    allocated or tried.
+    */
+    uintptr_t hint;
+    void* region = MAP_FAILED;
+    for (hint = start; region == MAP_FAILED && hint + size <= end; hint += step) {
+	    region = mmap((void*)hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+	    if (region != MAP_FAILED) {
+		    if (((size_t) region + (size - 1)) & 0xffff800000000000) {
+			    if (munmap(region, size)) {
+				    MOZ_ASSERT(errno == ENOMEM);
+			    }
+			    region = MAP_FAILED;
+		    }
+	    }
+    }
+    ret = region;
+#else
 	/*
 	 * We don't use MAP_FIXED here, because it can cause the *replacement*
 	 * of existing mappings, and we only want to create new mappings.
@@ -2440,7 +2467,7 @@ pages_map(void *addr, size_t size)
 	ret = mmap(addr, size, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANON, -1, 0);
 	assert(ret != NULL);
-
+#endif
 	if (ret == MAP_FAILED) {
 		ret = NULL;
 	}
