summaryrefslogtreecommitdiffstats
path: root/Modules/_hacl
diff options
context:
space:
mode:
authoraeiouaeiouaeiouaeiouaeiouaeiou <aeioudev@outlook.com>2024-12-18 06:14:16 (GMT)
committerGitHub <noreply@github.com>2024-12-18 06:14:16 (GMT)
commit329165639f9ac00ba64f6493dbcafcef6955e2cb (patch)
tree679370ce81359e6b71cb8d8804fc19af66410f7c /Modules/_hacl
parent5892853fb71acd6530e1e241a9a4bcf71a61fb21 (diff)
downloadcpython-329165639f9ac00ba64f6493dbcafcef6955e2cb.zip
cpython-329165639f9ac00ba64f6493dbcafcef6955e2cb.tar.gz
cpython-329165639f9ac00ba64f6493dbcafcef6955e2cb.tar.bz2
gh-127897: fix HACL* build on macOS/Catalina (GH-127932)
gh-127897: Update HACL* module from upstream sources to get: - Lib_Memzero0.c: don't use memset_s() on macOS <10.9 - Use _mm_malloc() for KRML_ALIGNED_MALLOC on macOS <10.15 - Add LEGACY_MACOS macros, use _mm_free() for KRML_ALIGNED_FREE on macOS <10.15
Diffstat (limited to 'Modules/_hacl')
-rw-r--r--Modules/_hacl/Lib_Memzero0.c6
-rw-r--r--Modules/_hacl/include/krml/internal/target.h18
2 files changed, 23 insertions, 1 deletions
diff --git a/Modules/_hacl/Lib_Memzero0.c b/Modules/_hacl/Lib_Memzero0.c
index 5c269d2..f01568a 100644
--- a/Modules/_hacl/Lib_Memzero0.c
+++ b/Modules/_hacl/Lib_Memzero0.c
@@ -8,6 +8,10 @@
#include <windows.h>
#endif
+#if defined(__APPLE__) && defined(__MACH__)
+#include <AvailabilityMacros.h>
+#endif
+
#if (defined(__APPLE__) && defined(__MACH__)) || defined(__linux__)
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
@@ -37,7 +41,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {
#ifdef _WIN32
SecureZeroMemory(dst, len_);
- #elif defined(__APPLE__) && defined(__MACH__)
+ #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
memset_s(dst, len_, 0, len_);
#elif (defined(__linux__) && !defined(LINUX_NO_EXPLICIT_BZERO)) || defined(__FreeBSD__)
explicit_bzero(dst, len_);
diff --git a/Modules/_hacl/include/krml/internal/target.h b/Modules/_hacl/include/krml/internal/target.h
index fd74d3d..9b403c3 100644
--- a/Modules/_hacl/include/krml/internal/target.h
+++ b/Modules/_hacl/include/krml/internal/target.h
@@ -19,6 +19,20 @@
# define inline __inline__
#endif
+/* There is no support for aligned_alloc() in macOS before Catalina, so
+ * let's make a macro to use _mm_malloc() and _mm_free() functions
+ * from mm_malloc.h. */
+#if defined(__APPLE__) && defined(__MACH__)
+# include <AvailabilityMacros.h>
+# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
+ (MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
+# include <mm_malloc.h>
+# define LEGACY_MACOS
+# else
+# undef LEGACY_MACOS
+#endif
+#endif
+
/******************************************************************************/
/* Macros that KaRaMeL will generate. */
/******************************************************************************/
@@ -133,6 +147,8 @@
defined(_MSC_VER) || \
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
# define KRML_ALIGNED_MALLOC(X, Y) _aligned_malloc(Y, X)
+# elif defined(LEGACY_MACOS)
+# define KRML_ALIGNED_MALLOC(X, Y) _mm_malloc(Y, X)
# else
# define KRML_ALIGNED_MALLOC(X, Y) aligned_alloc(X, Y)
# endif
@@ -150,6 +166,8 @@
defined(_MSC_VER) || \
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
# define KRML_ALIGNED_FREE(X) _aligned_free(X)
+# elif defined(LEGACY_MACOS)
+# define KRML_ALIGNED_FREE(X) _mm_free(X)
# else
# define KRML_ALIGNED_FREE(X) free(X)
# endif