$NetBSD$

* Part of patchset to build electron on NetBSD
* Based on OpenBSD's chromium patches, and
  FreeBSD's electron patches

--- third_party/lzma_sdk/chromium.patch.orig	2025-02-24 19:59:26.000000000 +0000
+++ third_party/lzma_sdk/chromium.patch
@@ -1,138 +1,46 @@
-diff --git "a/lzma2107\\C/7zCrc.c" "b/third_party\\lzma_sdk/7zCrc.c"
-index f186324ddc609..c0cc9bc7812e0 100644
---- "a/lzma2107\\C/7zCrc.c"
-+++ "b/third_party\\lzma_sdk/7zCrc.c"
-@@ -78,20 +78,20 @@ UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const U
-   #if defined(_MSC_VER)
-     #if defined(MY_CPU_ARM64)
-     #if (_MSC_VER >= 1910)
--        #define USE_ARM64_CRC
-+        // #define USE_ARM64_CRC
-     #endif
-     #endif
-   #elif (defined(__clang__) && (__clang_major__ >= 3)) \
-      || (defined(__GNUC__) && (__GNUC__ > 4))
-       #if !defined(__ARM_FEATURE_CRC32)
--        #define __ARM_FEATURE_CRC32 1
-+        // #define __ARM_FEATURE_CRC32 1
-           #if (!defined(__clang__) || (__clang_major__ > 3)) // fix these numbers
--            #define ATTRIB_CRC __attribute__((__target__("arch=armv8-a+crc")))
-+            // #define ATTRIB_CRC __attribute__((__target__("arch=armv8-a+crc")))
-           #endif
-       #endif
-       #if defined(__ARM_FEATURE_CRC32)
--        #define USE_ARM64_CRC
--        #include <arm_acle.h>
-+        // #define USE_ARM64_CRC
-+        // #include <arm_acle.h>
-       #endif
-   #endif
- 
-diff --git "a/lzma2107\\C/CpuArch.c" "b/third_party\\lzma_sdk/CpuArch.c"
-index fa9afe3970b3f..30451fba9b97b 100644
---- "a/lzma2107\\C/CpuArch.c"
-+++ "b/third_party\\lzma_sdk/CpuArch.c"
-@@ -417,7 +417,9 @@ BoolInt CPU_IsSupported_AES (void) { return APPLE_CRYPTO_SUPPORT_VAL; }
- 
- #include <sys/auxv.h>
- 
-+#if !defined(ARMV8_OS_FUCHSIA)
- #define USE_HWCAP
-+#endif // !defined(ARMV8_OS_FUCHSIA)
- 
- #ifdef USE_HWCAP
- 
-diff --git "a/lzma2107\\C/LzFind.c" "b/third_party\\lzma_sdk/LzFind.c"
-index 1b73c28484ccf..36f7330911435 100644
---- "a/lzma2107\\C/LzFind.c"
-+++ "b/third_party\\lzma_sdk/LzFind.c"
-@@ -505,7 +505,7 @@ void MatchFinder_Init(CMatchFinder *p)
- }
- 
- 
--
-+#if 0
- #ifdef MY_CPU_X86_OR_AMD64
-   #if defined(__clang__) && (__clang_major__ >= 8) \
-     || defined(__GNUC__) && (__GNUC__ >= 8) \
-@@ -549,6 +549,7 @@ void MatchFinder_Init(CMatchFinder *p)
-   #endif
- 
- #endif
-+#endif
- 
- /*
- #ifndef ATTRIB_SSE41
-diff --git "a/lzma2107\\C/Sha256.c" "b/third_party\\lzma_sdk/Sha256.c"
-index 8b3983ea7323d..21996848c9156 100644
---- "a/lzma2107\\C/Sha256.c"
-+++ "b/third_party\\lzma_sdk/Sha256.c"
-@@ -32,7 +32,8 @@ This code is based on public domain code from Wei Dai's Crypto++ library. */
-       #define _SHA_SUPPORTED
-     #endif
-   #endif
--#elif defined(MY_CPU_ARM_OR_ARM64)
-+// TODO(crbug.com/1338627): Enable ARM optimizations
-+#elif 0 // defined(MY_CPU_ARM_OR_ARM64)
-   #ifdef _MSC_VER
-     #if _MSC_VER >= 1910
-       #define _SHA_SUPPORTED
+diff -r /Users/waffles/Downloads/lzma2409/Asm/x86/LzmaDecOpt.asm ./Asm/x86/LzmaDecOpt.asm
+42c42,44
+< _TEXT$LZMADECOPT SEGMENT ALIGN(64) 'CODE'
+---
+> ; Make this deterministic
+> ; _TEXT$LZMADECOPT SEGMENT ALIGN(64) 'CODE'
+> LZMADEC SEGMENT ALIGN(64) 'CODE'
+1336c1338
+< _TEXT$LZMADECOPT ENDS
+---
+> LZMADEC ENDS
+diff -r /Users/waffles/Downloads/lzma2409/C/CpuArch.h ./C/CpuArch.h
+413c413,417
+<
+---
+> // Disable MY_CPU_LE_UNALIGN. Although the underlying ISA may be able to load
+> // unaligned words, doing so via pointer casts is undefined behavior in C and
+> // C++, under both strict aliasing and because it is invalid to construct
+> // unaligned pointers. Instead, load the bytes generically and leave optimizing
+> // this to the compiler.
+419,420c423,424
+<     #define MY_CPU_LE_UNALIGN
+<     #define MY_CPU_LE_UNALIGN_64
+---
+>     // #define MY_CPU_LE_UNALIGN
+>     // #define MY_CPU_LE_UNALIGN_64
+diff -r /Users/waffles/Downloads/lzma2409/C/LzFind.c ./C/LzFind.c
+598c598
+<
+---
+> #if 0
+642c642
+<
+---
+> #endif // #if 0
+diff -r /Users/waffles/Downloads/lzma2409/C/Util/SfxSetup/SfxSetup.c ./C/Util/SfxSetup/SfxSetup.c
+13a14,17
+> // SHELLEXECUTEINFO
+> #include <windows.h>
+> #include <shellapi.h>
+>
+144c148
+< #define kSignatureSearchLimit (1 << 22)
+---
+> #define kSignatureSearchLimit (1 << 26)
 
