Skip to content

Commit ad69e58

Browse files
zhuoweimodocache
authored andcommitted
android: Use Android bionic's arc4random_uniform (which isn't in headers but is available on all versions so far)
1 parent 5b407ca commit ad69e58

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

stdlib/public/stubs/LibcShims.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static_assert(std::is_same<ssize_t, swift::__swift_ssize_t>::value,
3030
#ifdef __ANDROID__
3131
extern "C" {
3232
extern size_t dlmalloc_usable_size(void*);
33+
// arc4random_random is missing in headers but does exist
34+
extern unsigned int arc4random_uniform(unsigned int upper_bound);
3335
}
3436
#endif
3537

@@ -78,21 +80,12 @@ size_t _swift_stdlib_malloc_size(const void *ptr) {
7880
#error No malloc_size analog known for this platform/libc.
7981
#endif
8082

81-
#ifndef __ANDROID__
8283
__swift_uint32_t _swift_stdlib_arc4random(void) { return arc4random(); }
8384

8485
__swift_uint32_t
8586
_swift_stdlib_arc4random_uniform(__swift_uint32_t upper_bound) {
8687
return arc4random_uniform(upper_bound);
8788
}
88-
#else
89-
// FIXME: Android: chosen by fair dice roll
90-
__swift_uint32_t _swift_stdlib_arc4random(void) { return 4; }
91-
__swift_uint32_t
92-
_swift_stdlib_arc4random_uniform(__swift_uint32_t upper_bound) {
93-
return 0;
94-
}
95-
#endif
9689

9790
} // namespace swift
9891

0 commit comments

Comments
 (0)