summaryrefslogtreecommitdiff
path: root/libcxx/src/random.cpp
AgeCommit message (Collapse)Author
2025-07-18Remove last few bits for Native Client support (#148983)Brad Smith
2025-05-28Revert "[libc++] Introduce ABI sensitive areas to avoid requiring ↵James Y Knight
_LIBCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756) This reverts commit c861fe8a71e64f3d2108c58147e7375cd9314521. Unfortunately, this use of hidden visibility attributes causes user-defined specializations of standard-library types to also be marked hidden by default, which is incorrect. See discussion thread on #131156. ...and also reverts the follow-up commits: Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)" This reverts commit 3e4c9dc299c35155934688184319d391b298fff7. Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)" This reverts commit f73287e623a6c2e4a3485832bc3e10860cd26eb5. Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)" This reverts commit 1d411f27c769a32cb22ce50b9dc4421e34fd40dd.
2025-05-18[libc++] Introduce ABI sensitive areas to avoid requiring ↵Nikolas Klauser
_LIBCPP_HIDE_FROM_ABI everywhere (#131156) This patch introduces `_LIBCPP_{BEGIN,END}_EXPLICIT_ABI_ANNOTATIONS`, which allow us to have implicit annotations for most functions, and just where it's not "hide_from_abi everything" we add explicit annotations. This allows us to drop the `_LIBCPP_HIDE_FROM_ABI` macro from most functions in libc++.
2025-05-12[libc++] Fix missing #includes (#130536)Matt
Adds missing includes that were detected when I tried to build libc++ as a module. Working towards #127012
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne
This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent. This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2024-11-16[libc++] Avoid including <string> in <mutex> (#116254)Nikolas Klauser
2024-04-09[libc++] Avoids using ENODATA. (#86165)Mark de Wever
This macro is deprecated in C++26. Fixes https://github.com/llvm/llvm-project/issues/81360 --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-03-21[libc++] Deprecates std::errc constants. (#80542)Mark de Wever
Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
2023-12-18[libc++] Format the code base (#74334)Louis Dionne
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-05-05[libc++] Remove Solaris related codeLouis Dionne
This was contributed ~10 years ago, but we don't officially support it and I am not aware of any bot testing it, so this has likely rotten to the point where it is unusable. Differential Revision: https://reviews.llvm.org/D138680
2023-04-09[libc++] Granularize system_error.Mark de Wever
Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D147853
2022-03-28[libcxx] random_device, specify optimal entropy properties for all OS's ↵Brad Smith
using arc4random() Reviewed By: ldionne Differential Revision: https://reviews.llvm.org/D122522
2022-02-15[libc++] Replace `#include ""` with `<>` in libcxx/src/. NFCI.Arthur O'Dwyer
Our best guess is that the two syntaxes should have exactly equivalent effects, so, let's be consistent with what we do in libcxx/include/. I've left `#include "include/x.h"` and `#include "../y.h"` alone because I'm less sure that they're interchangeable, and they aren't inconsistent with libcxx/include/ because libcxx/include/ never does that kind of thing. Also, use the `_LIBCPP_PUSH_MACROS/POP_MACROS` dance for `<__undef_macros>`, even though it's technically unnecessary in a standalone .cpp file, just so we have consistently one way to do it. Differential Revision: https://reviews.llvm.org/D119561
2022-01-12[libc++] Start using `arc4random()` to implement `std::random_device` on AppleLouis Dionne
On Apple platforms, arc4random is faster than /dev/urandom, and it is the recommended user-space RNG according to Apple's own OS folks. This commit adds an ABI switch to guard ABI-break-protections in std::random_device, and starts using arc4random instead of /dev/urandom to implement std::random_device on Apple platforms. Note that previously, `std::random_device` would allow passing a custom token to its constructor, and that token would be interpreted as the name of a file to read entropy from. This was implementation-defined and undocumented. After this change, Apple platforms will be using arc4random() instead, and any custom token passed to the constructor will be ignored. This behavioral change will also impact other platforms that use the arc4random() implementation, such as OpenBSD. This should be fine since that is effectively a relaxation of the constructor's requirements. rdar://86638350 Differential Revision: https://reviews.llvm.org/D116045
2022-01-04[libcxx] Use Fuchsia-native CPRNG for std::random_deviceRoland McGrath
Use the zx_cprng_draw system call directly rather than going through the libc getentropy function. The libc function is a trivial wrapper around the system call, and is not a standard C function. Avoiding it reduces the Fuchsia libc ABI surface that libc++ depends on. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D116498
2021-12-21[libc++][NFC] Reformatting in random_device.h and random.cppLouis Dionne
2021-11-17[runtimes][NFC] Remove filenames at the top of the license noticeLouis Dionne
We've stopped doing it in libc++ for a while now because these names would end up rotting as we move things around and copy/paste stuff. This cleans up all the existing files so as to stop the spreading as people copy-paste headers around.
2021-03-03[libc++/abi] Replace uses of _NOEXCEPT in src/ by noexceptLouis Dionne
We always build the libraries in a Standard mode that supports noexcept, so there's no need to use the _NOEXCEPT macro. Differential Revision: https://reviews.llvm.org/D97700
2021-01-25[libcxx] random_device, for OpenBSD specify optimal entropy propertiesBrad Smith
Reviewed By: ldionne Differential Revision: https://reviews.llvm.org/D94571
2021-01-21[libc++] Use ioctl when available to get random_device entropy.Marek Kurdej
Implemented the idea from D94571 to improve entropy on Linux. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D94953
2019-01-19Update more file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
2017-12-01[libcxx] Support getentropy as a source of randomness for std::random_devicePetr Hosek
Use this source use on Fuchsia where this is the oficially way to obtain randomness. This could be also used on other platforms that already support getentropy such as *BSD or Linux. Differential Revision: https://reviews.llvm.org/D40319 llvm-svn: 319523
2016-12-31random: include __config before buildingSaleem Abdulrasool
We need to include __config to ensure that we know what random implementation is being used. Fixes compilation for Windows. llvm-svn: 290775
2015-03-10Add support for arc4random() to random_device.Ed Schouten
Nuxi CloudABI (https://github.com/NuxiNL/cloudlibc) does not allow processes to access the global filesystem namespace. This breaks random_device, as it attempts to use /dev/{u,}random. This change adds support for arc4random(), which is present on CloudABI. In my opinion it would also make sense to use arc4random() on other operating systems, such as *BSD and Mac OS X, but I'd rather leave that to the maintainers of the respective platforms. Switching to arc4random() does change the ABI. This change also attempts to make some cleanups to the code. It adds a single #define for every random interface, instead of testing against operating systems explicitly. As discussed, also validate the token argument to be equal to "/dev/urandom" on all systems that only provide pseudo-random numbers. This should cause little to no breakage, as "/dev/urandom" is also the default argument value. Reviewed by: jfb Differential Revision: http://reviews.llvm.org/D8134 llvm-svn: 231764
2015-02-04libc++: remove unused variable in random_device::operator()()JF Bastien
Reviewers: jvoung Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D7416 llvm-svn: 228183
2014-12-01libc++: add NaCl and PNaCl support for std::random_deviceJF Bastien
Summary: The NaCl sandbox doesn't allow opening files under /dev, but it offers an API which provides the same capabilities. This is the same random device emulation that nacl_io performs for POSIX support, but nacl_io is an optional library so libc++ can't assume that device emulation will be performed. Note that NaCl only supports /dev/urandom, not /dev/random. This patch also cleans up some of the preprocessor #endif, and fixes the test for Win32 (it accepts any token, and would therefore never throw regardless of the token provided). Test Plan: ninja check-libcxx Reviewers: dschuff, mclow.lists, danalbert Subscribers: jfb, cfe-commits Differential Revision: http://reviews.llvm.org/D6442 llvm-svn: 223068
2014-06-03[libc++] Don't return uninitialized data from random_device::operator()David Majnemer
Make sure we appropriately retry calls to read if the return result is less than what we asked for. Additionally, check and handle IO errors: EINTR results in the read operation getting restarted; other errors turn into exceptions. llvm-svn: 210061
2014-06-03[libc++] random_device fails if open returns zeroDavid Majnemer
random_device::random_device(const string&) wrongly assumes that open can only validly return a file descriptor greater than zero. This results in random_device believing that it didn't successfully open the device causing it to throw in it's constructor, this ends up leaking a file descriptor. The fix is simple, don't error on file descriptors which are zero. llvm-svn: 210060
2013-11-18G M suggestion: conditionally include files on _WIN32.Yaron Keren
llvm-svn: 195045
2013-10-09patch by Yaron: Uses rand_s() from stdlib.h (when building for Windows)Marshall Clow
llvm-svn: 192325
2012-07-20noexcept applied to <random>.Howard Hinnant
llvm-svn: 160579
2012-02-29Solaris port. Currently sees around 200 test failures, mostly related toDavid Chisnall
Solaris not providing some of the locales that the test suite uses. Note: This depends on an xlocale (partial) implementation for Solaris and a couple of fixed standard headers. These will be committed to a branch later today. llvm-svn: 151720
2010-11-16license changeHoward Hinnant
llvm-svn: 119395
2010-08-22Fixing whitespace problemsHoward Hinnant
llvm-svn: 111751
2010-05-11Wiped out some non-ascii characters that snuck into the copyright.Howard Hinnant
llvm-svn: 103516
2010-05-11libcxx initial importHoward Hinnant
llvm-svn: 103490