Otherwise if RLIMIT_NOFILE exceeds the UBsan reports false-positive
reports, because it cannot correctly check types:
pipe() <-- fails on EMFILE and IsAccessibleMemoryRange() returns false __sanitizer::IsAccessibleMemoryRange(unsigned long, unsigned long) __ubsan::checkDynamicType(void*, void*, unsigned long) + 271 HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) + 34 __ubsan_handle_dynamic_type_cache_miss_abort + 58
But there are some issues with this patch, first of all it will leave
pair of file descriptors in each thread, although it initialize them
Another option is to simply ignore pipe() error, i.e. return true from
IsAccessibleMemoryRange() instead of false (like was before this patch).
And also it uses global destructor, and there is a compile warning
(although I saw other places in compiler-rt that does this, i.e.
But, if this is not a good thing to go, this can be fixed by using some
initialize and destructor.
v2: tried /dev/null
v3: read data from pipe to avoid stall
v4: add a test for pipe capacity exceed
v5: thread local
v6: test with RLIMIT_NOFILE
v7: ignore unavailable pipe errors