From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4D044208F1 for ; Mon, 16 Jul 2018 21:19:38 +0000 (UTC) From: Eric Wong To: mwrap-public@80x24.org Subject: [PATCH 08/19] reduce stack usage from file names Date: Mon, 16 Jul 2018 21:19:22 +0000 Message-Id: <20180716211933.5835-9-e@80x24.org> In-Reply-To: <20180716211933.5835-1-e@80x24.org> References: <20180716211933.5835-1-e@80x24.org> List-Id: Ruby source locations can be extremely long and use excessive stack space. Move it off stack for the temporary key lookup to reduce the likelyhood of stack overflows. No need to use TSD (which is stored on stack with GCC anyways); as we have GVL at that point. --- ext/mwrap/mwrap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index 6109070..d08ebf0 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -291,6 +291,7 @@ static struct src_loc *update_stats_rcu(size_t size, uintptr_t caller) const char *ptr = rb_source_location_cstr(&line); size_t len; size_t int_size = INT2STR_MAX; + static char buf[PATH_MAX + INT2STR_MAX + sizeof(*k) + 2]; generation = rb_gc_count(); @@ -298,7 +299,7 @@ static struct src_loc *update_stats_rcu(size_t size, uintptr_t caller) /* avoid vsnprintf or anything which could call malloc here: */ len = strlen(ptr); - k = alloca(sizeof(*k) + len + 1 + int_size + 1); + k = (void *)buf; k->total = size; dst = mempcpy(k->k, ptr, len); *dst++ = ':'; -- EW