git: 9add38eb0b0e - main - www/{librewolf,tor-browser,waterfox}: Fix runtime on arm64 (gecko-based ports)

From: Vladimir Druzenko <vvd_at_FreeBSD.org>
Date: Mon, 28 Jul 2025 16:28:37 UTC
The branch main has been updated by vvd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9add38eb0b0e4972b3316966c46a6666dd0d36c8

commit 9add38eb0b0e4972b3316966c46a6666dd0d36c8
Author:     Martin Filla <freebsd@sysctl.cz>
AuthorDate: 2025-07-28 16:25:15 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2025-07-28 16:27:55 +0000

    www/{librewolf,tor-browser,waterfox}: Fix runtime on arm64 (gecko-based ports)
    
    Reports of crashes on arm64 with aslr enabled.
    
    PR:     271081 288512 288516 288504
    MFH:    2025Q3
---
 www/librewolf/Makefile                 |  1 +
 www/librewolf/files/patch-bug1876632   | 35 ++++++++++++++++++++++++++++++++++
 www/tor-browser/Makefile               |  1 +
 www/tor-browser/files/patch-bug1876632 | 35 ++++++++++++++++++++++++++++++++++
 www/waterfox/Makefile                  |  1 +
 www/waterfox/files/patch-bug1876632    | 35 ++++++++++++++++++++++++++++++++++
 6 files changed, 108 insertions(+)

diff --git a/www/librewolf/Makefile b/www/librewolf/Makefile
index 1bb46bc7c67a..c3af88bf4969 100644
--- a/www/librewolf/Makefile
+++ b/www/librewolf/Makefile
@@ -2,6 +2,7 @@ PORTNAME=	librewolf
 DISTVERSION=	140.0.4
 LWPATCH=	-1
 DISTVERSIONSUFFIX=	${LWPATCH}.source
+PORTREVISION=	1
 CATEGORIES=	www wayland
 MASTER_SITES=	https://gitlab.com/api/v4/projects/32320088/packages/generic/${PORTNAME}-source/${DISTVERSION}${LWPATCH}/
 
