mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-10 16:16:16 +00:00
Add nodejs support
This commit is contained in:
@@ -6,6 +6,7 @@ option(MOMO_ENABLE_AVX2 "Enable AVX2 support" ON)
|
||||
option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF)
|
||||
option(MOMO_ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF)
|
||||
option(MOMO_ENABLE_RUST_CODE "Enable code parts written in rust" ON)
|
||||
option(MOMO_EMSCRIPTEN_SUPPORT_NODEJS "Enable Node.js filesystem for emscripten compilation" OFF)
|
||||
option(MOMO_BUILD_AS_LIBRARY "Configure and Build the emulator as a shared library (without the samples and tests)" OFF)
|
||||
|
||||
set(MOMO_REFLECTION_LEVEL "0" CACHE STRING "Reflection level for the build")
|
||||
|
||||
@@ -89,8 +89,9 @@ endif()
|
||||
##########################################
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
|
||||
add_compile_options(
|
||||
momo_add_c_and_cxx_compile_options(
|
||||
-fexceptions
|
||||
-ftrivial-auto-var-init=zero
|
||||
)
|
||||
|
||||
add_link_options(
|
||||
@@ -98,13 +99,24 @@ if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
|
||||
-sALLOW_MEMORY_GROWTH=1
|
||||
-sASSERTIONS
|
||||
-sWASM_BIGINT
|
||||
-sENVIRONMENT=web
|
||||
-sUSE_OFFSET_CONVERTER
|
||||
#-sEXCEPTION_CATCHING_ALLOWED=[..]
|
||||
-sEXIT_RUNTIME
|
||||
#-lnodefs.js -sNODERAWFS=1
|
||||
#-sASYNCIFY
|
||||
)
|
||||
)
|
||||
|
||||
if(MOMO_EMSCRIPTEN_SUPPORT_NODEJS)
|
||||
add_link_options(
|
||||
-lnodefs.js -sNODERAWFS=1
|
||||
-sENVIRONMENT=node
|
||||
-sMAXIMUM_MEMORY=4gb
|
||||
--pre-js ${CMAKE_CURRENT_LIST_DIR}/misc/node-pre-script.js
|
||||
)
|
||||
else()
|
||||
add_link_options(
|
||||
-sENVIRONMENT=worker
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
3
cmake/misc/node-pre-script.js
Normal file
3
cmake/misc/node-pre-script.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Module['preRun'] = () => {
|
||||
ENV = process.env;
|
||||
};
|
||||
2
deps/unicorn
vendored
2
deps/unicorn
vendored
Submodule deps/unicorn updated: 6b32965144...843eb15bcd
@@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include <utils/object.hpp>
|
||||
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument_internal(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
const auto a1 = args[index++];
|
||||
|
||||
if constexpr (sizeof(T) <= sizeof(a1) || sizeof(size_t) > 4)
|
||||
{
|
||||
return T(a1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto a2 = args[index++];
|
||||
|
||||
const auto arg = (a1 | (static_cast<uint64_t>(a2) << 32));
|
||||
return T(arg);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
auto arg = resolve_indexed_argument_internal<T, N>(args, index);
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename ReturnType, typename... Args>
|
||||
class function_wrapper_tcg : public utils::object
|
||||
{
|
||||
public:
|
||||
using user_data_pointer = void*;
|
||||
using c_function_type = ReturnType(Args..., user_data_pointer);
|
||||
using functor_type = std::function<ReturnType(Args...)>;
|
||||
|
||||
function_wrapper_tcg() = default;
|
||||
|
||||
function_wrapper_tcg(functor_type functor)
|
||||
: functor_(std::make_unique<functor_type>(std::move(functor)))
|
||||
{
|
||||
}
|
||||
|
||||
c_function_type* get_c_function() const
|
||||
{
|
||||
auto* func = +[](const size_t a1, const size_t a2, const size_t a3, const size_t a4, const size_t a5,
|
||||
const size_t a6, const size_t a7, const size_t a8, const size_t a9, const size_t a10,
|
||||
const size_t a11, const size_t a12) -> uint64_t {
|
||||
const std::array arguments = {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12};
|
||||
|
||||
const auto lambda = +[](Args... args, user_data_pointer user_data) -> ReturnType {
|
||||
return (*static_cast<functor_type*>(user_data))(std::forward<Args>(args)...);
|
||||
};
|
||||
|
||||
size_t index = 0;
|
||||
std::tuple<Args..., user_data_pointer> func_args{
|
||||
resolve_indexed_argument<std::remove_cv_t<std::remove_reference_t<Args>>>(arguments, index)...,
|
||||
resolve_indexed_argument<user_data_pointer>(arguments, index)};
|
||||
|
||||
(void)index;
|
||||
|
||||
if constexpr (!std::is_void_v<ReturnType>)
|
||||
{
|
||||
return uint64_t(std::apply(lambda, std::move(func_args)));
|
||||
}
|
||||
|
||||
std::apply(lambda, std::move(func_args));
|
||||
return 0;
|
||||
};
|
||||
|
||||
return reinterpret_cast<c_function_type*>(reinterpret_cast<void*>(func));
|
||||
}
|
||||
|
||||
void* get_function() const
|
||||
{
|
||||
return reinterpret_cast<void*>(this->get_c_function());
|
||||
}
|
||||
|
||||
user_data_pointer get_user_data() const
|
||||
{
|
||||
return this->functor_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<functor_type> functor_{};
|
||||
};
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "unicorn_hook.hpp"
|
||||
|
||||
#include "function_wrapper.hpp"
|
||||
#include "function_wrapper_tcg.hpp"
|
||||
#include <ranges>
|
||||
|
||||
namespace unicorn
|
||||
@@ -550,7 +549,7 @@ namespace unicorn
|
||||
c(address); //
|
||||
};
|
||||
|
||||
function_wrapper_tcg<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
function_wrapper<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
|
||||
unicorn_hook hook{*this};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user