[libcxx-commits] [PATCH] D116045: [libc++] Use arc4random instead of /dev/urandom on Apple platforms

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 21 10:44:07 PST 2021


Mordante added a comment.

I assume that's something along the lines of

- #ifdef _LIBCPP_USING_DEV_RANDOM

+ #if defined(_LIBCPP_USING_DEV_RANDOM) || defined(__APPLE__)

With the appropriate comment and closing `#endif`.

I grepped for `urandom` and it didn't find documentation, so it seems it's only documented in the code.
It's however documented at https://en.cppreference.com/w/cpp/numeric/random/random_device/random_device
Which also mentions MSVC STL ignores the token completely.

I wonder whether it wouldn't be better to ignore the token for `_LIBCPP_USING_ARC4_RANDOM` instead of throwing an exception. (Probably in a separate patch.) That way even when Apple users now select a device their code will keep working after this change instead of suddenly throwing an exception.



================
Comment at: libcxx/include/__config:338
    // Certain architectures provide arc4random(). Prefer using
    // arc4random() over /dev/{u,}random to make it possible to obtain
    // random data even when using sandboxing mechanisms such as chroots,
----------------
This comment is somewhat misleading, since it doesn't work when the token is `/dev/random`.
But as commented below I think it would be good to document here that the token is ignored when using arc4random.

Documenting the behavior of token for the other devices would be nice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116045/new/

https://reviews.llvm.org/D116045



More information about the libcxx-commits mailing list