diff --git a/www/librewolf/files/patch-bug1876632 b/www/librewolf/files/patch-bug1876632
new file mode 100644
index 000000000000..3932b1deccc9
--- /dev/null
+++ b/www/librewolf/files/patch-bug1876632
@@ -0,0 +1,35 @@
+commit 4f531ca86d24be5d4de673f6e652ed899151d20c
+Author: Jesper Schmitz Mouridsen <jesper@schmitz.computer>
+Date:   Wed Jul 23 22:01:31 2025 +0000
+
+    Bug 1876632 Fix aslr allocations on FreeBSD r=spidermonkey-reviewers,sfink
+    
+    Without the alignment flag the desired address
+    gets randomized by aslr in a way which causes it to not
+    be aligned. Furthermore the TryToAlignChunk almost always
+    fails. With this fix it never gets to TryToAlignChunk
+    because the flag guarantees upfront alignment.
+    
+    Differential Revision: https://phabricator.services.mozilla.com/D257824
+
+diff --git js/src/gc/Memory.cpp js/src/gc/Memory.cpp
+index e790f1784ede..13639c9a6eb4 100644
+--- js/src/gc/Memory.cpp
++++ js/src/gc/Memory.cpp
+@@ -608,7 +608,16 @@ static void* MapAlignedPagesRandom(size_t length, size_t alignment) {
+   for (size_t i = 1; i <= 1024; ++i) {
+     if (i & 0xf) {
+       uint64_t desired = alignment * GetNumberInRange(minNum, maxNum);
++#  if defined(__FreeBSD__) && defined(__aarch64__)
++      int flags = MAP_PRIVATE | MAP_ANON |
++                  MAP_ALIGNED(mozilla::CeilingLog2Size(alignment));
++      region = MozTaggedAnonymousMmap((void*)(uintptr_t)desired, length,
++                                      int(PageAccess::ReadWrite), flags, -1, 0,
++                                      "js-gc-heap");
++#  else
+       region = MapMemoryAtFuzzy(reinterpret_cast<void*>(desired), length);
++
++#  endif
+       if (!region) {
+         continue;
+       }
diff --git a/www/tor-browser/Makefile b/www/tor-browser/Makefile
index 8c1d5ef06dd6..4ec256a3e68b 100644
--- a/www/tor-browser/Makefile
+++ b/www/tor-browser/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	tor-browser
 DISTVERSION=	14.5.5
+PORTREVISION=	1
 CATEGORIES=	www net security wayland
 TAG_BASE=	8600afeb12fdae895c37618e1386c1a1ac2f5308
 TAG_TOR=	9fe8a13ee4c69f91cd545dc3c575ca8f4851d58e
diff --git a/www/tor-browser/files/patch-bug1876632 b/www/tor-browser/files/patch-bug1876632
new file mode 100644
index 000000000000..3932b1deccc9
--- /dev/null
+++ b/www/tor-browser/files/patch-bug1876632
@@ -0,0 +1,35 @@
+commit 4f531ca86d24be5d4de673f6e652ed899151d20c
+Author: Jesper Schmitz Mouridsen <jesper@schmitz.computer>
+Date:   Wed Jul 23 22:01:31 2025 +0000
+
+    Bug 1876632 Fix aslr allocations on FreeBSD r=spidermonkey-reviewers,sfink
+    
+    Without the alignment flag the desired address
+    gets randomized by aslr in a way which causes it to not
+    be aligned. Furthermore the TryToAlignChunk almost always
+    fails. With this fix it never gets to TryToAlignChunk
+    because the flag guarantees upfront alignment.
+    
+    Differential Revision: https://phabricator.services.mozilla.com/D257824
+
+diff --git js/src/gc/Memory.cpp js/src/gc/Memory.cpp
+index e790f1784ede..13639c9a6eb4 100644
+--- js/src/gc/Memory.cpp
++++ js/src/gc/Memory.cpp
+@@ -608,7 +608,16 @@ static void* MapAlignedPagesRandom(size_t length, size_t alignment) {
+   for (size_t i = 1; i <= 1024; ++i) {
+     if (i & 0xf) {
+       uint64_t desired = alignment * GetNumberInRange(minNum, maxNum);
++#  if defined(__FreeBSD__) && defined(__aarch64__)
++      int flags = MAP_PRIVATE | MAP_ANON |
++                  MAP_ALIGNED(mozilla::CeilingLog2Size(alignment));
++      region = MozTaggedAnonymousMmap((void*)(uintptr_t)desired, length,
++                                      int(PageAccess::ReadWrite), flags, -1, 0,
++                                      "js-gc-heap");
++#  else
+       region = MapMemoryAtFuzzy(reinterpret_cast<void*>(desired), length);
++
++#  endif
+       if (!region) {
+         continue;
+       }
diff --git a/www/waterfox/Makefile b/www/waterfox/Makefile
index ca094e9fc62c..1147c32387fe 100644
--- a/www/waterfox/Makefile
+++ b/www/waterfox/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	waterfox
 DISTVERSION=	6.6.0-beta-3
+PORTREVISION=	1
 PORTEPOCH=	1
 CATEGORIES=	www
 
diff --git a/www/waterfox/files/patch-bug1876632 b/www/waterfox/files/patch-bug1876632
new file mode 100644
index 000000000000..3932b1deccc9
--- /dev/null
+++ b/www/waterfox/files/patch-bug1876632
@@ -0,0 +1,35 @@
+commit 4f531ca86d24be5d4de673f6e652ed899151d20c
+Author: Jesper Schmitz Mouridsen <jesper@schmitz.computer>
+Date:   Wed Jul 23 22:01:31 2025 +0000
+
+    Bug 1876632 Fix aslr allocations on FreeBSD r=spidermonkey-reviewers,sfink
+    
+    Without the alignment flag the desired address
+    gets randomized by aslr in a way which causes it to not
+    be aligned. Furthermore the TryToAlignChunk almost always
+    fails. With this fix it never gets to TryToAlignChunk
+    because the flag guarantees upfront alignment.
+    
+    Differential Revision: https://phabricator.services.mozilla.com/D257824
+
+diff --git js/src/gc/Memory.cpp js/src/gc/Memory.cpp
+index e790f1784ede..13639c9a6eb4 100644
+--- js/src/gc/Memory.cpp
++++ js/src/gc/Memory.cpp
+@@ -608,7 +608,16 @@ static void* MapAlignedPagesRandom(size_t length, size_t alignment) {
+   for (size_t i = 1; i <= 1024; ++i) {
+     if (i & 0xf) {
+       uint64_t desired = alignment * GetNumberInRange(minNum, maxNum);
++#  if defined(__FreeBSD__) && defined(__aarch64__)
++      int flags = MAP_PRIVATE | MAP_ANON |
++                  MAP_ALIGNED(mozilla::CeilingLog2Size(alignment));
++      region = MozTaggedAnonymousMmap((void*)(uintptr_t)desired, length,
++                                      int(PageAccess::ReadWrite), flags, -1, 0,
++                                      "js-gc-heap");
++#  else
+       region = MapMemoryAtFuzzy(reinterpret_cast<void*>(desired), length);
++
++#  endif
+       if (!region) {
+         continue;
+       }