Skip to content

Commit

Permalink
1.0.8.0
Browse files Browse the repository at this point in the history
VoidPointer.fromAddress*
null VoidPointer equals null
exceptionInfos for runtime error
  • Loading branch information
karikera committed Jun 8, 2021
1 parent 265df71 commit c44e2b7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bdsx/bdsx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<TargetName>Chakra</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseTest|x64'">
<LibraryPath>$(SolutionDir)node-chakracore\$(ConfigDir)\lib;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)node-chakracore\$(ConfigDir)\lib;$(SolutionDir)node-chakracore\$(ConfigDir);$(LibraryPath)</LibraryPath>
<TargetName>Chakra</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -197,7 +197,7 @@ echo #define BUILD_TIME "%25date%-%time2:.=%"&gt;"gen/buildtime.h"</Command>
<CustomBuild Include="version.bat">
<FileType>Document</FileType>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">gen\version.h;$(SolutionDir)..\bdsx\bdsx\version-bdsx.json</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='ReleaseTest|x64'">gen\version.h;$(SolutionDir)..\bdsx\bdsx\version.json</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='ReleaseTest|x64'">gen\version.h;$(SolutionDir)..\bdsx\bdsx\version-bdsx.json</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">gen\version.h;$(SolutionDir)..\bdsx\bdsx\version-bdsx.json</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">@call "%(Identity)"

Expand Down
2 changes: 2 additions & 0 deletions bdsx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace
}
catch (ThrowAbort&)
{
_catch(param, "kr::ThrowAbort");
}
catch (std::exception& e)
{
Expand Down Expand Up @@ -396,6 +397,7 @@ void nodegate::initNativeModule(void* exports_raw) noexcept
}
s_globalScope.create();
}

void nodegate::clearNativeModule() noexcept
{
s_globalScope.remove();
Expand Down
17 changes: 13 additions & 4 deletions bdsx/sehandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "sehandler.h"
#include "voidpointer.h"
#include "nativepointer.h"
#include "nodegate.h"
#include "jsctx.h"
#include "unwind.h"
Expand Down Expand Up @@ -28,6 +29,7 @@ namespace
JsPersistent handler;
JsPropertyId nativeStack = JsPropertyId(u"nativeStack");
DWORD threadId;
ULONG_PTR exceptionInfos[EXCEPTION_MAXIMUM_PARAMETERS];

DeferField() noexcept
{
Expand Down Expand Up @@ -75,11 +77,11 @@ namespace
}
return u"[Unknown]";
}
bool addFunctionTable(VoidPointer* baseptr, int unwindcount, int fncount) throws(JsException)
bool addFunctionTable(VoidPointer* runtimeFunctionTable, int fncount, VoidPointer* baseptr) throws(JsException)
{
if (baseptr == nullptr) throw JsException(u"Invalid arguments");
DWORD64 base = (DWORD64)baseptr->getAddressRawSafe();
return RtlAddFunctionTable((RUNTIME_FUNCTION*)(base + unwindcount * sizeof(UNWIND_INFO)), fncount, base);
RUNTIME_FUNCTION* functionTable = (RUNTIME_FUNCTION*)runtimeFunctionTable->getAddressRawSafe();
return RtlAddFunctionTable(functionTable, fncount, base);
}
}

Expand Down Expand Up @@ -165,12 +167,12 @@ ATTR_NORETURN void runtimeError::raise(EXCEPTION_POINTERS* exptr) noexcept

AText16 stack = getStack(exptr);
if (stack.endsWith('\n')) stack.pop();

CsLock lock = s_stackLock;
if (s_nativeErrorCode != 0) break;
s_nativeErrorCode = code;
s_threadId = threadId;
s_nativeExceptionStack << move(stack);
memcpy(s_field->exceptionInfos, exptr->ExceptionRecord->ExceptionInformation, sizeof(s_field->exceptionInfos));
}
catch (...)
{
Expand Down Expand Up @@ -231,6 +233,13 @@ kr::JsValue runtimeError::getError() noexcept
message << u']';
err.set(u"stack", (Text16)message);
}
JsValue exceptionInfos = JsNewArray(EXCEPTION_MAXIMUM_PARAMETERS);
err.set(u"exceptionInfos", exceptionInfos);
for (size_t i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) {
JsValue addr = NativePointer::newInstanceRaw({});
addr.getNativeObject<VoidPointer>()->setAddressRaw((void*)s_field->exceptionInfos[i]);
exceptionInfos.set((int)i, addr );
}
return err;
}
kr::JsValue runtimeError::getRuntimeErrorClass() noexcept
Expand Down
2 changes: 1 addition & 1 deletion bdsx/version.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

set BDSX_CORE_VERSION=1.0.7.0
set BDSX_CORE_VERSION=1.0.8.0
49 changes: 46 additions & 3 deletions bdsx/voidpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void* VoidPointer::getAddressRaw() noexcept
}
void* VoidPointer::getAddressRawSafe() noexcept
{
if (this == nullptr) return nullptr;
if (this == nullptr) {
return nullptr;
}
return m_address;
}
int32_t VoidPointer::getAddressLow() noexcept
Expand Down Expand Up @@ -54,7 +56,7 @@ kr::JsValue VoidPointer::addressOfThis() noexcept

