Bug 214067 - Add a way to return early from detected infinite loops to aid the fuzzer
Summary: Add a way to return early from detected infinite loops to aid the fuzzer
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-07 19:13 PDT by Saam Barati
Modified: 2020-07-08 09:43 PDT (History)
16 users (show)

See Also:


Attachments
patch (20.04 KB, patch)
2020-07-07 20:33 PDT, Saam Barati
ysuzuki: review+
Details | Formatted Diff | Diff
patch for landing (19.96 KB, patch)
2020-07-07 21:20 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch for landing (20.94 KB, patch)
2020-07-07 22:42 PDT, Saam Barati
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2020-07-07 19:13:04 PDT
...
Comment 1 Saam Barati 2020-07-07 20:33:29 PDT
Created attachment 403753 [details]
patch
Comment 2 Yusuke Suzuki 2020-07-07 20:44:51 PDT
Comment on attachment 403753 [details]
patch

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

r=me

> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:14718
> +        patchpoint->effects.writesLocalState = true;

patchpoint->clobber(RegisterSet::macroScratchRegisters()); is required.

> Source/JavaScriptCore/runtime/VM.cpp:1562
> +        uint64_t* ptr = static_cast<uint64_t*>(fastMalloc(sizeof(uint64_t)));
> +        *ptr = 0;
> +        addResult.iterator->value.second = ptr;

How about using `std::unique_ptr<uint64_t>` & `makeUnique<uint64_t>()`?

> Source/JavaScriptCore/runtime/VM.cpp:1582
> +        fastFree(iter->value.second);

Then, we can remove this.
Comment 3 Saam Barati 2020-07-07 20:50:03 PDT
Comment on attachment 403753 [details]
patch

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

>> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:14718
>> +        patchpoint->effects.writesLocalState = true;
> 
> patchpoint->clobber(RegisterSet::macroScratchRegisters()); is required.

Actually I tried to not make it so that we use them. I added AllowMacroScratxh RAII before I refactored the code. I will remove the RAII

>> Source/JavaScriptCore/runtime/VM.cpp:1562
>> +        addResult.iterator->value.second = ptr;
> 
> How about using `std::unique_ptr<uint64_t>` & `makeUnique<uint64_t>()`?

Sounds good
Comment 4 Mark Lam 2020-07-07 21:05:02 PDT
Comment on attachment 403753 [details]
patch

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

> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:468
> +        *ptr += codeBlock->llintExecuteCounter().m_activeThreshold;

Why inc by m_activeThreshold here and only by 1 in the JITs?
Comment 5 Saam Barati 2020-07-07 21:07:04 PDT
Comment on attachment 403753 [details]
patch

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

>> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:468
>> +        *ptr += codeBlock->llintExecuteCounter().m_activeThreshold;
> 
> Why inc by m_activeThreshold here and only by 1 in the JITs?

this is just a heuristic of how much we've executed. This is actually slightly higher than what we've executed. It's because I don't want to change the LLInt's runtime code. But changing the JITs is trivial, since it's controlled behind a runtime option.
Comment 6 Saam Barati 2020-07-07 21:20:30 PDT
Created attachment 403757 [details]
patch for landing
Comment 7 Mark Lam 2020-07-07 21:23:06 PDT
Comment on attachment 403753 [details]
patch

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

>>> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:468
>>> +        *ptr += codeBlock->llintExecuteCounter().m_activeThreshold;
>> 
>> Why inc by m_activeThreshold here and only by 1 in the JITs?
> 
> this is just a heuristic of how much we've executed. This is actually slightly higher than what we've executed. It's because I don't want to change the LLInt's runtime code. But changing the JITs is trivial, since it's controlled behind a runtime option.

OK, I understand now.  The detail to note is that this function (llint_loop_osr) is only called once after the loop_hint has been visited m_activeThreshold times.  It is not called on every loop_hint.
Comment 8 Saam Barati 2020-07-07 22:42:39 PDT
Created attachment 403758 [details]
patch for landing

Now skipping this for builtin functions, since we rely on some of those not early returning out of loops for the integrity of data structures we create.
Comment 9 EWS 2020-07-08 09:42:59 PDT
Committed r264105: <https://trac.webkit.org/changeset/264105>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 403758 [details].
Comment 10 Radar WebKit Bug Importer 2020-07-08 09:43:16 PDT
<rdar://problem/65227843>