From e7273ab40042a219c15d91260409bc52dbafb9df Mon Sep 17 00:00:00 2001 From: hydai Date: Wed, 28 Apr 2021 09:54:16 +0000 Subject: [PATCH] [SSVM] Upgrade to 0.7.3 --- .github/workflows/external-test.yml | 3 +++ .github/workflows/main.yml | 3 +++ .gitmodules | 3 +++ README.md | 19 +++++++++++-------- binding.gyp | 17 +++++++++++------ index.js | 2 +- package.json | 8 ++++---- ssvm-image | 1 + ssvm-napi | 2 +- ssvm-storage | 2 +- ssvm-tensorflow | 2 +- ssvmaddon.cc | 23 +++++++++++++++++------ utils/docker/Dockerfile | 5 ++++- 13 files changed, 61 insertions(+), 29 deletions(-) create mode 160000 ssvm-image diff --git a/.github/workflows/external-test.yml b/.github/workflows/external-test.yml index 9987ef9..e2a19a2 100644 --- a/.github/workflows/external-test.yml +++ b/.github/workflows/external-test.yml @@ -26,6 +26,9 @@ jobs: with: submodules: recursive + - name: Set Rust to required version + run: rustup override set 1.50.0 + - name: Build and install SSVM-napi uses: './ssvm-napi/.github/actions/build-from-source' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ce74ab..edd3766 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,9 @@ jobs: with: submodules: recursive + - name: Set Rust to required version + run: rustup override set 1.50.0 + - name: Build SSVM-napi with ${{ matrix.cc }} uses: './ssvm-napi/.github/actions/build-from-source' with: diff --git a/.gitmodules b/.gitmodules index 5791540..946411a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "ssvm-tensorflow"] path = ssvm-tensorflow url = https://github.com/second-state/ssvm-tensorflow.git +[submodule "ssvm-image"] + path = ssvm-image + url = git@github.com:second-state/ssvm-image.git diff --git a/README.md b/README.md index 66ddc7b..85bafbf 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ For the tensorflow extensions: * libtensorflow.so * Please refer to the TensorFlow website for more details ```base - RUN wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \ + wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \ && tar -C /usr/local -xzf libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \ && ldconfig ``` @@ -92,17 +92,19 @@ Please refer to [Tutorial: A standalone wasm32-wasi application](./Tutorial_Wasm ### Constructor: `ssvm.VM(wasm, ssvm_options) -> vm_instance` * Create a ssvm instance by given wasm file and options. * Arguments: - * `wasm`: Input wasm file, can be the following three formats: + * `wasm`: Input wasm file, can be the following two formats: 1. Wasm file path (String, e.g. `/tmp/hello.wasm`) 2. Wasm bytecode format which is the content of a wasm binary file (Uint8Array) * `options`: An options object for setup the SSVM execution environment. * `options` - * `args` : An array of strings that Wasm application will get as function arguments. Default: `[]` - * `env` : An object like `process.env` that Wasm application will get as its environment variables. Default: `{}` - * `preopens` : An object which maps ':'. E.g. `{'/sandbox': '/some/real/path/that/wasm/can/access'}` Default: `{}` - * `EnableWasiStartFunction`: This option will disable wasm-bindgen mode and prepare the working environment for standalone wasm program. If you want to run an appliation with `main()`, you should set this to `true`. Default: `false`. - * `EnableAOT`: This option will enable ssvm aot mode. Default: `false`. - * `EnableMeasurement`: This option will enable measurement but decrease its performance. Default: `false`. + * `args` : An array of strings that Wasm application will get as function arguments. Default: `[]`. + * `env` : An object like `process.env` that Wasm application will get as its environment variables. Default: `{}`. + * `preopens` : An object which maps ':'. E.g. `{'/sandbox': '/some/real/path/that/wasm/can/access'}` Default: `{}`. + * `EnableWasiStartFunction` : This option will disable wasm-bindgen mode and prepare the working environment for standalone wasm program. If you want to run an appliation with `main()`, you should set this to `true`. Default: `false`. + * `EnableAOT` : This option will enable ssvm aot mode. Default: `false`. + * `EnableMeasurement` : This option will enable measurement but decrease its performance. Default: `false`. + * `AllowCommands` : An array of strings that indicate what commands are allowed to execute in the SSVM Process Module. Default `[]`. + * `AllowAllCommands` : Allow users to call any command in the SSVM Process Module. This option will overwrite the `AllowCommands`. Default: `false`. * Return value: * `vm_instance`: A ssvm instance. @@ -218,6 +220,7 @@ vm.RunXXX("Func", args); * `InstructionCount` -> : The number of executed instructions in this execution. * `TotalGasCost` -> : The cost of this execution. * `InstructionPerSecond` -> : The instructions per second of this execution. + ```javascript let result = RunInt("Add", 1, 2); // result should be 3 diff --git a/binding.gyp b/binding.gyp index 887f510..c7765da 100644 --- a/binding.gyp +++ b/binding.gyp @@ -38,10 +38,10 @@ }, "sources": [ "ssvmaddon.cc", - "ssvm-napi/addon.cc", - "ssvm-napi/bytecode.cc", - "ssvm-napi/options.cc", - "ssvm-napi/utils.cc", + "ssvm-napi/src/addon.cc", + "ssvm-napi/src/bytecode.cc", + "ssvm-napi/src/options.cc", + "ssvm-napi/src/utils.cc", "ssvm-napi/ssvm-core/lib/aot/compiler.cpp", "ssvm-napi/ssvm-core/lib/ast/description.cpp", "ssvm-napi/ssvm-core/lib/ast/expression.cpp", @@ -61,6 +61,7 @@ "ssvm-napi/ssvm-core/lib/interpreter/engine/control.cpp", "ssvm-napi/ssvm-core/lib/interpreter/engine/engine.cpp", "ssvm-napi/ssvm-core/lib/interpreter/engine/memory.cpp", + "ssvm-napi/ssvm-core/lib/interpreter/engine/proxy.cpp", "ssvm-napi/ssvm-core/lib/interpreter/engine/table.cpp", "ssvm-napi/ssvm-core/lib/interpreter/engine/variable.cpp", "ssvm-napi/ssvm-core/lib/interpreter/instantiate/data.cpp", @@ -72,18 +73,20 @@ "ssvm-napi/ssvm-core/lib/interpreter/instantiate/memory.cpp", "ssvm-napi/ssvm-core/lib/interpreter/instantiate/module.cpp", "ssvm-napi/ssvm-core/lib/interpreter/instantiate/table.cpp", + "ssvm-napi/ssvm-core/lib/interpreter/helper.cpp", "ssvm-napi/ssvm-core/lib/interpreter/interpreter.cpp", "ssvm-napi/ssvm-core/lib/loader/filemgr.cpp", "ssvm-napi/ssvm-core/lib/loader/ldmgr.cpp", "ssvm-napi/ssvm-core/lib/loader/loader.cpp", + "ssvm-napi/ssvm-core/lib/loader/shared_library.cpp", "ssvm-napi/ssvm-core/lib/validator/formchecker.cpp", "ssvm-napi/ssvm-core/lib/validator/validator.cpp", "ssvm-napi/ssvm-core/lib/vm/vm.cpp", "ssvm-napi/ssvm-core/thirdparty/easyloggingpp/easylogging++.cc", + "ssvm-image/lib/image_func.cpp", + "ssvm-image/lib/image_module.cpp", "ssvm-storage/lib/storage_func.cpp", "ssvm-storage/lib/storage_module.cpp", - "ssvm-tensorflow/lib/image_func.cpp", - "ssvm-tensorflow/lib/image_module.cpp", "ssvm-tensorflow/lib/tensorflow_func.cpp", "ssvm-tensorflow/lib/tensorflow_module.cpp", "ssvm-tensorflow/lib/tensorflowlite_func.cpp", @@ -92,9 +95,11 @@ "include_dirs": [ " @@ -64,8 +66,8 @@ inline uint64_t castFromU32ToU64(uint32_t L, uint32_t H) { inline bool endsWith(const std::string &S, const std::string &Suffix) { return S.length() >= Suffix.length() && - S.compare(S.length() - Suffix.length(), std::string::npos, - Suffix) == 0; + S.compare(S.length() - Suffix.length(), std::string::npos, Suffix) == + 0; } } // namespace @@ -146,6 +148,17 @@ void SSVMAddon::InitVM(const Napi::CallbackInfo &Info) { SSVM::Log::setErrorLoggingLevel(); + SSVM::Host::SSVMProcessModule *ProcMod = + dynamic_cast( + VM->getImportModule(SSVM::VM::Configure::VMType::SSVM_Process)); + + if (Options.isAllowedCmdsAll()) { + ProcMod->getEnv().AllowedAll = true; + } + for (auto &Cmd : Options.getAllowedCmds()) { + ProcMod->getEnv().AllowedCmd.insert(Cmd); + } + Inited = true; } @@ -173,8 +186,7 @@ void SSVMAddon::InitWasi(const Napi::CallbackInfo &Info, if (Options.isAOTMode()) { if (BC.isFile() && endsWith(BC.getPath(), ".so")) { // BC is already the compiled filename, do nothing - } - else if (!BC.isCompiled()) { + } else if (!BC.isCompiled()) { Compile(); } /// After Compile(), {Bytecode, FilePath} -> {FilePath} @@ -432,8 +444,7 @@ void SSVMAddon::Run(const Napi::CallbackInfo &Info) { FiniVM(); } -Napi::Value SSVMAddon::RunCompile(const Napi::CallbackInfo &Info) -{ +Napi::Value SSVMAddon::RunCompile(const Napi::CallbackInfo &Info) { std::string FileName; if (Info.Length() > 0) { FileName = Info[0].As().Utf8Value(); diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile index 4592260..558a04c 100644 --- a/utils/docker/Dockerfile +++ b/utils/docker/Dockerfile @@ -30,7 +30,7 @@ RUN wget https://github.com/second-state/ssvm-tensorflow-deps/releases/download/ && ldconfig RUN npm install -y -g --unsafe-perm \ - node-pre-gyp \ + @mapbox/node-pre-gyp \ ssvmup \ wabt @@ -40,5 +40,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ mtcnn \ mobilenet_v2 +RUN rustup override set 1.50.0 + + RUN rm -rf /var/lib/apt/lists/* ${TENSORFLOW_TARBALL} WORKDIR /root