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

Commit

Permalink
chakrashim: update chakracore to 1.1.0.5
Browse files Browse the repository at this point in the history
Update chakracore to 1.1.0.5
(head b30c60d09a8e1bae2ba88398d4ece4dbe8e65092).

PR-URL: #47
Reviewed-By: Sandeep Agarwal <Agarwal.Sandeep@microsoft.com>
  • Loading branch information
Jianchun Xu committed Mar 31, 2016
1 parent b838007 commit d9469f1
Show file tree
Hide file tree
Showing 45 changed files with 663 additions and 515 deletions.
41 changes: 0 additions & 41 deletions deps/chakrashim/core/jenkins.check_copyright.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
setlocal

set JENKINS_BUILD=True
call test\jenkins.testall.cmd %*
call %~dp0..\test\jenkins.buildall.cmd %*

endlocal
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if "%2"=="" (
:main

set JENKINS_BUILD=True
call test\jenkins.buildone.cmd %*
call %~dp0..\test\jenkins.buildone.cmd %*

goto :end

Expand Down
60 changes: 60 additions & 0 deletions deps/chakrashim/core/jenkins/check_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

# Python 2.7 and 3.x compatibility for easier testing regardless of python installation
from __future__ import print_function

import sys
import os.path
import re

copyright_lines = [
r'-------------------------------------------------------------------------------------------------------',
r' Copyright \(C\) Microsoft( Corporation and contributors)?\. All rights reserved\.',
r' Licensed under the MIT license\. See LICENSE\.txt file in the project root for full license information\.',
r'.*' # the above should always be followed by at least one other line, so make sure that line is present
]

regexes = []
for line in copyright_lines:
pattern = '^.{1,5}%s$' % line
regexes.append(re.compile(pattern))

if len(sys.argv) < 2:
print("Requires passing a filename as an argument.")
exit(1)

file_name = sys.argv[1]
if not os.path.isfile(file_name):
print("File does not exist:", file_name, "(not necessarily an error)")
exit(0)

def report_incorrect(file_name, pairs):
# found a problem so report the problem to the caller and exit
print(file_name, "... does not contain a correct Microsoft copyright notice.\n")
# print the relevant lines to help the reader find the problem
for (_, line) in pairs:
print(" ", line, end="")
print()

linecount = 0
pairs = []
with open(file_name, 'r') as sourcefile:
pairs += zip(regexes, sourcefile)

for (regex, line) in pairs:
linecount += 1
line = line.rstrip()
matches = regex.match(line)
if not matches:
report_incorrect(file_name, pairs)
exit(1)

if linecount == 0:
# the file was empty (e.g. dummy.js) so no problem
exit(0)
elif linecount != len(regexes):
report_incorrect(file_name, pairs)
exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
PATH=/bin:/usr/bin:$PATH
fi

ERRFILE=jenkins.check_copyright.sh.err
ERRFILE=check_copyright.sh.err
ERRFILETEMP=$ERRFILE.0
rm -f $ERRFILE
rm -f $ERRFILETEMP
Expand All @@ -32,7 +32,7 @@ git diff --name-only `git merge-base origin/master HEAD` HEAD |
grep -v -E '\.def$' |
grep -v -E '\.inc$' |
grep -v -E 'test/benchmarks/.*\.js$' |
xargs -I % sh -c "echo 'Check Copyright > Checking %'; python jenkins.check_copyright.py % > $ERRFILETEMP; if [ \$? -ne 0 ]; then cat $ERRFILETEMP >> $ERRFILE; fi"
xargs -I % sh -c "echo 'Check Copyright > Checking %'; python jenkins/check_copyright.py % > $ERRFILETEMP || cat $ERRFILETEMP >> $ERRFILE"

if [ -e $ERRFILE ]; then # if error file exists then there were errors
>&2 echo "--------------" # leading >&2 means echo to stderr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if [ $? -ne 0 ]; then
PATH=/bin:/usr/bin:$PATH
fi

ERRFILE=jenkins.check_eol.sh.err
ERRFILE=check_eol.sh.err
rm -f $ERRFILE

git diff --name-only `git merge-base origin/master HEAD` HEAD | grep -v -E "(test/.*\\.js|\\.cmd|\\.baseline)" | xargs -I % ./jenkins.check_file_eol.sh %
git diff --name-only `git merge-base origin/master HEAD` HEAD | grep -v -E "(test/.*\\.js|\\.cmd|\\.baseline)" | xargs -I % ./jenkins/check_file_eol.sh %

if [ -e $ERRFILE ]; then # if error file exists then there were errors
>&2 echo "--------------" # leading >&2 means echo to stderr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# We will run dos2unix on the argument and make sure that it doesn't change.
# If it changes, that means someone introduced a CRLF by not setting core.autocrlf to true.

ERRFILE=jenkins.check_eol.sh.err
ERRFILE=check_eol.sh.err
ERRFILETEMP=$ERRFILE.0

# display a helpful message for someone reading the log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
setlocal

set JENKINS_BUILD=True
call test\jenkins.buildall.cmd
call %~dp0..\test\jenkins.testall.cmd %*

endlocal
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if "%2"=="" (
:main

set JENKINS_BUILD=True
call test\jenkins.testone.cmd %*
call %~dp0..\test\jenkins.testone.cmd %*

goto :end

Expand Down
8 changes: 7 additions & 1 deletion deps/chakrashim/core/lib/Backend/CodeGenWorkItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ void CodeGenWorkItem::RecordNativeCodeSize(Func *func, size_t bytes, ushort pdat
#else
bool canAllocInPreReservedHeapPageSegment = func->CanAllocInPreReservedHeapPageSegment();
#endif
EmitBufferAllocation *allocation = func->GetEmitBufferManager()->AllocateBuffer(bytes, &buffer, false, pdataCount, xdataSize, canAllocInPreReservedHeapPageSegment, true);
EmitBufferAllocation *allocation = func->GetEmitBufferManager()->AllocateBuffer(bytes, &buffer, pdataCount, xdataSize, canAllocInPreReservedHeapPageSegment, true);

#if DBG
MEMORY_BASIC_INFORMATION memBasicInfo;
size_t resultBytes = VirtualQuery(allocation->allocation->address, &memBasicInfo, sizeof(memBasicInfo));
Assert(resultBytes != 0 && memBasicInfo.Protect == PAGE_EXECUTE);
#endif

Assert(allocation != nullptr);
if (buffer == nullptr)
Expand Down
40 changes: 24 additions & 16 deletions deps/chakrashim/core/lib/Backend/EmitBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ bool EmitBufferManager<SyncObject>::FinalizeAllocation(EmitBufferAllocation *all
DWORD bytes = allocation->BytesFree();
if(bytes > 0)
{
BYTE* buffer;
this->GetBuffer(allocation, bytes, &buffer, false /*readWrite*/);
BYTE* buffer = nullptr;
this->GetBuffer(allocation, bytes, &buffer);
if (!this->CommitBuffer(allocation, buffer, 0, /*sourceBuffer=*/ nullptr, /*alignPad=*/ bytes))
{
return false;
Expand All @@ -262,11 +262,10 @@ bool EmitBufferManager<SyncObject>::FinalizeAllocation(EmitBufferAllocation *all
}

template <typename SyncObject>
EmitBufferAllocation* EmitBufferManager<SyncObject>::GetBuffer(EmitBufferAllocation *allocation, __in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, bool readWrite)
EmitBufferAllocation* EmitBufferManager<SyncObject>::GetBuffer(EmitBufferAllocation *allocation, __in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer)
{
Assert(this->criticalSection.IsLocked());

this->allocationHeap.EnsureAllocationProtection(allocation->allocation, readWrite);
Assert(allocation->BytesFree() >= bytes);

// In case of ThunkEmitter the script context would be null and we don't want to track that as code size.
Expand All @@ -288,7 +287,7 @@ EmitBufferAllocation* EmitBufferManager<SyncObject>::GetBuffer(EmitBufferAllocat
// to modify this buffer one page at a time.
//----------------------------------------------------------------------------
template <typename SyncObject>
EmitBufferAllocation* EmitBufferManager<SyncObject>::AllocateBuffer(__in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, bool readWrite /*= false*/, ushort pdataCount /*=0*/, ushort xdataSize /*=0*/, bool canAllocInPreReservedHeapPageSegment /*=false*/,
EmitBufferAllocation* EmitBufferManager<SyncObject>::AllocateBuffer(__in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, ushort pdataCount /*=0*/, ushort xdataSize /*=0*/, bool canAllocInPreReservedHeapPageSegment /*=false*/,
bool isAnyJittedCode /* = false*/)
{
AutoRealOrFakeCriticalSection<SyncObject> autoCs(&this->criticalSection);
Expand All @@ -297,7 +296,13 @@ EmitBufferAllocation* EmitBufferManager<SyncObject>::AllocateBuffer(__in size_t

EmitBufferAllocation * allocation = this->NewAllocation(bytes, pdataCount, xdataSize, canAllocInPreReservedHeapPageSegment, isAnyJittedCode);

GetBuffer(allocation, bytes, ppBuffer, readWrite);
GetBuffer(allocation, bytes, ppBuffer);

#if DBG
MEMORY_BASIC_INFORMATION memBasicInfo;
size_t resultBytes = VirtualQuery(allocation->allocation->address, &memBasicInfo, sizeof(memBasicInfo));
Assert(resultBytes != 0 && memBasicInfo.Protect == PAGE_EXECUTE);
#endif

return allocation;
}
Expand Down Expand Up @@ -327,6 +332,14 @@ bool EmitBufferManager<SyncObject>::CheckCommitFaultInjection()

#endif

template <typename SyncObject>
bool EmitBufferManager<SyncObject>::ProtectBufferWithExecuteReadWriteForInterpreter(EmitBufferAllocation* allocation)
{
Assert(this->criticalSection.IsLocked());
Assert(allocation != nullptr);
return (this->allocationHeap.ProtectAllocationWithExecuteReadWrite(allocation->allocation) == TRUE);
}

// Returns true if we successfully commit the buffer
// Returns false if we OOM
template <typename SyncObject>
Expand All @@ -340,8 +353,6 @@ bool EmitBufferManager<SyncObject>::CommitReadWriteBufferForInterpreter(EmitBuff
this->totalBytesCode += bufferSize;
#endif

DWORD oldProtect;

VerboseHeapTrace(L"Setting execute permissions on 0x%p, allocation: 0x%p\n", pBuffer, allocation->allocation->address);

#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
Expand All @@ -351,14 +362,13 @@ bool EmitBufferManager<SyncObject>::CommitReadWriteBufferForInterpreter(EmitBuff
}
#endif

if (!this->allocationHeap.ProtectAllocation(allocation->allocation, PAGE_EXECUTE, &oldProtect, PAGE_READWRITE))
if (!this->allocationHeap.ProtectAllocationWithExecuteReadOnly(allocation->allocation))
{
return false;
}

FlushInstructionCache(AutoSystemInfo::Data.GetProcessHandle(), pBuffer, bufferSize);

Assert(oldProtect == PAGE_READWRITE);
return true;
}

Expand All @@ -378,8 +388,6 @@ EmitBufferManager<SyncObject>::CommitBuffer(EmitBufferAllocation* allocation, __
Assert(destBuffer != nullptr);
Assert(allocation != nullptr);

DWORD oldProtect;

BYTE *currentDestBuffer = allocation->GetUnused();
BYTE *bufferToFlush = currentDestBuffer;
Assert(allocation->BytesFree() >= bytes + alignPad);
Expand All @@ -404,11 +412,11 @@ EmitBufferManager<SyncObject>::CommitBuffer(EmitBufferAllocation* allocation, __
return false;
}
#endif
if (!this->allocationHeap.ProtectAllocationPage(allocation->allocation, (char*)readWriteBuffer, PAGE_EXECUTE_READWRITE, &oldProtect, PAGE_EXECUTE))

if (!this->allocationHeap.ProtectAllocationWithExecuteReadWrite(allocation->allocation, (char*)readWriteBuffer))
{
return false;
}
Assert(oldProtect == PAGE_EXECUTE);

if (alignPad != 0)
{
Expand Down Expand Up @@ -440,11 +448,11 @@ EmitBufferManager<SyncObject>::CommitBuffer(EmitBufferAllocation* allocation, __
}

Assert(readWriteBuffer + readWriteBytes == currentDestBuffer);
if (!this->allocationHeap.ProtectAllocationPage(allocation->allocation, (char*)readWriteBuffer, PAGE_EXECUTE, &oldProtect, PAGE_EXECUTE_READWRITE))

if (!this->allocationHeap.ProtectAllocationWithExecuteReadOnly(allocation->allocation, (char*)readWriteBuffer))
{
return false;
}
Assert(oldProtect == PAGE_EXECUTE_READWRITE);
}

FlushInstructionCache(AutoSystemInfo::Data.GetProcessHandle(), bufferToFlush, sizeToFlush);
Expand Down
5 changes: 3 additions & 2 deletions deps/chakrashim/core/lib/Backend/EmitBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class EmitBufferManager
void Decommit();
void Clear();

EmitBufferAllocation* AllocateBuffer(__in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, bool readWrite = false, ushort pdataCount = 0, ushort xdataSize = 0, bool canAllocInPreReservedHeapPageSegment = false, bool isAnyJittedCode = false);
EmitBufferAllocation* AllocateBuffer(__in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, ushort pdataCount = 0, ushort xdataSize = 0, bool canAllocInPreReservedHeapPageSegment = false, bool isAnyJittedCode = false);
bool CommitBuffer(EmitBufferAllocation* allocation, __out_bcount(bytes) BYTE* destBuffer, __in size_t bytes, __in_bcount(bytes) const BYTE* sourceBuffer, __in DWORD alignPad = 0);
bool ProtectBufferWithExecuteReadWriteForInterpreter(EmitBufferAllocation* allocation);
bool CommitReadWriteBufferForInterpreter(EmitBufferAllocation* allocation, _In_reads_bytes_(bufferSize) BYTE* pBuffer, _In_ size_t bufferSize);
void CompletePreviousAllocation(EmitBufferAllocation* allocation);
bool FreeAllocation(void* address);
Expand Down Expand Up @@ -119,7 +120,7 @@ class EmitBufferManager
Js::ScriptContext * scriptContext;

EmitBufferAllocation * NewAllocation(size_t bytes, ushort pdataCount, ushort xdataSize, bool canAllocInPreReservedHeapPageSegment, bool isAnyJittedCode);
EmitBufferAllocation* GetBuffer(EmitBufferAllocation *allocation, __in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer, bool readWrite);
EmitBufferAllocation* GetBuffer(EmitBufferAllocation *allocation, __in size_t bytes, __deref_bcount(bytes) BYTE** ppBuffer);

bool FinalizeAllocation(EmitBufferAllocation *allocation);
CustomHeap::Heap allocationHeap;
Expand Down
7 changes: 6 additions & 1 deletion deps/chakrashim/core/lib/Backend/InterpreterThunkEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ void InterpreterThunkEmitter::NewThunkBlock()
DWORD bufferSize = BlockSize;
DWORD thunkCount = 0;

allocation = emitBufferManager.AllocateBuffer(bufferSize, &buffer, /*readWrite*/ true);
allocation = emitBufferManager.AllocateBuffer(bufferSize, &buffer);
if (!emitBufferManager.ProtectBufferWithExecuteReadWriteForInterpreter(allocation))
{
Js::Throw::OutOfMemory();
}

currentBuffer = buffer;

#ifdef _M_X64
Expand Down
Loading

0 comments on commit d9469f1

Please sign in to comment.