Bug 171162 - [JSC] Get stack pointer without pthread attr
Summary: [JSC] Get stack pointer without pthread attr
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-22 09:00 PDT by Yusuke Suzuki
Modified: 2017-04-22 11:08 PDT (History)
11 users (show)

See Also:


Attachments
Patch (4.58 KB, patch)
2017-04-22 09:33 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (4.87 KB, patch)
2017-04-22 09:47 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (5.49 KB, patch)
2017-04-22 10:09 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (5.49 KB, patch)
2017-04-22 10:11 PDT, Yusuke Suzuki
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2017-04-22 09:00:25 PDT
pthread_ attr operations are not safe for calling it when the thread is suspended since it can invoke malloc / free.
We would like to retrieve stack pointer without using pthread attr operations, like,

NEVER_INLINES void* getPossibleStackPointer()
{
    volatile void* stackLocation = nullptr;
    return &stackLocation;
}
Comment 1 Yusuke Suzuki 2017-04-22 09:33:18 PDT
Created attachment 307909 [details]
Patch
Comment 2 Yusuke Suzuki 2017-04-22 09:35:14 PDT
Comment on attachment 307909 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307909&action=review

> Source/WTF/wtf/ThreadingPthreads.cpp:101
> +}

Now, we do not consider about alternative signal stack explicitly. Originally, it is not safe with conservative GC by nature.
Comment 3 Yusuke Suzuki 2017-04-22 09:47:50 PDT
Created attachment 307910 [details]
Patch
Comment 4 Yusuke Suzuki 2017-04-22 10:09:12 PDT
Created attachment 307911 [details]
Patch
Comment 5 Yusuke Suzuki 2017-04-22 10:11:21 PDT
Created attachment 307912 [details]
Patch
Comment 6 Mark Lam 2017-04-22 10:15:26 PDT
Comment on attachment 307912 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307912&action=review

r=me with fixes.

> Source/WTF/wtf/ThreadingPthreads.cpp:115
> +    int ret = sigaltstack(nullptr, &stack);

typo: /sigaltstack/signaltstack/

> Source/WTF/wtf/ThreadingPthreads.cpp:136
> +    ASSERT_WITH_MESSAGE(!isOnAlternativeSignalStack(), "Do not support alternative signal stack. Consider disabling concurrent GC.");

Let's change the message to "Using an alternative signal stack is not supported. Consider disabling the concurrent GC."

Also, I suggest making this a RELEASE_ASSERT.  I think this code is not performance critical, and this failure is critical and may be hard to detect if not asserted.
Comment 7 Mark Lam 2017-04-22 10:30:25 PDT
Comment on attachment 307912 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307912&action=review

>> Source/WTF/wtf/ThreadingPthreads.cpp:115
>> +    int ret = sigaltstack(nullptr, &stack);
> 
> typo: /sigaltstack/signaltstack/

Yusuke pointed out that I was wrong.  sigaltstack is correct.

> Source/WTF/wtf/ThreadingPthreads.cpp:117
> +    ASSERT_UNUSED(ret, ret);
> +    return stack.ss_flags == SS_ONSTACK;

If this assert is critical, you can combine it with the return value instead:

    return ret && stack.ss_flags == SS_ONSTACK;
Comment 8 Yusuke Suzuki 2017-04-22 10:53:56 PDT
Comment on attachment 307912 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307912&action=review

Thanks!

> Source/WTF/wtf/ThreadingPthreads.cpp:116
> +    ASSERT_UNUSED(ret, ret);

This will be changed to RELEASE_ASSERT(!ret).

>> Source/WTF/wtf/ThreadingPthreads.cpp:117
>> +    return stack.ss_flags == SS_ONSTACK;
> 
> If this assert is critical, you can combine it with the return value instead:
> 
>     return ret && stack.ss_flags == SS_ONSTACK;

I think this |ret| never becomes non-zero. So, if it is non-zero, some crazy thing happens I think.
I would like to have two assertions for that to investigate what is wrong if the assertion is fired.

>> Source/WTF/wtf/ThreadingPthreads.cpp:136
>> +    ASSERT_WITH_MESSAGE(!isOnAlternativeSignalStack(), "Do not support alternative signal stack. Consider disabling concurrent GC.");
> 
> Let's change the message to "Using an alternative signal stack is not supported. Consider disabling the concurrent GC."
> 
> Also, I suggest making this a RELEASE_ASSERT.  I think this code is not performance critical, and this failure is critical and may be hard to detect if not asserted.

Yeah, changed.
Comment 9 Yusuke Suzuki 2017-04-22 11:03:44 PDT
Comment on attachment 307912 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307912&action=review

>>> Source/WTF/wtf/ThreadingPthreads.cpp:136
>>> +    ASSERT_WITH_MESSAGE(!isOnAlternativeSignalStack(), "Do not support alternative signal stack. Consider disabling concurrent GC.");
>> 
>> Let's change the message to "Using an alternative signal stack is not supported. Consider disabling the concurrent GC."
>> 
>> Also, I suggest making this a RELEASE_ASSERT.  I think this code is not performance critical, and this failure is critical and may be hard to detect if not asserted.
> 
> Yeah, changed.

I've considered about it a bit more. This signal function is guarded by a global mutex, and GC / sampling profiler invokes it repeatedly. So, I think this function is a bit frequently called.
And sigaltstack is system call. I think it is not good.
Temporary, I would like to make it usual ASSERT for this reason.
Comment 10 Yusuke Suzuki 2017-04-22 11:08:10 PDT
Committed r215667: <http://trac.webkit.org/changeset/215667>