2025-05-10 21:58:58 +08:00

46 lines
1.2 KiB
Diff

From 1b90c61f1fd4d83054a60ed5d21c6f76f1d23925 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Wed, 11 Aug 2021 20:08:33 -0700
Subject: [PATCH] provide __close on musl
Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
base/files/scoped_file_linux.cc | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/base/files/scoped_file_linux.cc b/base/files/scoped_file_linux.cc
index e72b5b7248..958f7c2823 100644
--- a/base/files/scoped_file_linux.cc
+++ b/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"
@@ -81,9 +82,18 @@ bool IsFDOwned(int fd) {
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);