bool VoidPointer::equals(VoidPointer* other) noexcept
{
if (other == nullptr) return false;
if (other == nullptr) return m_address == nullptr;
return m_address == other->m_address;
}
NativePointer* VoidPointer::pointer() noexcept
Expand Down Expand Up @@ -171,7 +173,6 @@ void VoidPointer::initMethods(JsClassT<VoidPointer>* cls) noexcept
cls->setMethod(u"addBin", &VoidPointer::addBin);
cls->setMethod(u"subBin", &VoidPointer::subBin);
cls->setMethod(u"subptr", &VoidPointer::subptr);
cls->setMethod(u"clone", &VoidPointer::pointer);

cls->setMethod(u"as", &VoidPointer::as);
cls->setMethod(u"addAs", &VoidPointer::addAs);
Expand All @@ -182,6 +183,48 @@ void VoidPointer::initMethods(JsClassT<VoidPointer>* cls) noexcept
cls->setMethod(u"isNull", &VoidPointer::isNull);
cls->setMethod(u"isNotNull", &VoidPointer::isNotNull);
cls->setMethod(u"toString", &VoidPointer::toString);

cls->setStaticMethodRaw(u"fromAddress", [](const JsArguments& args) {
JsValue instance = JsClass(args.getThis()).newInstanceRaw({});
VoidPointer* ptr = instance.getNativeObject<VoidPointer>();
if (ptr == nullptr) throw JsException(TSZ16() << instance.get(u"name").cast<Text16>() << u" is not *Pointer");

uint32_t low = args.at<int>(0);
uint32_t high = args.at<int>(1);
ptr->setAddressRaw((void*)(((uint64_t)high << 32) | low));
return instance;
});
cls->setStaticMethodRaw(u"fromAddressBin", [](const JsArguments& args) {
JsValue instance = JsClass(args.getThis()).newInstanceRaw({});
VoidPointer* ptr = instance.getNativeObject<VoidPointer>();
if (ptr == nullptr) throw JsException(TSZ16() << instance.get(u"name").cast<Text16>() << u" is not *Pointer");
ptr->setAddressRaw((void*)::getBin64(args.at<Text16>(0)));
return instance;
});
cls->setStaticMethodRaw(u"fromAddressBuffer", [](const JsArguments& args) {
JsValue instance = JsClass(args.getThis()).newInstanceRaw({});
VoidPointer* ptr = instance.getNativeObject<VoidPointer>();
if (ptr == nullptr) throw JsException(TSZ16() << instance.get(u"name").cast<Text16>() << u" is not *Pointer");
if (args.size() == 0) return instance;
Buffer buf = args[0].getBuffer();
if (buf == nullptr) return instance;
ptr->setAddressRaw(buf.data());
return instance;
});
cls->setStaticMethodRaw(u"fromAddressString", [](const JsArguments& args) {
JsValue instance = JsClass(args.getThis()).newInstanceRaw({});
VoidPointer* ptr = instance.getNativeObject<VoidPointer>();
if (ptr == nullptr) throw JsException(TSZ16() << instance.get(u"name").cast<Text16>() << u" is not *Pointer");
ptr->setAddressRaw(args.at<Text16>(0).data());
return instance;
});
cls->setStaticMethodRaw(u"fromAddressFloat", [](const JsArguments& args) {
JsValue instance = JsClass(args.getThis()).newInstanceRaw({});
VoidPointer* ptr = instance.getNativeObject<VoidPointer>();
if (ptr == nullptr) throw JsException(TSZ16() << instance.get(u"name").cast<Text16>() << u" is not *Pointer");
ptr->setAddressRaw((void*)(int64_t)args.at<double>(0));
return instance;
});
}

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
<Link>
<AdditionalDependencies Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'arm'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\arm\Debug\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'arm'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\arm\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'ReleaseTest' And '$(Platform)' == 'arm'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\arm\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'x64'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Debug\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'ReleaseTest' And '$(Platform)' == 'x64'">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Debug' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Debug\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Release' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'ReleaseTest' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Release\ChakraCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand All @@ -28,15 +25,15 @@
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Debug\ChakraCore.dll" />
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Debug\ChakraCore.pdb" />
</ItemGroup>
<ItemGroup Condition="('$(Configuration)' == 'Release' or '$(Configuration)' == 'ReleaseTest') And '$(Platform)' == 'x64'">
<ItemGroup Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'">
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Release\ChakraCore.dll" />
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x64\Release\ChakraCore.pdb" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Debug\ChakraCore.dll" />
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Debug\ChakraCore.pdb" />
</ItemGroup>
<ItemGroup Condition="('$(Configuration)' == 'Release' or '$(Configuration)' == 'ReleaseTest') And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">
<ItemGroup Condition="'$(Configuration)' == 'Release' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Release\ChakraCore.dll" />
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\lib\native\v140\x86\Release\ChakraCore.pdb" />
</ItemGroup>
Expand Down

0 comments on commit c44e2b7

Please sign in to comment.