|
| 1 | +//===- Linux implementation of secure random buffer generation --*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
1 | 8 | #include "src/__support/OSUtil/linux/random.h" |
2 | 9 | #include "src/__support/CPP/mutex.h" |
3 | 10 | #include "src/__support/CPP/new.h" |
4 | 11 | #include "src/__support/OSUtil/linux/syscall.h" |
5 | 12 | #include "src/__support/OSUtil/linux/vdso.h" |
6 | | -#include "src/__support/OSUtil/linux/x86_64/vdso.h" |
7 | 13 | #include "src/__support/libc_assert.h" |
8 | 14 | #include "src/__support/memory_size.h" |
9 | 15 | #include "src/__support/threads/callonce.h" |
@@ -307,8 +313,13 @@ void random_fill(void *buf, size_t size) { |
307 | 313 | random_fill_impl( |
308 | 314 | [state](void *buf, size_t size) { |
309 | 315 | vdso::TypedSymbol<vdso::VDSOSym::GetRandom> vgetrandom; |
310 | | - return vgetrandom(buf, size, 0, state, |
311 | | - StateFactory::size_of_opaque_state()); |
| 316 | + int res = vgetrandom(buf, size, 0, state, |
| 317 | + StateFactory::size_of_opaque_state()); |
| 318 | + if (res < 0) { |
| 319 | + libc_errno = -res; |
| 320 | + return -1; |
| 321 | + } |
| 322 | + return res; |
312 | 323 | }, |
313 | 324 | buf, size); |
314 | 325 | } else { |
|
0 commit comments