From 39b491d1c8152681f64e06d72a034e725a6d0014 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 27 Jun 2018 04:58:14 -0500 Subject: system/ruby: fix stack size calculation (crash on ppc64) --- system/ruby/APKBUILD | 8 +++-- system/ruby/fix-get_main_stack.patch | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 system/ruby/fix-get_main_stack.patch diff --git a/system/ruby/APKBUILD b/system/ruby/APKBUILD index b6547468f..3849dffb9 100644 --- a/system/ruby/APKBUILD +++ b/system/ruby/APKBUILD @@ -25,7 +25,7 @@ pkgname=ruby pkgver=2.5.1 _abiver="${pkgver%.*}.0" -pkgrel=0 +pkgrel=1 pkgdesc="An object-oriented language for quick and easy programming" url="http://www.ruby-lang.org/" arch="all" @@ -57,7 +57,8 @@ subpackages="$pkgname-doc $pkgname-dev " source="https://cache.ruby-lang.org/pub/ruby/${pkgver%.*}/$pkgname-$pkgver.tar.xz rubygems-avoid-platform-specific-gems.patch - test_insns-lower-recursion-depth.patch" + test_insns-lower-recursion-depth.patch + fix-get_main_stack.patch" replaces="ruby-gems" _gemdir="/usr/lib/ruby/gems/$_abiver" @@ -312,4 +313,5 @@ _mvgem() { sha512sums="31bacf58469953282cd5d8b51862dcf4b84dedb927c1871bc3fca32fc157fe49187631575a70838705fe246f4555647577a7ecc26894445a7d64de5503dc11b4 ruby-2.5.1.tar.xz cfdc5ea3b2e2ea69c51f38e8e2180cb1dc27008ca55cc6301f142ebafdbab31c3379b3b6bba9ff543153876dd98ed2ad194df3255b7ea77a62e931c935f80538 rubygems-avoid-platform-specific-gems.patch -814fe6359505b70d8ff680adf22f20a74b4dbd3fecc9a63a6c2456ee9824257815929917b6df5394ed069a6869511b8c6dce5b95b4acbbb7867c1f3a975a0150 test_insns-lower-recursion-depth.patch" +814fe6359505b70d8ff680adf22f20a74b4dbd3fecc9a63a6c2456ee9824257815929917b6df5394ed069a6869511b8c6dce5b95b4acbbb7867c1f3a975a0150 test_insns-lower-recursion-depth.patch +8d730f02f76e53799f1c220eb23e3d2305940bb31216a7ab1e42d3256149c0721c7d173cdbfe505023b1af2f5cb3faa233dcc1b5d560fa8f980c17c2d29a9d81 fix-get_main_stack.patch" diff --git a/system/ruby/fix-get_main_stack.patch b/system/ruby/fix-get_main_stack.patch new file mode 100644 index 000000000..4bb9a0932 --- /dev/null +++ b/system/ruby/fix-get_main_stack.patch @@ -0,0 +1,70 @@ +diff --git a/thread_pthread.c b/thread_pthread.c +index 951885ffa0..cf90321d1d 100644 +--- a/thread_pthread.c ++++ b/thread_pthread.c +@@ -530,9 +530,6 @@ hpux_attr_getstackaddr(const pthread_attr_t *attr, void **addr) + # define MAINSTACKADDR_AVAILABLE 0 + # endif + #endif +-#if MAINSTACKADDR_AVAILABLE && !defined(get_main_stack) +-# define get_main_stack(addr, size) get_stack(addr, size) +-#endif + + #ifdef STACKADDR_AVAILABLE + /* +@@ -614,6 +611,55 @@ get_stack(void **addr, size_t *size) + return 0; + #undef CHECK_ERR + } ++ ++#if defined(__linux__) && !defined(__GLIBC__) && defined(HAVE_GETRLIMIT) ++ ++#ifndef PAGE_SIZE ++#include ++#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) ++#endif ++ ++static int ++get_main_stack(void **addr, size_t *size) ++{ ++ size_t start, end, limit, prevend = 0; ++ struct rlimit r; ++ FILE *f; ++ char buf[PATH_MAX+80], s[8]; ++ int n; ++ STACK_GROW_DIR_DETECTION; ++ ++ f = fopen("/proc/self/maps", "re"); ++ if (!f) ++ return -1; ++ n = 0; ++ while (fgets(buf, sizeof buf, f)) { ++ n = sscanf(buf, "%zx-%zx %*s %*s %*s %*s %7s", &start, &end, s); ++ if (n >= 2) { ++ if (n == 3 && strcmp(s, "[stack]") == 0) ++ break; ++ prevend = end; ++ } ++ n = 0; ++ } ++ fclose(f); ++ if (n == 0) ++ return -1; ++ ++ limit = 100 << 20; /* 100MB stack limit */ ++ if (getrlimit(RLIMIT_STACK, &r)==0 && r.rlim_cur < limit) ++ limit = r.rlim_cur & -PAGE_SIZE; ++ if (limit > end) limit = end; ++ if (prevend < end - limit) prevend = end - limit; ++ if (start > prevend) start = prevend; ++ *addr = IS_STACK_DIR_UPPER() ? (void *)start : (void *)end; ++ *size = end - start; ++ return 0; ++} ++#else ++# define get_main_stack(addr, size) get_stack(addr, size) ++#endif ++ + #endif + + static struct { -- cgit v1.2.3-60-g2f50