<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279341] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279341">279341</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2021-06-28 09:48:33 -0700 (Mon, 28 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Prevent sign-extended casts for 32 bits arch
https://bugs.webkit.org/show_bug.cgi?id=227170

Patch by Mikhail R. Gadelha <mikhail@igalia.com> on 2021-06-28
Reviewed by Yusuke Suzuki.

In a number of places, addresses are reinterpreted as uint64, which can
lead to wrong addresses in 32 bits arch.

Source/JavaScriptCore:

* assembler/testmasm.cpp:
(JSC::testBranchTruncateDoubleToInt32):
* disassembler/ARM64/A64DOpcode.h:
(JSC::ARM64Disassembler::A64DOpcode::appendPCRelativeOffset):
* runtime/JSCell.cpp:
(JSC::reportZappedCellAndCrash):
* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::emitEntryTierUpCheck):
(JSC::Wasm::AirIRGenerator::emitLoopTierUpCheck):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::emitEntryTierUpCheck):
(JSC::Wasm::B3IRGenerator::emitLoopTierUpCheck):

Source/WTF:

* wtf/LoggerHelper.h:
(WTF::LoggerHelper::childLogIdentifier):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblertestmasmcpp">trunk/Source/JavaScriptCore/assembler/testmasm.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredisassemblerARM64A64DOpcodeh">trunk/Source/JavaScriptCore/disassembler/ARM64/A64DOpcode.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSCellcpp">trunk/Source/JavaScriptCore/runtime/JSCell.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmAirIRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfLoggerHelperh">trunk/Source/WTF/wtf/LoggerHelper.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/ChangeLog       2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2021-06-28  Mikhail R. Gadelha  <mikhail@igalia.com>
+
+        Prevent sign-extended casts for 32 bits arch
+        https://bugs.webkit.org/show_bug.cgi?id=227170
+
+        Reviewed by Yusuke Suzuki.
+
+        In a number of places, addresses are reinterpreted as uint64, which can
+        lead to wrong addresses in 32 bits arch.
+
+        * assembler/testmasm.cpp:
+        (JSC::testBranchTruncateDoubleToInt32):
+        * disassembler/ARM64/A64DOpcode.h:
+        (JSC::ARM64Disassembler::A64DOpcode::appendPCRelativeOffset):
+        * runtime/JSCell.cpp:
+        (JSC::reportZappedCellAndCrash):
+        * wasm/WasmAirIRGenerator.cpp:
+        (JSC::Wasm::AirIRGenerator::emitEntryTierUpCheck):
+        (JSC::Wasm::AirIRGenerator::emitLoopTierUpCheck):
+        * wasm/WasmB3IRGenerator.cpp:
+        (JSC::Wasm::B3IRGenerator::emitEntryTierUpCheck):
+        (JSC::Wasm::B3IRGenerator::emitLoopTierUpCheck):
+
</ins><span class="cx"> 2021-06-25  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, reverting r279266.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblertestmasmcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/testmasm.cpp (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/testmasm.cpp       2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/assembler/testmasm.cpp  2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx"> // Nan, should either yield 0 in dest or fail.
</span><span class="cx"> void testBranchTruncateDoubleToInt32(double val, int32_t expected)
</span><span class="cx"> {
</span><del>-    const uint64_t valAsUInt = *reinterpret_cast<uint64_t*>(&val);
</del><ins>+    const uint64_t valAsUInt = bitwise_cast<uint64_t>(val);
</ins><span class="cx"> #if CPU(BIG_ENDIAN)
</span><span class="cx">     const bool isBigEndian = true;
</span><span class="cx"> #else
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredisassemblerARM64A64DOpcodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/disassembler/ARM64/A64DOpcode.h (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/disassembler/ARM64/A64DOpcode.h      2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/disassembler/ARM64/A64DOpcode.h 2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -187,7 +187,7 @@
</span><span class="cx"> 
</span><span class="cx">     void appendPCRelativeOffset(uint32_t* pc, int32_t immediate)
</span><span class="cx">     {
</span><del>-        bufferPrintf("0x%" PRIx64, reinterpret_cast<uint64_t>(pc + immediate));
</del><ins>+        bufferPrintf("0x%" PRIxPTR, bitwise_cast<uintptr_t>(pc + immediate));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void appendShiftAmount(unsigned amount)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp      2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/jsc.cpp 2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -1480,7 +1480,7 @@
</span><span class="cx">     if (!value.isCell())
</span><span class="cx">         return JSValue::encode(jsUndefined());
</span><span class="cx">     // Need to cast to uint64_t so bitwise_cast will play along.
</span><del>-    uint64_t asNumber = reinterpret_cast<uintptr_t>(value.asCell());
</del><ins>+    uint64_t asNumber = bitwise_cast<uintptr_t>(value.asCell());
</ins><span class="cx">     EncodedJSValue returnValue = JSValue::encode(jsNumber(bitwise_cast<double>(asNumber)));
</span><span class="cx">     return returnValue;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSCellcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSCell.cpp (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSCell.cpp   2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/runtime/JSCell.cpp      2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx">         variousState |= static_cast<uint64_t>(foundBlockHandle->needsDestruction()) << 3;
</span><span class="cx">         variousState |= static_cast<uint64_t>(foundBlock->isNewlyAllocated(cell)) << 4;
</span><span class="cx"> 
</span><del>-        ptrdiff_t cellOffset = cellAddress - reinterpret_cast<uint64_t>(foundBlockHandle->start());
</del><ins>+        ptrdiff_t cellOffset = cellAddress - bitwise_cast<uintptr_t>(foundBlockHandle->start());
</ins><span class="cx">         bool cellIsProperlyAligned = !(cellOffset % cellSize);
</span><span class="cx">         variousState |= static_cast<uint64_t>(cellIsProperlyAligned) << 5;
</span><span class="cx">     } else {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmAirIRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp  2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp     2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -2808,9 +2808,8 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     auto countdownPtr = g64();
</span><ins>+    append(Move, Arg::bigImm(bitwise_cast<uintptr_t>(&m_tierUp->m_counter)), countdownPtr);
</ins><span class="cx"> 
</span><del>-    append(Move, Arg::bigImm(reinterpret_cast<uint64_t>(&m_tierUp->m_counter)), countdownPtr);
-
</del><span class="cx">     auto* patch = addPatchpoint(B3::Void);
</span><span class="cx">     B3::Effects effects = B3::Effects::none();
</span><span class="cx">     effects.reads = B3::HeapRange::top();
</span><span class="lines">@@ -2860,9 +2859,8 @@
</span><span class="cx">     m_tierUp->outerLoops().append(outerLoopIndex);
</span><span class="cx"> 
</span><span class="cx">     auto countdownPtr = g64();
</span><ins>+    append(Move, Arg::bigImm(bitwise_cast<uintptr_t>(&m_tierUp->m_counter)), countdownPtr);
</ins><span class="cx"> 
</span><del>-    append(Move, Arg::bigImm(reinterpret_cast<uint64_t>(&m_tierUp->m_counter)), countdownPtr);
-
</del><span class="cx">     auto* patch = addPatchpoint(B3::Void);
</span><span class="cx">     B3::Effects effects = B3::Effects::none();
</span><span class="cx">     effects.reads = B3::HeapRange::top();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp   2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp      2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -2030,7 +2030,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_tierUp);
</span><del>-    Value* countDownLocation = constant(pointerType(), reinterpret_cast<uint64_t>(&m_tierUp->m_counter), Origin());
</del><ins>+    Value* countDownLocation = constant(pointerType(), bitwise_cast<uintptr_t>(&m_tierUp->m_counter), Origin());
</ins><span class="cx"> 
</span><span class="cx">     PatchpointValue* patch = m_currentBlock->appendNew<PatchpointValue>(m_proc, B3::Void, Origin());
</span><span class="cx">     Effects effects = Effects::none();
</span><span class="lines">@@ -2080,7 +2080,7 @@
</span><span class="cx">     m_tierUp->osrEntryTriggers().append(TierUpCount::TriggerReason::DontTrigger);
</span><span class="cx">     m_tierUp->outerLoops().append(outerLoopIndex);
</span><span class="cx"> 
</span><del>-    Value* countDownLocation = constant(pointerType(), reinterpret_cast<uint64_t>(&m_tierUp->m_counter), origin);
</del><ins>+    Value* countDownLocation = constant(pointerType(), bitwise_cast<uintptr_t>(&m_tierUp->m_counter), origin);
</ins><span class="cx"> 
</span><span class="cx">     Vector<ExpressionType> stackmap;
</span><span class="cx">     for (auto& local : m_locals) {
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/WTF/ChangeLog  2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-06-28  Mikhail R. Gadelha  <mikhail@igalia.com>
+
+        Prevent sign-extended casts for 32 bits arch
+        https://bugs.webkit.org/show_bug.cgi?id=227170
+
+        Reviewed by Yusuke Suzuki.
+
+        In a number of places, addresses are reinterpreted as uint64, which can
+        lead to wrong addresses in 32 bits arch.
+
+        * wtf/LoggerHelper.h:
+        (WTF::LoggerHelper::childLogIdentifier):
+
</ins><span class="cx"> 2021-06-28  Sam Weinig  <weinig@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add helpers to create Spans from CFDataRef and NSData
</span></span></pre></div>
<a id="trunkSourceWTFwtfLoggerHelperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/LoggerHelper.h (279340 => 279341)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/LoggerHelper.h      2021-06-28 16:39:19 UTC (rev 279340)
+++ trunk/Source/WTF/wtf/LoggerHelper.h 2021-06-28 16:48:33 UTC (rev 279341)
</span><span class="lines">@@ -76,7 +76,7 @@
</span><span class="cx">     {
</span><span class="cx">         static constexpr uint64_t parentMask = 0xffffffffffff0000ull;
</span><span class="cx">         static constexpr uint64_t maskLowerWord = 0xffffull;
</span><del>-        return reinterpret_cast<const void*>((reinterpret_cast<uint64_t>(parentIdentifier) & parentMask) | (childIdentifier & maskLowerWord));
</del><ins>+        return reinterpret_cast<const void*>((bitwise_cast<uintptr_t>(parentIdentifier) & parentMask) | (childIdentifier & maskLowerWord));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     static const void* uniqueLogIdentifier()
</span></span></pre>
</div>
</div>

</body>
</html>