summaryrefslogtreecommitdiff
path: root/repo/chromium/scoped-file.patch
blob: 34bf6eb4e79a66f4ed5b3cbe47736576474800a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--- ./base/files/scoped_file_linux.cc.orig
+++ ./base/files/scoped_file_linux.cc
@@ -7,6 +7,7 @@
 #include <algorithm>
 #include <array>
 #include <atomic>
+#include <dlfcn.h>
 
 #include "base/compiler_specific.h"
 #include "base/debug/stack_trace.h"
@@ -80,9 +81,18 @@
 
 extern "C" {
 
-int __close(int);
-
 __attribute__((visibility("default"), noinline)) int close(int fd) {
+  static int (*__close)(int) = nullptr;
+
+  if (__close == nullptr) {
+    __close = (int (*)(int))dlsym(RTLD_NEXT, "close");
+
+    if (__close == nullptr) {
+      RAW_LOG(ERROR, "musl close not found\n");
+      IMMEDIATE_CRASH();
+    }
+  }
+
   if (base::IsFDOwned(fd) && g_is_ownership_enforced)
     CrashOnFdOwnershipViolation();
   return __close(fd);