]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/uuid/detail/random_provider_detect_platform.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / uuid / detail / random_provider_detect_platform.hpp
1 //
2 // Copyright (c) 2017 James E. King III
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // https://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Platform-specific random entropy provider platform detection
9 //
10
11 #ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
12 #define BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
13
14 #include <boost/predef/library/c/cloudabi.h>
15 #include <boost/predef/library/c/gnu.h>
16 #include <boost/predef/os/bsd/open.h>
17 #include <boost/predef/os/windows.h>
18
19 // Note: Don't use Boost.Predef to detect Linux and Android as it may give different results depending on header inclusion order.
20 // https://github.com/boostorg/predef/issues/81#issuecomment-413329061
21 #if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
22 #include <sys/syscall.h>
23 #if defined(SYS_getrandom)
24 #define BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM
25 #endif // defined(SYS_getrandom)
26 #endif
27
28 // On Linux, getentropy is implemented via getrandom. If we know that getrandom is not supported by the kernel, getentropy
29 // will certainly not work, even if libc provides a wrapper function for it. There is no reason, ever, to use getentropy on that platform.
30 #if !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY) && (defined(__linux__) || defined(__linux) || defined(linux) || defined(__ANDROID__))
31 #define BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY
32 #endif
33
34 //
35 // Platform Detection - will load in the correct header and
36 // will define the class <tt>random_provider_base</tt>.
37 //
38
39 #if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_LIB_C_CLOUDABI
40 # define BOOST_UUID_RANDOM_PROVIDER_ARC4RANDOM
41 # define BOOST_UUID_RANDOM_PROVIDER_NAME arc4random
42
43 #elif BOOST_OS_WINDOWS
44 # include <boost/winapi/config.hpp>
45 # if BOOST_WINAPI_PARTITION_APP_SYSTEM && \
46 !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT) && \
47 !defined(_WIN32_WCE) && \
48 (BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6)
49 # define BOOST_UUID_RANDOM_PROVIDER_BCRYPT
50 # define BOOST_UUID_RANDOM_PROVIDER_NAME bcrypt
51
52 # elif BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
53 # define BOOST_UUID_RANDOM_PROVIDER_WINCRYPT
54 # define BOOST_UUID_RANDOM_PROVIDER_NAME wincrypt
55 # else
56 # error Unable to find a suitable windows entropy provider
57 # endif
58
59 #elif defined(BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETRANDOM)
60 # define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM
61 # define BOOST_UUID_RANDOM_PROVIDER_NAME getrandom
62
63 #elif BOOST_LIB_C_GNU >= BOOST_VERSION_NUMBER(2, 25, 0) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY)
64 # define BOOST_UUID_RANDOM_PROVIDER_GETENTROPY
65 # define BOOST_UUID_RANDOM_PROVIDER_NAME getentropy
66
67 #else
68 # define BOOST_UUID_RANDOM_PROVIDER_POSIX
69 # define BOOST_UUID_RANDOM_PROVIDER_NAME posix
70
71 #endif
72
73 #define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X) #X
74 #define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(X) BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X)
75
76 #if defined(BOOST_UUID_RANDOM_PROVIDER_SHOW)
77 #pragma message("BOOST_UUID_RANDOM_PROVIDER_NAME " BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(BOOST_UUID_RANDOM_PROVIDER_NAME))
78 #endif
79
80 #endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP