Skip to content

Commit 061580b

Browse files
committed
[libc++][Android] Disable fdsan in close.pass.cpp
fdsan is Bionic's "File Descriptor Sanitizer". Starting in API 30+, it aborts this close.pass.cpp test, because it closes the FD belonging to std::filebuf's FILE*. Use an fdsan API to suppress the diagnostic.
1 parent 89c8d68 commit 061580b

File tree

1 file changed

+15
-5
lines changed
  • libcxx/test/std/input.output/file.streams/fstreams/filebuf.members

1 file changed

+15
-5
lines changed

libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/close.pass.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
// basic_filebuf<charT,traits>* close();
1212

13-
// This test closes an fd that belongs to a std::filebuf, and Bionic's fdsan
14-
// detects this and aborts the process, starting in Android R (API 30).
15-
// See D137129.
16-
// XFAIL: LIBCXX-ANDROID-FIXME && !android-device-api={{2[1-9]}}
17-
1813
#include <fstream>
1914
#include <cassert>
2015
#if defined(__unix__)
@@ -24,6 +19,14 @@
2419
#include "test_macros.h"
2520
#include "platform_support.h"
2621

22+
// If we're building for a lower __ANDROID_API__, the Bionic versioner will
23+
// omit the function declarations from fdsan.h. We might be running on a newer
24+
// API level, though, so declare the API function here using weak.
25+
#if defined(__BIONIC__)
26+
#include <android/fdsan.h>
27+
enum android_fdsan_error_level android_fdsan_set_error_level(enum android_fdsan_error_level new_level) __attribute__((weak));
28+
#endif
29+
2730
int main(int, char**)
2831
{
2932
std::string temp = get_temp_file_name();
@@ -37,6 +40,13 @@ int main(int, char**)
3740
assert(f.close() == nullptr);
3841
assert(!f.is_open());
3942
}
43+
#if defined(__BIONIC__)
44+
// Starting with Android API 30+, Bionic's fdsan aborts a process that
45+
// attempts to close a file descriptor belonging to something else. Disable
46+
// fdsan to allow closing the FD belonging to std::filebuf's FILE*.
47+
if (android_fdsan_set_error_level != nullptr)
48+
android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
49+
#endif
4050
#if defined(__unix__)
4151
{
4252
std::filebuf f;

0 commit comments

Comments
 (0)