Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 058485b

Browse files
akroshgchakrabot
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@8b56bb5028
[1.8>1.9] [MERGE #4812 @akroshg] ChakraCore 2018-03 Security updates Merge pull request #4812 from akroshg:test1803_1 Pushing 18-03 changes. Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
1 parent f7e7601 commit 058485b

31 files changed

+269
-256
lines changed

deps/chakrashim/core/Build/Common.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<!-- Separate global variable for linker -->
7979
<AdditionalOptions>%(AdditionalOptions) /Gw</AdditionalOptions>
8080

81+
<!-- Enable warnings not included in W4 by default -->
82+
<AdditionalOptions>%(AdditionalOptions) /w44242 /w44254</AdditionalOptions>
83+
8184
<ProgramDataBaseFileName Condition="'$(ConfigurationType)'=='StaticLibrary'">$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
8285
<ProgramDataBaseFileName Condition="'$(ConfigurationType)'!='StaticLibrary'">$(IntDir)</ProgramDataBaseFileName>
8386

deps/chakrashim/core/bin/NativeTests/NativeTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define CATCH_CONFIG_RUNNER
88
#pragma warning(push)
99
// conversion from 'int' to 'char', possible loss of data
10+
#pragma warning(disable:4242)
1011
#pragma warning(disable:4244)
1112
#include "catch.hpp"
1213
#pragma warning(pop)

deps/chakrashim/core/lib/Backend/BailOut.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,11 @@ BailOutRecord::BailOutInlinedHelper(Js::JavascriptCallStackLayout * layout, Bail
13011301
InlineeFrameRecord* inlineeFrameRecord = entryPointInfo->FindInlineeFrame(returnAddress);
13021302
if (inlineeFrameRecord)
13031303
{
1304+
// While bailing out, RestoreFrames should box all Vars on the stack. If there are multiple Vars pointing to the same
1305+
// object, the cached version (that was previously boxed) will be reused to maintain pointer identity and correctness
1306+
// after the transition to the interpreter.
13041307
InlinedFrameLayout* outerMostFrame = (InlinedFrameLayout *)(((uint8 *)Js::JavascriptCallStackLayout::ToFramePointer(layout)) - entryPointInfo->frameHeight);
1305-
inlineeFrameRecord->RestoreFrames(functionBody, outerMostFrame, layout, false /* deepCopy */);
1308+
inlineeFrameRecord->RestoreFrames(functionBody, outerMostFrame, layout, true /* boxArgs */);
13061309
}
13071310
}
13081311

deps/chakrashim/core/lib/Backend/GlobOpt.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,8 +2481,11 @@ GlobOpt::OptInstr(IR::Instr *&instr, bool* isInstrRemoved)
24812481
CurrentBlockData()->KillStateForGeneratorYield();
24822482
}
24832483

2484-
// Change LdFld on arrays, strings, and 'arguments' to LdLen when we're accessing the .length field
2485-
this->TryReplaceLdLen(instr);
2484+
if (!IsLoopPrePass())
2485+
{
2486+
// Change LdFld on arrays, strings, and 'arguments' to LdLen when we're accessing the .length field
2487+
this->TryReplaceLdLen(instr);
2488+
}
24862489

24872490
// Consider: Do we ever get post-op bailout here, and if so is the FillBailOutInfo call in the right place?
24882491
if (instr->HasBailOutInfo() && !this->IsLoopPrePass())
@@ -13440,6 +13443,9 @@ GlobOpt::OptArraySrc(IR::Instr * *const instrRef)
1344013443
return;
1344113444
}
1344213445

