Skip to content

Commit 3291656

Browse files
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
1 parent 5892853 commit 3291656

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Misc/sbom.spdx.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_hacl/Lib_Memzero0.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <windows.h>
99
#endif
1010

11+
#if defined(__APPLE__) && defined(__MACH__)
12+
#include <AvailabilityMacros.h>
13+
#endif
14+
1115
#if (defined(__APPLE__) && defined(__MACH__)) || defined(__linux__)
1216
#define __STDC_WANT_LIB_EXT1__ 1
1317
#include <string.h>
@@ -37,7 +41,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {
3741

3842
#ifdef _WIN32
3943
SecureZeroMemory(dst, len_);
40-
#elif defined(__APPLE__) && defined(__MACH__)
44+
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
4145
memset_s(dst, len_, 0, len_);
4246
#elif (defined(__linux__) && !defined(LINUX_NO_EXPLICIT_BZERO)) || defined(__FreeBSD__)
4347
explicit_bzero(dst, len_);

Modules/_hacl/include/krml/internal/target.h

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
# define inline __inline__
2020
#endif
2121

22+
/* There is no support for aligned_alloc() in macOS before Catalina, so
23+
* let's make a macro to use _mm_malloc() and _mm_free() functions
24+
* from mm_malloc.h. */
25+
#if defined(__APPLE__) && defined(__MACH__)
26+
# include <AvailabilityMacros.h>
27+
# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
28+
(MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
29+
# include <mm_malloc.h>
30+
# define LEGACY_MACOS
31+
# else
32+
# undef LEGACY_MACOS
33+
#endif
34+
#endif
35+
2236
/******************************************************************************/
2337
/* Macros that KaRaMeL will generate. */
2438
/******************************************************************************/
@@ -133,6 +147,8 @@
133147
defined(_MSC_VER) || \
134148
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
135149
# define KRML_ALIGNED_MALLOC(X, Y) _aligned_malloc(Y, X)
150+
# elif defined(LEGACY_MACOS)
151+
# define KRML_ALIGNED_MALLOC(X, Y) _mm_malloc(Y, X)
136152
# else
137153
# define KRML_ALIGNED_MALLOC(X, Y) aligned_alloc(X, Y)
138154
# endif
@@ -150,6 +166,8 @@
150166
defined(_MSC_VER) || \
151167
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
152168
# define KRML_ALIGNED_FREE(X) _aligned_free(X)
169+
# elif defined(LEGACY_MACOS)
170+
# define KRML_ALIGNED_FREE(X) _mm_free(X)
153171
# else
154172
# define KRML_ALIGNED_FREE(X) free(X)
155173
# endif

0 commit comments

Comments
 (0)