Skip to content

Commit 0ad56e6

Browse files
committed
Inline the alpine patch
Ruby bugtracker gives 500 occasionally GitHub goes down too of course but now the eggs are all in one basket
1 parent 243c070 commit 0ad56e6

10 files changed

Lines changed: 101 additions & 9 deletions

File tree

3.1/alpine3.19/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.1/alpine3.20/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.2/alpine3.19/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.2/alpine3.20/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.3/alpine3.19/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.3/alpine3.20/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.4-rc/alpine3.19/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.4-rc/alpine3.20/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ RUN set -eux; \
210210
# https://github.com/docker-library/ruby/issues/196
211211
# https://bugs.ruby-lang.org/issues/14387#note-13 (patch source)
212212
# https://bugs.ruby-lang.org/issues/14387#note-16 ("Therefore ncopa's patch looks good for me in general." -- only breaks glibc which doesn't matter here)
213-
wget -O 'thread-stack-fix.patch' 'https://bugs.ruby-lang.org/attachments/download/7081/0001-thread_pthread.c-make-get_main_stack-portable-on-lin.patch'; \
213+
wget -O 'thread-stack-fix.patch' 'https://raw.githubusercontent.com/docker-ruby-nightly/ruby/master/thread-stack-fix.patch'; \
214214
echo '3ab628a51d92fdf0d2b5835e93564857aea73e0c1de00313864a94a6255cb645 *thread-stack-fix.patch' | sha256sum --check --strict; \
215215
patch -p1 -i thread-stack-fix.patch; \
216216
rm thread-stack-fix.patch; \

thread-stack-fix.patch

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From 2cd56ff98bdb291b9b5e2d0e3fd4cd315076c904 Mon Sep 17 00:00:00 2001
2+
From: Natanael Copa <ncopa@alpinelinux.org>
3+
Date: Wed, 14 Mar 2018 14:14:11 +0100
4+
Subject: [PATCH] thread_pthread.c: make get_main_stack portable on linux
5+
6+
We can not rely on the calculated stack size from pthread_getattr_np()
7+
for the main thread, because the way this is calculated may differ
8+
depending on implementation. The _np means non-portable.
9+
10+
So we test if it is a known implementation (__GLIBC__) and fallback to a
11+
portable way on Linux by parsing /proc/self/maps to get the stack for
12+
main thread. We also add a 100MB safety limit so we don't reserve_stack
13+
with an insane value.
14+
15+
Credit goes to Szabolcs Nagy for this code.
16+
---
17+
thread_pthread.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
18+
1 file changed, 49 insertions(+), 3 deletions(-)
19+
20+
diff --git a/thread_pthread.c b/thread_pthread.c
21+
index 951885ffa0..cf90321d1d 100644
22+
--- a/thread_pthread.c
23+
+++ b/thread_pthread.c
24+
@@ -530,9 +530,6 @@ hpux_attr_getstackaddr(const pthread_attr_t *attr, void **addr)
25+
# define MAINSTACKADDR_AVAILABLE 0
26+
# endif
27+
#endif
28+
-#if MAINSTACKADDR_AVAILABLE && !defined(get_main_stack)
29+
-# define get_main_stack(addr, size) get_stack(addr, size)
30+
-#endif
31+
32+
#ifdef STACKADDR_AVAILABLE
33+
/*
34+
@@ -614,6 +611,55 @@ get_stack(void **addr, size_t *size)
35+
return 0;
36+
#undef CHECK_ERR
37+
}
38+
+
39+
+#if defined(__linux__) && !defined(__GLIBC__) && defined(HAVE_GETRLIMIT)
40+
+
41+
+#ifndef PAGE_SIZE
42+
+#include <unistd.h>
43+
+#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
44+
+#endif
45+
+
46+
+static int
47+
+get_main_stack(void **addr, size_t *size)
48+
+{
49+
+ size_t start, end, limit, prevend = 0;
50+
+ struct rlimit r;
51+
+ FILE *f;
52+
+ char buf[PATH_MAX+80], s[8];
53+
+ int n;
54+
+ STACK_GROW_DIR_DETECTION;
55+
+
56+
+ f = fopen("/proc/self/maps", "re");
57+
+ if (!f)
58+
+ return -1;
59+
+ n = 0;
60+
+ while (fgets(buf, sizeof buf, f)) {
61+
+ n = sscanf(buf, "%zx-%zx %*s %*s %*s %*s %7s", &start, &end, s);
62+
+ if (n >= 2) {
63+
+ if (n == 3 && strcmp(s, "[stack]") == 0)
64+
+ break;
65+
+ prevend = end;
66+
+ }
67+
+ n = 0;
68+
+ }
69+
+ fclose(f);
70+
+ if (n == 0)
71+
+ return -1;
72+
+
73+
+ limit = 100 << 20; /* 100MB stack limit */
74+
+ if (getrlimit(RLIMIT_STACK, &r)==0 && r.rlim_cur < limit)
75+
+ limit = r.rlim_cur & -PAGE_SIZE;
76+
+ if (limit > end) limit = end;
77+
+ if (prevend < end - limit) prevend = end - limit;
78+
+ if (start > prevend) start = prevend;
79+
+ *addr = IS_STACK_DIR_UPPER() ? (void *)start : (void *)end;
80+
+ *size = end - start;
81+
+ return 0;
82+
+}
83+
+#else
84+
+# define get_main_stack(addr, size) get_stack(addr, size)
85+
+#endif
86+
+
87+
#endif
88+
89+
static struct {
90+
--
91+
2.16.2
92+

0 commit comments

Comments
 (0)