aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/bootstrap_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/bootstrap_hash.c')
-rw-r--r--Python/bootstrap_hash.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
index 47369305ee8..a212f69870e 100644
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -25,6 +25,16 @@
# include <sanitizer/msan_interface.h>
#endif
+#if defined(__APPLE__) && defined(__has_builtin)
+# if __has_builtin(__builtin_available)
+# define HAVE_GETENTRYPY_GETRANDOM_RUNTIME __builtin_available(macOS 10.12, iOS 10.10, tvOS 10.0, watchOS 3.0, *)
+# endif
+#endif
+#ifndef HAVE_GETENTRYPY_GETRANDOM_RUNTIME
+# define HAVE_GETENTRYPY_GETRANDOM_RUNTIME 1
+#endif
+
+
#ifdef Py_DEBUG
int _Py_HashSecret_Initialized = 0;
#else
@@ -208,6 +218,16 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
error.
getentropy() is retried if it failed with EINTR: interrupted by a signal. */
+
+#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
+static int
+py_getentropy(char *buffer, Py_ssize_t size, int raise)
+ __attribute__((availability(macos,introduced=10.12)))
+ __attribute__((availability(ios,introduced=10.0)))
+ __attribute__((availability(tvos,introduced=10.0)))
+ __attribute__((availability(watchos,introduced=3.0)));
+#endif
+
static int
py_getentropy(char *buffer, Py_ssize_t size, int raise)
{
@@ -498,19 +518,21 @@ pyurandom(void *buffer, Py_ssize_t size, int blocking, int raise)
#else
#if defined(PY_GETRANDOM) || defined(PY_GETENTROPY)
+ if (HAVE_GETENTRYPY_GETRANDOM_RUNTIME) {
#ifdef PY_GETRANDOM
- res = py_getrandom(buffer, size, blocking, raise);
+ res = py_getrandom(buffer, size, blocking, raise);
#else
- res = py_getentropy(buffer, size, raise);
+ res = py_getentropy(buffer, size, raise);
#endif
- if (res < 0) {
- return -1;
- }
- if (res == 1) {
- return 0;
- }
- /* getrandom() or getentropy() function is not available: failed with
- ENOSYS or EPERM. Fall back on reading from /dev/urandom. */
+ if (res < 0) {
+ return -1;
+ }
+ if (res == 1) {
+ return 0;
+ }
+ /* getrandom() or getentropy() function is not available: failed with
+ ENOSYS or EPERM. Fall back on reading from /dev/urandom. */
+ } /* end of availability block */
#endif
return dev_urandom(buffer, size, raise);