Using getrandom() libc interface, SYS_getrandom fixes.
The interface is available since Glibc 2.25, and FreeBSD 12.0.
This commit is contained in:
34
auto/unix
34
auto/unix
@@ -3,25 +3,51 @@
|
|||||||
# Copyright (C) NGINX, Inc.
|
# Copyright (C) NGINX, Inc.
|
||||||
|
|
||||||
|
|
||||||
# Linux 3.17 getrandom().
|
# getrandom().
|
||||||
|
|
||||||
nxt_feature="getrandom()"
|
nxt_feature="getrandom()"
|
||||||
nxt_feature_name=NXT_HAVE_GETRANDOM
|
nxt_feature_name=NXT_HAVE_GETRANDOM
|
||||||
nxt_feature_run=
|
nxt_feature_run=yes
|
||||||
nxt_feature_incs=
|
nxt_feature_incs=
|
||||||
nxt_feature_libs=
|
nxt_feature_libs=
|
||||||
nxt_feature_test="#include <linux/random.h>
|
nxt_feature_test="#include <unistd.h>
|
||||||
|
#include <sys/random.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
(void) getrandom(buf, 4, 0);
|
if (getrandom(buf, 4, 0) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}"
|
}"
|
||||||
. auto/feature
|
. auto/feature
|
||||||
|
|
||||||
|
|
||||||
|
if [ $nxt_found = no ]; then
|
||||||
|
|
||||||
|
# Linux 3.17 SYS_getrandom.
|
||||||
|
|
||||||
|
nxt_feature="SYS_getrandom in Linux"
|
||||||
|
nxt_feature_name=NXT_HAVE_LINUX_SYS_GETRANDOM
|
||||||
|
nxt_feature_test="#include <unistd.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <linux/random.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char buf[4];
|
||||||
|
|
||||||
|
if (syscall(SYS_getrandom, buf, 4, 0) < 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}"
|
||||||
|
. auto/feature
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
nxt_feature="ucontext"
|
nxt_feature="ucontext"
|
||||||
nxt_feature_name=NXT_HAVE_UCONTEXT
|
nxt_feature_name=NXT_HAVE_UCONTEXT
|
||||||
nxt_feature_run=
|
nxt_feature_run=
|
||||||
|
|||||||
@@ -62,9 +62,13 @@ nxt_random_stir(nxt_random_t *r)
|
|||||||
|
|
||||||
#if (NXT_HAVE_GETRANDOM)
|
#if (NXT_HAVE_GETRANDOM)
|
||||||
|
|
||||||
/* Linux 3.17 getrandom(). */
|
n = getrandom(&key, NXT_RANDOM_KEY_SIZE, 0);
|
||||||
|
|
||||||
n = getrandom(key, NXT_RANDOM_KEY_SIZE, 0);
|
#elif (NXT_HAVE_LINUX_SYS_GETRANDOM)
|
||||||
|
|
||||||
|
/* Linux 3.17 SYS_getrandom. */
|
||||||
|
|
||||||
|
n = syscall(SYS_getrandom, &key, NXT_RANDOM_KEY_SIZE, 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,6 @@
|
|||||||
#include <malloc.h> /* malloc_usable_size(). */
|
#include <malloc.h> /* malloc_usable_size(). */
|
||||||
#include <sys/syscall.h> /* syscall(SYS_gettid). */
|
#include <sys/syscall.h> /* syscall(SYS_gettid). */
|
||||||
|
|
||||||
#if (NXT_GETRANDOM)
|
|
||||||
#include <linux/random.h> /* getrandom(). */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4)
|
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4)
|
||||||
/*
|
/*
|
||||||
* POSIX semaphores using NPTL atomic/futex operations
|
* POSIX semaphores using NPTL atomic/futex operations
|
||||||
@@ -234,6 +230,12 @@
|
|||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (NXT_HAVE_GETRANDOM)
|
||||||
|
#include <sys/random.h> /* getrandom(). */
|
||||||
|
#elif (NXT_HAVE_LINUX_SYS_GETRANDOM)
|
||||||
|
#include <linux/random.h> /* SYS_getrandom. */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (NXT_TEST_BUILD)
|
#if (NXT_TEST_BUILD)
|
||||||
#include <nxt_test_build.h>
|
#include <nxt_test_build.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user