13446+
const bool isLikelyVirtualTypedArray = baseValueType.IsLikelyOptimizedVirtualTypedArray();
13447+
Assert(!(isLikelyJsArray && isLikelyVirtualTypedArray));
13448+
1344313449
ValueType newBaseValueType(baseValueType.ToDefiniteObject());
1344413450
if(isLikelyJsArray && newBaseValueType.HasNoMissingValues() && !DoArrayMissingValueCheckHoist())
1344513451
{
@@ -13770,7 +13776,7 @@ GlobOpt::OptArraySrc(IR::Instr * *const instrRef)
1377013776
{
1377113777
const JsArrayKills loopKills(loop->jsArrayKills);
1377213778
Value *baseValueInLoopLandingPad = nullptr;
13773-
if((isLikelyJsArray && loopKills.KillsValueType(newBaseValueType)) ||
13779+
if(((isLikelyJsArray || isLikelyVirtualTypedArray) && loopKills.KillsValueType(newBaseValueType)) ||
1377413780
!OptIsInvariant(baseOpnd->m_sym, currentBlock, loop, baseValue, true, true, &baseValueInLoopLandingPad) ||
1377513781
!(doArrayChecks || baseValueInLoopLandingPad->GetValueInfo()->IsObject()))
1377613782
{
@@ -17384,7 +17390,9 @@ GlobOpt::DoArrayCheckHoist(const ValueType baseValueType, Loop* loop, IR::Instr
1738417390
return false;
1738517391
}
1738617392

17387-
if(!baseValueType.IsLikelyArrayOrObjectWithArray() ||
17393+
// This includes typed arrays, but not virtual typed arrays, whose vtable can change if the buffer goes away.
17394+
// Note that in the virtual case the vtable check is the only way to catch this, since there's no bound check.
17395+
if(!(baseValueType.IsLikelyArrayOrObjectWithArray() || baseValueType.IsLikelyOptimizedVirtualTypedArray()) ||
1738817396
(loop ? ImplicitCallFlagsAllowOpts(loop) : ImplicitCallFlagsAllowOpts(func)))
1738917397
{
1739017398
return true;

deps/chakrashim/core/lib/Backend/GlobOpt.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,16 @@ class JsArrayKills
332332
public:
333333
bool KillsValueType(const ValueType valueType) const
334334
{
335-
Assert(valueType.IsArrayOrObjectWithArray());
335+
Assert(valueType.IsArrayOrObjectWithArray() || valueType.IsOptimizedVirtualTypedArray());
336336

337337
return
338338
killsAllArrays ||
339-
(killsArraysWithNoMissingValues && valueType.HasNoMissingValues()) ||
340-
(killsNativeArrays && !valueType.HasVarElements());
339+
(valueType.IsArrayOrObjectWithArray() &&
340+
(
341+
(killsArraysWithNoMissingValues && valueType.HasNoMissingValues()) ||
342+
(killsNativeArrays && !valueType.HasVarElements())
343+
)
344+
);
341345
}
342346

343347
bool AreSubsetOf(const JsArrayKills &other) const

deps/chakrashim/core/lib/Backend/InlineeFrameInfo.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ void InlineeFrameRecord::Finalize(Func* inlinee, uint32 currentOffset)
199199
Assert(this->inlineDepth != 0);
200200
}
201201

202-
void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLayout *inlinedFrame, Js::JavascriptCallStackLayout * layout, bool deepCopy) const
202+
void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLayout *inlinedFrame, Js::JavascriptCallStackLayout * layout, bool boxValues) const
203203
{
204204
Assert(this->inlineDepth != 0);
205205
Assert(inlineeStartOffset != 0);
206206

207207
BAILOUT_VERBOSE_TRACE(functionBody, _u("Restore function object: "));
208208
// No deepCopy needed for just the function
209-
Js::Var varFunction = this->Restore(this->functionOffset, /*isFloat64*/ false, /*isInt32*/ false, layout, functionBody, /*deepCopy*/ false);
209+
Js::Var varFunction = this->Restore(this->functionOffset, /*isFloat64*/ false, /*isInt32*/ false, layout, functionBody, boxValues);
210210
Assert(Js::ScriptFunction::Is(varFunction));
211211

212212
Js::ScriptFunction* function = Js::ScriptFunction::FromVar(varFunction);
@@ -222,9 +222,9 @@ void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLay
222222

223223
// Forward deepCopy flag for the arguments in case their data must be guaranteed
224224
// to have its own lifetime
225-
Js::Var var = this->Restore(this->argOffsets[i], isFloat64, isInt32, layout, functionBody, deepCopy);
225+
Js::Var var = this->Restore(this->argOffsets[i], isFloat64, isInt32, layout, functionBody, boxValues);
226226
#if DBG
227-
if (!Js::TaggedNumber::Is(var))
227+
if (boxValues && !Js::TaggedNumber::Is(var))
228228
{
229229
Js::RecyclableObject *const recyclableObject = Js::RecyclableObject::FromVar(var);
230230
Assert(!ThreadContext::IsOnStack(recyclableObject));
@@ -236,7 +236,10 @@ void InlineeFrameRecord::Restore(Js::FunctionBody* functionBody, InlinedFrameLay
236236
BAILOUT_FLUSH(functionBody);
237237
}
238238

239-
void InlineeFrameRecord::RestoreFrames(Js::FunctionBody* functionBody, InlinedFrameLayout* outerMostFrame, Js::JavascriptCallStackLayout* callstack, bool deepCopy)
239+
// Note: the boxValues parameter should be true when this is called from a Bailout codepath to ensure that multiple vars to
240+
// the same object reuse the cached value during the transition to the interpreter.
241+
// Otherwise, this parameter should be false as the values are not required to be moved to the heap to restore the frame.
242+
void InlineeFrameRecord::RestoreFrames(Js::FunctionBody* functionBody, InlinedFrameLayout* outerMostFrame, Js::JavascriptCallStackLayout* callstack, bool boxValues)
240243
{
241244
InlineeFrameRecord* innerMostRecord = this;
242245
class AutoReverse
@@ -274,7 +277,7 @@ void InlineeFrameRecord::RestoreFrames(Js::FunctionBody* functionBody, InlinedFr
274277

275278
while (currentRecord)
276279
{
277-
currentRecord->Restore(functionBody, currentFrame, callstack, deepCopy);
280+
currentRecord->Restore(functionBody, currentFrame, callstack, boxValues);
278281
currentRecord = currentRecord->parent;
279282
currentFrame = currentFrame->Next();
280283
}
@@ -283,10 +286,10 @@ void InlineeFrameRecord::RestoreFrames(Js::FunctionBody* functionBody, InlinedFr
283286
currentFrame->callInfo.Count = 0;
284287
}
285288

286-
Js::Var InlineeFrameRecord::Restore(int offset, bool isFloat64, bool isInt32, Js::JavascriptCallStackLayout * layout, Js::FunctionBody* functionBody, bool deepCopy) const
289+
Js::Var InlineeFrameRecord::Restore(int offset, bool isFloat64, bool isInt32, Js::JavascriptCallStackLayout * layout, Js::FunctionBody* functionBody, bool boxValue) const
287290
{
288291
Js::Var value;
289-
bool boxStackInstance = true;
292+
bool boxStackInstance = boxValue;
290293
double dblValue;
291294
if (offset >= 0)
292295
{
@@ -324,8 +327,11 @@ Js::Var InlineeFrameRecord::Restore(int offset, bool isFloat64, bool isInt32, Js
324327
BAILOUT_VERBOSE_TRACE(functionBody, _u(", value: 0x%p"), value);
325328
if (boxStackInstance)
326329
{
330+
// Do not deepCopy in this call to BoxStackInstance because this should be used for
331+
// bailing out, where a shallow copy that is cached is needed to ensure that multiple
332+
// vars pointing to the same boxed object reuse the new boxed value.
327333
Js::Var oldValue = value;
328-
value = Js::JavascriptOperators::BoxStackInstance(oldValue, functionBody->GetScriptContext(), /* allowStackFunction */ true, deepCopy);
334+
value = Js::JavascriptOperators::BoxStackInstance(oldValue, functionBody->GetScriptContext(), /* allowStackFunction */ true, false /* deepCopy */);
329335

330336
#if ENABLE_DEBUG_CONFIG_OPTIONS
331337
if (oldValue != value)

deps/chakrashim/core/lib/Backend/InlineeFrameInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct InlineeFrameRecord
108108
}
109109

110110
void PopulateParent(Func* func);
111-
void RestoreFrames(Js::FunctionBody* functionBody, InlinedFrameLayout* outerMostInlinee, Js::JavascriptCallStackLayout* callstack, bool deepCopy);
111+
void RestoreFrames(Js::FunctionBody* functionBody, InlinedFrameLayout* outerMostInlinee, Js::JavascriptCallStackLayout* callstack, bool boxValues);
112112
void Finalize(Func* inlinee, uint currentOffset);
113113
#if DBG_DUMP
114114
void Dump() const;
@@ -123,8 +123,8 @@ struct InlineeFrameRecord
123123
}
124124

125125
private:
126-
void Restore(Js::FunctionBody* functionBody, InlinedFrameLayout *outerMostFrame, Js::JavascriptCallStackLayout * layout, bool deepCopy) const;
127-
Js::Var Restore(int offset, bool isFloat64, bool isInt32, Js::JavascriptCallStackLayout * layout, Js::FunctionBody* functionBody, bool deepCopy) const;
126+
void Restore(Js::FunctionBody* functionBody, InlinedFrameLayout *outerMostFrame, Js::JavascriptCallStackLayout * layout, bool boxValues) const;
127+
Js::Var Restore(int offset, bool isFloat64, bool isInt32, Js::JavascriptCallStackLayout * layout, Js::FunctionBody* functionBody, bool boxValue) const;
128128
InlineeFrameRecord* Reverse();
129129
};
130130

deps/chakrashim/core/lib/Common/CommonDefines.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@
320320

321321
#ifndef NTBUILD
322322
#define DELAYLOAD_SECTIONAPI 1
323-
#else
323+
#define DELAYLOAD_UNLOCKMEMORY 1
324+
#endif
325+
326+
#ifdef NTBUILD
324327
#define ENABLE_PROJECTION
325328
#define ENABLE_FOUNDATION_OBJECT
326329
#define ENABLE_EXPERIMENTAL_FLAGS

deps/chakrashim/core/lib/Common/Core/DelayLoadLibrary.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,43 @@ NtdllLibrary::NTSTATUS NtdllLibrary::Close(_In_ HANDLE Handle)
317317
#endif
318318
}
319319

320+
#ifndef DELAYLOAD_UNLOCKMEMORY
321+
extern "C"
322+
WINBASEAPI
323+
NtdllLibrary::NTSTATUS
324+
WINAPI
325+
NtUnlockVirtualMemory(
326+
_In_ HANDLE ProcessHandle,
327+
_Inout_ PVOID *BaseAddress,
328+
_Inout_ PSIZE_T RegionSize,
329+
_In_ ULONG MapType
330+
);
331+
#endif
332+
333+
NtdllLibrary::NTSTATUS NtdllLibrary::UnlockVirtualMemory(
334+
_In_ HANDLE ProcessHandle,
335+
_Inout_ PVOID *BaseAddress,
336+
_Inout_ PSIZE_T RegionSize,
337+
_In_ ULONG MapType)
338+
{
339+
#ifdef DELAYLOAD_UNLOCKMEMORY
340+
if (m_hModule)
341+
{
342+
if (unlock == nullptr)
343+
{
344+
unlock = (PFnNtUnlockVirtualMemory)GetFunction("NtUnlockVirtualMemory");
345+
if (unlock == nullptr)
346+
{
347+
Assert(false);
348+
return -1;
349+
}
350+
}
351+
return unlock(ProcessHandle, BaseAddress, RegionSize, MapType);
352+
}
353+
return -1;
354+
#else
355+
return NtUnlockVirtualMemory(ProcessHandle, BaseAddress, RegionSize, MapType);
356+
#endif
357+
}
358+
320359
#endif // _WIN32

deps/chakrashim/core/lib/Common/Core/DelayLoadLibrary.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class NtdllLibrary : protected DelayLoadLibrary
3434
public:
3535
// needed for InitializeObjectAttributes
3636
static const ULONG OBJ_KERNEL_HANDLE = 0x00000200;
37+
static const ULONG MAP_PROCESS = 1;
3738

3839
typedef struct _UNICODE_STRING {
3940
USHORT Length;
@@ -105,6 +106,13 @@ class NtdllLibrary : protected DelayLoadLibrary
105106
typedef NTSTATUS(NTAPI *PFnNtClose)(_In_ HANDLE Handle);
106107
PFnNtClose close;
107108

109+
typedef NTSTATUS(NTAPI *PFnNtUnlockVirtualMemory)(
110+
_In_ HANDLE ProcessHandle,
111+
_Inout_ PVOID *BaseAddress,
112+
_Inout_ PSIZE_T RegionSize,
113+
_In_ ULONG MapType);
114+
PFnNtUnlockVirtualMemory unlock;
115+
108116
public:
109117
static NtdllLibrary* Instance;
110118

@@ -117,7 +125,8 @@ class NtdllLibrary : protected DelayLoadLibrary
117125
createSection(NULL),
118126
mapViewOfSection(NULL),
119127
unmapViewOfSection(NULL),
120-
close(NULL)
128+
close(NULL),
129+
unlock(nullptr)
121130
{
122131
this->EnsureFromSystemDirOnly();
123132
}
@@ -176,5 +185,12 @@ class NtdllLibrary : protected DelayLoadLibrary
176185
NTSTATUS Close(
177186
_In_ HANDLE Handle
178187
);
188+
189+
NTSTATUS UnlockVirtualMemory(
190+
_In_ HANDLE ProcessHandle,
191+
_Inout_ PVOID *BaseAddress,
192+
_Inout_ PSIZE_T RegionSize,
193+
_In_ ULONG MapType
194+
);
179195
};
180196
#endif

deps/chakrashim/core/lib/Common/Memory/RecyclerSweep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ RecyclerSweep::EndSweep()
290290

291291
// Clean up the HeapBlockMap.
292292
// This will release any internal structures that are no longer needed after Sweep.
293-
recycler->heapBlockMap.Cleanup(!recycler->IsMemProtectMode());
293+
recycler->heapBlockMap.Cleanup(recycler->IsMemProtectMode());
294294
}
295295

296296
#if ENABLE_CONCURRENT_GC

0 commit comments

Comments
 (0)