Bug 232328 - Fails to execute JavaScript when soft stack limit is unlimited
Summary: Fails to execute JavaScript when soft stack limit is unlimited
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-10-26 12:59 PDT by Michael Catanzaro
Modified: 2021-11-02 15:09 PDT (History)
9 users (show)

See Also:


Attachments
Patch (1.84 KB, patch)
2021-10-26 14:16 PDT, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2021-10-26 12:59:27 PDT
Reproducer:

$ ulimit -s unlimited
$ jsc
>>> 1 + 1
Exception:

I'm not sure why JSC cannot print the exception, but it's "maximum call stack size exceeded."

Problem is since r276695 "[WPE][GTK] More correct fixes for stack size issues on musl libc", WTF::StackBounds::currentThreadStackBoundsInternal now calls getrlimit() to get the soft stack limit. When the limit is unlimited, rlim_cur is -1 and the function is not prepared for that. I don't know how to fix it other than to fall back to some suitable default (8192 seems to be the default soft limit).

This is only a regression on Linux, but the Darwin code has the same bug too.
Comment 1 Daniel Kolesa 2021-10-26 13:02:22 PDT
let's have it max out at 8M, realistically there is nothing better you can do i think
Comment 2 Michael Catanzaro 2021-10-26 13:08:41 PDT
Actually I'm not certain it's really a regression, because there are preexisting calls to pthread_getattr_np() (or pthread_get_stacksize_np() on Darwin) that would likely have had the same problem.

(In reply to Daniel Kolesa from comment #1)
> let's have it max out at 8M, realistically there is nothing better you can
> do i think

Sounds good.
Comment 3 Michael Catanzaro 2021-10-26 14:14:29 PDT
(In reply to Michael Catanzaro from comment #0)
> When the limit is unlimited,
> rlim_cur is -1 and the function is not prepared for that.

Actually, it is RLIM_INFINITY. Doesn't change the rest of the analysis, though.
Comment 4 Michael Catanzaro 2021-10-26 14:16:08 PDT
Created attachment 442530 [details]
Patch
Comment 5 Michael Catanzaro 2021-10-26 14:18:39 PDT
(In reply to Michael Catanzaro from comment #2)
> Actually I'm not certain it's really a regression, because there are
> preexisting calls to pthread_getattr_np() (or pthread_get_stacksize_np() on
> Darwin) that would likely have had the same problem.

I think it's OK because this returns the real stack size, not the limit. Also, it works fine in practice with no changes to this.
Comment 6 Daniel Kolesa 2021-10-27 04:46:29 PDT
patch lgtm
Comment 7 Radar WebKit Bug Importer 2021-11-02 13:00:26 PDT
<rdar://problem/84943302>
Comment 8 Michael Catanzaro 2021-11-02 13:43:41 PDT
Ping reviewers
Comment 9 Yusuke Suzuki 2021-11-02 15:03:23 PDT
Comment on attachment 442530 [details]
Patch

r=me
Comment 10 EWS 2021-11-02 15:09:33 PDT
Committed r285187 (243816@main): <https://commits.webkit.org/243816@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 442530 [details].