Skip to content

Commit 02c8477

Browse files
committed
chromium: Fix tab crashes due to stack overflow on musl
These patches are musl specific and are refreshed to fix mainly the problem with stack overflow which was happening due to crash in thread stack from code using mallinfo, we have to disable mallinfo using codepaths completely. rand_r() API is available in musl so there is no need to disable it providing res_ninit/res_nclose using obsolete APIs is not good solution so do not use these APIs on musl chromium works like a charm on musl now ( tested on x86_64/qemu ) Signed-off-by: Khem Raj <[email protected]>
1 parent b400a16 commit 02c8477

File tree

3 files changed

+88
-194
lines changed

3 files changed

+88
-194
lines changed

meta-chromium/recipes-browser/chromium/files/musl/0001-mallinfo-implementation-is-glibc-specific.patch

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,48 @@ Subject: [PATCH] mallinfo implementation is glibc specific
66
Upstream-Status: Pending
77
Signed-off-by: Khem Raj <[email protected]>
88
---
9-
base/process/process_metrics_posix.cc | 2 +-
10-
base/trace_event/malloc_dump_provider.cc | 2 +-
11-
.../llvm-subzero/build/Linux/include/llvm/Config/config.h | 2 +-
12-
third_party/tcmalloc/chromium/src/config_linux.h | 2 +-
13-
4 files changed, 4 insertions(+), 4 deletions(-)
9+
--- a/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
10+
+++ b/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
11+
@@ -35,7 +35,7 @@ bool MemoryUsage::IsSupported() {
1412

13+
MemoryUsage GetMemoryUsage() {
14+
MemoryUsage result;
15+
-#ifdef __linux__
16+
+#if defined(__linux__) && defined(__GLIBC__)
17+
rusage res;
18+
if (getrusage(RUSAGE_SELF, &res) == 0) {
19+
result.max_rss_kb = res.ru_maxrss;
1520
--- a/base/process/process_metrics_posix.cc
1621
+++ b/base/process/process_metrics_posix.cc
1722
@@ -105,7 +105,7 @@ void IncreaseFdLimitTo(unsigned int max_
18-
23+
1924
#endif // !defined(OS_FUCHSIA)
20-
25+
2126
-#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
22-
+#if defined(__GLIBC__) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
27+
+#if (defined(OS_LINUX) && defined(__GLIBC__)) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
2328
namespace {
24-
29+
2530
size_t GetMallocUsageMallinfo() {
26-
@@ -134,7 +134,7 @@ size_t ProcessMetrics::GetMallocUsage()
31+
@@ -127,16 +127,16 @@ size_t GetMallocUsageMallinfo() {
32+
}
33+
34+
} // namespace
35+
-#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
36+
+#endif // (defined(OS_LINUX) && defined(__GLIBC__)) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
37+
38+
size_t ProcessMetrics::GetMallocUsage() {
39+
#if defined(OS_APPLE)
2740
malloc_statistics_t stats = {0};
2841
malloc_zone_statistics(nullptr, &stats);
2942
return stats.size_in_use;
3043
-#elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
31-
+#elif defined(__GLIBC__) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
44+
+#elif (defined(OS_LINUX) && defined(__GLIBC__)) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
3245
return GetMallocUsageMallinfo();
33-
#elif defined(OS_FUCHSIA)
46+
-#elif defined(OS_FUCHSIA)
47+
+#else
3448
// TODO(fuchsia): Not currently exposed. https://crbug.com/735087.
49+
return 0;
50+
#endif
3551
--- a/base/trace_event/malloc_dump_provider.cc
3652
+++ b/base/trace_event/malloc_dump_provider.cc
3753
@@ -203,7 +203,7 @@ bool MallocDumpProvider::OnMemoryDump(co
@@ -47,61 +63,10 @@ Signed-off-by: Khem Raj <[email protected]>
4763
+++ b/third_party/swiftshader/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
4864
@@ -130,7 +130,7 @@
4965
/* #undef HAVE_MALLCTL */
50-
66+
5167
/* Define to 1 if you have the `mallinfo' function. */
5268
-#define HAVE_MALLINFO 1
5369
+/* #undef HAVE_MALLINFO */
54-
70+
5571
/* Define to 1 if you have the <malloc.h> header file. */
5672
#define HAVE_MALLOC_H 1
57-
--- a/third_party/tcmalloc/chromium/src/config_linux.h
58-
+++ b/third_party/tcmalloc/chromium/src/config_linux.h
59-
@@ -152,7 +152,7 @@
60-
#define HAVE_STRING_H 1
61-
62-
/* Define to 1 if the system has the type `struct mallinfo'. */
63-
-#define HAVE_STRUCT_MALLINFO 1
64-
+/* #undef HAVE_STRUCT_MALLINFO */
65-
66-
/* Define to 1 if you have the <sys/cdefs.h> header file. */
67-
#define HAVE_SYS_CDEFS_H 1
68-
--- a/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h
69-
+++ b/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h
70-
@@ -125,7 +125,7 @@
71-
/* #undef HAVE_MALLCTL */
72-
73-
/* Define to 1 if you have the `mallinfo' function. */
74-
-#define HAVE_MALLINFO 1
75-
+/* #undef HAVE_MALLINFO */
76-
77-
/* Define to 1 if you have the <malloc/malloc.h> header file. */
78-
/* #undef HAVE_MALLOC_MALLOC_H */
79-
--- a/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
80-
+++ b/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
81-
@@ -14,7 +14,7 @@ limitations under the License.
82-
==============================================================================*/
83-
#include "tensorflow/lite/profiling/memory_info.h"
84-
85-
-#ifdef __linux__
86-
+#ifdef __GLIBC__
87-
#include <malloc.h>
88-
#include <sys/resource.h>
89-
#include <sys/time.h>
90-
@@ -27,7 +27,7 @@ namespace memory {
91-
const int MemoryUsage::kValueNotSet = 0;
92-
93-
bool MemoryUsage::IsSupported() {
94-
-#ifdef __linux__
95-
+#ifdef __GLIBC__
96-
return true;
97-
#endif
98-
return false;
99-
@@ -35,7 +35,7 @@ bool MemoryUsage::IsSupported() {
100-
101-
MemoryUsage GetMemoryUsage() {
102-
MemoryUsage result;
103-
-#ifdef __linux__
104-
+#ifdef __GLIBC__
105-
rusage res;
106-
if (getrusage(RUSAGE_SELF, &res) == 0) {
107-
result.max_rss_kb = res.ru_maxrss;
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From da6183c75d9b4f0f77ea0bee460315697302f23c Mon Sep 17 00:00:00 2001
22
From: Khem Raj <[email protected]>
33
Date: Wed, 13 Feb 2019 09:51:14 -0800
4-
Subject: [PATCH] fontconfig: Musl does not have rand_r() API
4+
Subject: [PATCH] fontconfig: Musl does not have random_r() API
55

66
Mark it to be glibc specific
77

@@ -11,24 +11,14 @@ Signed-off-by: Khem Raj <[email protected]>
1111
third_party/fontconfig/include/config.h | 9 ++++++---
1212
1 file changed, 6 insertions(+), 3 deletions(-)
1313

14-
diff --git a/third_party/fontconfig/include/config.h b/third_party/fontconfig/include/config.h
15-
index 9087ca0c15..265e69248f 100644
1614
--- a/third_party/fontconfig/include/config.h
1715
+++ b/third_party/fontconfig/include/config.h
18-
@@ -157,10 +157,13 @@
16+
@@ -157,7 +157,7 @@
1917
#define HAVE_RANDOM 1
20-
18+
2119
/* Define to 1 if you have the `random_r' function. */
2220
-#define HAVE_RANDOM_R 1
23-
-
24-
+#ifdef __GLIBC__
25-
+# define HAVE_RANDOM_R 1
26-
+#endif
21+
+/* #undef HAVE_RANDOM_R */
22+
2723
/* Define to 1 if you have the `rand_r' function. */
28-
-#define HAVE_RAND_R 1
29-
+#ifdef __GLIBC__
30-
+# define HAVE_RAND_R 1
31-
+#endif
32-
33-
/* Define to 1 if you have the `readlink' function. */
34-
#define HAVE_READLINK 1
24+
#define HAVE_RAND_R 1

meta-chromium/recipes-browser/chromium/files/musl/0009-provide-res_ninit-and-nclose-APIs-on-non-glibc-linux.patch

Lines changed: 52 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -9,124 +9,63 @@ These APIs are not implemented on musl
99
Upstream-Status: Pending
1010
Signed-off-by: Khem Raj <[email protected]>
1111
---
12-
net/dns/dns_config_service_posix.cc | 30 +++++++++++++++++++++++++++++
13-
net/dns/dns_reloader.cc | 30 +++++++++++++++++++++++++++++
14-
2 files changed, 60 insertions(+)
15-
16-
--- a/net/dns/dns_config_service_posix.cc
17-
+++ b/net/dns/dns_config_service_posix.cc
18-
@@ -32,6 +32,36 @@
19-
#include "net/dns/dns_config_watcher_mac.h"
20-
#endif
21-
22-
+#if !defined(__GLIBC__)
23-
+/***************************************************************************
24-
+ * resolv_compat.h
25-
+ *
26-
+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
27-
+ * Note: res_init() is actually deprecated according to
28-
+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
29-
+ **************************************************************************/
30-
+#include <string.h>
31-
+
32-
+static inline int res_ninit(res_state statp)
33-
+{
34-
+ int rc = res_init();
35-
+ if (statp != &_res) {
36-
+ memcpy(statp, &_res, sizeof(*statp));
37-
+ }
38-
+ return rc;
39-
+}
40-
+
41-
+static inline int res_nclose(res_state statp)
42-
+{
43-
+ if (!statp)
44-
+ return -1;
45-
+ if (statp != &_res) {
46-
+ memset(statp, 0, sizeof(*statp));
47-
+ }
48-
+ return 0;
49-
+}
50-
+#endif
51-
+
52-
namespace net {
53-
54-
namespace internal {
5512
--- a/net/dns/dns_reloader.cc
5613
+++ b/net/dns/dns_reloader.cc
57-
@@ -17,6 +17,36 @@
58-
#include "base/threading/thread_local.h"
59-
#include "net/base/network_change_notifier.h"
14+
@@ -4,8 +4,7 @@
15+
16+
#include "net/dns/dns_reloader.h"
17+
18+
-#if defined(OS_POSIX) && !defined(OS_APPLE) && !defined(OS_OPENBSD) && \
19+
- !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
20+
+#if defined(__GLIBC__)
6021

61-
+#if !defined(__GLIBC__)
62-
+/***************************************************************************
63-
+ * resolv_compat.h
64-
+ *
65-
+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
66-
+ * Note: res_init() is actually deprecated according to
67-
+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
68-
+ **************************************************************************/
69-
+#include <string.h>
70-
+
71-
+static inline int res_ninit(res_state statp)
72-
+{
73-
+ int rc = res_init();
74-
+ if (statp != &_res) {
75-
+ memcpy(statp, &_res, sizeof(*statp));
76-
+ }
77-
+ return rc;
78-
+}
79-
+
80-
+static inline int res_nclose(res_state statp)
81-
+{
82-
+ if (!statp)
83-
+ return -1;
84-
+ if (statp != &_res) {
85-
+ memset(statp, 0, sizeof(*statp));
86-
+ }
87-
+ return 0;
88-
+}
89-
+#endif
90-
+
91-
namespace net {
22+
#include <resolv.h>
9223

93-
namespace {
24+
--- a/net/dns/host_resolver_manager.cc
25+
+++ b/net/dns/host_resolver_manager.cc
26+
@@ -2536,8 +2536,7 @@ HostResolverManager::HostResolverManager
27+
NetworkChangeNotifier::AddConnectionTypeObserver(this);
28+
if (system_dns_config_notifier_)
29+
system_dns_config_notifier_->AddObserver(this);
30+
-#if defined(OS_POSIX) && !defined(OS_APPLE) && !defined(OS_OPENBSD) && \
31+
- !defined(OS_ANDROID)
32+
+#if defined(__GLIBC__)
33+
EnsureDnsReloaderInit();
34+
#endif
35+
36+
--- a/net/dns/host_resolver_proc.cc
37+
+++ b/net/dns/host_resolver_proc.cc
38+
@@ -176,8 +176,7 @@ int SystemHostResolverCall(const std::st
39+
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
40+
base::BlockingType::WILL_BLOCK);
41+
42+
-#if defined(OS_POSIX) && !defined(OS_APPLE) && !defined(OS_OPENBSD) && \
43+
- !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
44+
+#if defined(__GLIBC__)
45+
DnsReloaderMaybeReload();
46+
#endif
47+
absl::optional<AddressInfo> ai;
9448
--- a/net/dns/dns_config_service_linux.cc
9549
+++ b/net/dns/dns_config_service_linux.cc
96-
@@ -35,6 +35,36 @@
97-
#include "net/dns/serial_worker.h"
98-
#include "third_party/abseil-cpp/absl/types/optional.h"
50+
@@ -486,20 +486,11 @@ class DnsConfigServiceLinux::ConfigReade
51+
52+
std::unique_ptr<struct __res_state>
53+
DnsConfigServiceLinux::ResolvReader::GetResState() {
54+
- auto res = std::make_unique<struct __res_state>();
55+
- memset(res.get(), 0, sizeof(struct __res_state));
56+
-
57+
- if (res_ninit(res.get()) != 0) {
58+
- CloseResState(res.get());
59+
- return nullptr;
60+
- }
61+
-
62+
- return res;
63+
+ return nullptr;
64+
}
9965

100-
+#if !defined(__GLIBC__)
101-
+/***************************************************************************
102-
+ * resolv_compat.h
103-
+ *
104-
+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
105-
+ * Note: res_init() is actually deprecated according to
106-
+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
107-
+ **************************************************************************/
108-
+#include <string.h>
109-
+
110-
+static inline int res_ninit(res_state statp)
111-
+{
112-
+ int rc = res_init();
113-
+ if (statp != &_res) {
114-
+ memcpy(statp, &_res, sizeof(*statp));
115-
+ }
116-
+ return rc;
117-
+}
118-
+
119-
+static inline int res_nclose(res_state statp)
120-
+{
121-
+ if (!statp)
122-
+ return -1;
123-
+ if (statp != &_res) {
124-
+ memset(statp, 0, sizeof(*statp));
125-
+ }
126-
+ return 0;
127-
+}
128-
+#endif
129-
+
130-
namespace net {
66+
void DnsConfigServiceLinux::ResolvReader::CloseResState(
67+
struct __res_state* res) {
68+
- res_nclose(res);
69+
}
13170

132-
namespace internal {
71+
DnsConfigServiceLinux::DnsConfigServiceLinux()

0 commit comments

Comments
 (0)