-diff --git a/lzma2107/Asm/arm64/7zAsm.S b/third_party/lzma_sdk/Asm/arm64/7zAsm.S
-index 67d650d9a7c22..aa30a9ef8bf34 100644
---- a/lzma2107/Asm/arm64/7zAsm.S
-+++ b/third_party/lzma_sdk/Asm/arm64/7zAsm.S
-@@ -37,6 +37,19 @@
- #define  REG_ABI_PARAM_1 r1
- #define  REG_ABI_PARAM_2 r2
- 
-+// The .note.gnu.property section is required because Chromium Android builds
-+// utilize the linker flag force-bti.
-+.pushsection .note.gnu.property, "a"
-+.balign 8
-+.long 4
-+.long 0x10
-+.long 0x5
-+.asciz "GNU"
-+.long 0xc0000000
-+.long 4
-+.long ((1 << 0 ) | (1 << 1))
-+.long 0
-+.popsection
- 
- .macro p2_add reg:req, param:req
-         add     \reg, \reg, \param
-diff --git a/lzma2107/Asm/x86/7zAsm.asm b/third_party/lzma_sdk/Asm/x86/7zAsm.asm
-index 9ca25bccd28cf..df2d4cf5820da 100644
---- a/lzma2107/Asm/x86/7zAsm.asm
-+++ b/third_party/lzma_sdk/Asm/x86/7zAsm.asm
-@@ -47,7 +47,7 @@ MY_ASM_START macro
-   else
-     .386
-     .model flat
--    _TEXT$00 SEGMENT PARA PUBLIC 'CODE'
-+    SEVENZ SEGMENT PARA PUBLIC 'CODE'
-   endif
- endm
- 
-diff --git a/lzma2107/Asm/x86/LzmaDecOpt.asm b/third_party/lzma_sdk/Asm/x86/LzmaDecOpt.asm
-index 7e08acc639743..ddbd88ffc2e95 100644
---- a/lzma2107/Asm/x86/LzmaDecOpt.asm
-+++ b/third_party/lzma_sdk/Asm/x86/LzmaDecOpt.asm
-@@ -17,7 +17,7 @@ include 7zAsm.asm
- 
- MY_ASM_START
- 
--_TEXT$LZMADECOPT SEGMENT ALIGN(64) 'CODE'
-+LZMADEC SEGMENT ALIGN(64) 'CODE'
- 
- MY_ALIGN macro num:req
-         align  num
-@@ -1298,6 +1298,6 @@ fin:
- MY_POP_PRESERVED_ABI_REGS
- MY_ENDP
- 
--_TEXT$LZMADECOPT ENDS
-+LZMADEC ENDS
- 
- end
