wasmvm / wasmvm Goto Github PK
View Code? Open in Web Editor NEWA standalone WebAssembly process virtual machine
Home Page: https://wasmvm.github.io/WasmVM/
License: BSD 3-Clause "New" or "Revised" License
A standalone WebAssembly process virtual machine
Home Page: https://wasmvm.github.io/WasmVM/
License: BSD 3-Clause "New" or "Revised" License
在 decoder 之外直接操作 bytecode 或 Runtime Instance
語意上和擴充彈性都很糟
因此我們需要先定義出 Wasm 規格內的資料結構,透過這些資料結構來操作
可以參考 doc/images/WasmStructure.svg 把 WasmStructure 都定義在 src/include/structures
目前只有完成整個系統的架構,並讓他可以進行基本的運作
還沒有對系統進行優化
優化的重點:
預防 Or 解決潛在的危險
增進執行效率
減少使用的資源
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 CallC0.h 和 CallC0.cpp
Executor 是執行程式的元件,包含 SysCall, Core 和 Store
目前正開放討論實作方法!
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call160.h 和 Call160.cpp
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel,
利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h
裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp
裡, 加上對應的case 判斷
請將 編號 0x00-0x20 的實作寫在 Call20.h 和 Call20.cpp, 編號 0x21-0x40 的實作寫在 Call40.h 和 Call40.cpp
fn
is the function index of the module in WebAssembly mannerchild_stack
is the direct memory address got by mmap
f32.load
f32.store
f64.load
f64.store
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call60.h 和 Call60.cpp
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call80.h 和 Call80.cpp
現在已經有 CTest 的測試設定,但是只有 unreachable 和 nop 的測試資料。
需要擴充其他指令和 Syscall 測試資料
請參照 tests 裡 unreachable 和 nop 的格式實作
Control Instructions
Memory Instructions
Variable Instructions
Parameter Instructions
Numeric Instructions
Since WasmVM
is under development, it is vital for users to distinguish from the internal problems and wasm files generated by external tools. We can implement make check
to perform the validation of given wasm files which were checked in advanced.
Runtime function 是每個指令真正運行的函式,目前先實作算數指令,從 Stack 取出數值,運算之後再把結果填回去
已指定的清單:
i32.load
i32.load8_s
i32.load8_u
i32.load16_s
i32.load16_u
i32.store
i32.store8
i32.store16
i64.load
i64.load8_s
i64.load8_u
i64.load16_s
i64.load16_u
i64.load32_s
i64.load32_u
i64.store8
i64.store16
i64.store32
i64.store
current_memory
grow_memory
Core 是執行程式的部件,會逐步從函式中取出指令,根據 opcode 執行對應的 runtime function
有點像是 CPU 裡“核心”的概念,用不同的 Thread 去模擬不同核心數
目前正開放討論實作方法!
在 WasmModule 讀取 & 驗證之後,需要透過 Instantiator 把模組轉換成執行時的格式 (Instance),並載入 Executor
現在能產生 Wasm binary code 的方式目前還是官方的 wabt 工具
(emscripten 會加入一些他自己的 JavaScript binding,沒法用在 WasmVM)
希望能加入一些工具支援支援現有的編譯器, 或是打造專屬的編譯器,
在不需要 JavaScript binding的情況下產生 WasmVM 能執行的 binary
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 CallA0.h 和 CallA0.cpp
WebAssembly 官網上寫著
In the MVP, WebAssembly does not yet have a stable ABI for libraries. Developers will need to ensure that all code linked into an application are compiled with the same compiler and options.
既然沒有 libc ABI,那我們就用 Syscall 來幫忙完成吧!
With Syscall, maybe libc ABI can be implemented by pure Wasm in WasmVM
雖然已經實作 function 功能,但是沒有支援 Native function
目前我也還沒想到要如何實作...
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call140.h 和 Call140.cpp
Reported by gcc-7.2
:
WasmVM/src/Component/Decoder.cpp: In static member function ‘static void Decoder::decode(Store&, Stack&)’:
WasmVM/src/Component/Decoder.cpp:22:6: warning: ‘sprintf’ writing a terminating nul past the end of the destination [-Wformat-overflow=]
void Decoder::decode(Store& store, Stack& coreStack) {
^~~~~~~
WasmVM/src/Component/Decoder.cpp:829:14: note: ‘sprintf’ output 3 bytes into a destination of size 2
sprintf(codeChr, "%02x", ((std::uint32_t)bincode) & 0xff);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The casting from unsigned 32-bit integer is not exactly what sprintf
expects.
目前已完成一些 System call ,可以開始加上測試資料
請參照 tests 裡 unreachable 和 nop 的格式實作
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call100.h 和 Call100.cpp
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 CallE0.h 和 CallE0.cpp
While building on Aarch64/Linux, cmake complained as following:
[ 13%] Building CXX object src/Syscall/CMakeFiles/WasmVM_Syscall.dir/Call20.cpp.o
/tmp/WasmVM/src/Syscall/Call20.cpp: In function ‘void Call::sysFstat(Store&, Stack&)’:
/tmp/WasmVM/src/Syscall/Call20.cpp:226:33: error: no match for call to ‘(Stack) ()’
Value* fd = (Value*)coreStack().data;
^
/tmp/WasmVM/src/Syscall/Call20.cpp:243:32: error: ‘pathnameAddr’ was not declared in this scope
char* bufPtr = memoryData += pathnameAddr->data.i32;
^~~~~~~~~~~~
/tmp/WasmVM/src/Syscall/Call20.cpp: In function ‘void Call::sysSelect(Store&, Stack&)’:
/tmp/WasmVM/src/Syscall/Call20.cpp:550:50: error: ‘data’ was not declared in this scope
char* readfdsPtr = memoryData += readfdsAddr > data.i32;
^~~~
Extra information:
g++ -v
dumps gcc version 6.3.0
.The core is composed with
Operand Stack
Running loop to run Fetch -> Decode cycle
Program Counter...etc
Implement classes of the core with the components above.
Implement classes of the core with the components above.
Served as an helper to let people get used to wast and then wasm.
仿造其他架構中 syscall 的運作方式,
我們打算在 WasmVM 參考 linux 4.10 kernel, 利用 unreachable 實作 System call
請參考 syscall_64.tbl 的編號和名稱
請在 src/Syscall/Syscode.h 裡,參考其他 Syscall 的格式定義對應的編號
請在 src/Syscall/Syscall.cpp 裡, 加上對應的case 判斷
請將實作寫在 Call120.h 和 Call120.cpp
The message I got
src/Syscall/Call20.cpp:506:16: error: cannot initialize a variable of type 'std::int32_t' (aka 'int') with an rvalue of type 'void * std::int32_t ret = brk((void*)programbreakPtr);
make[2]: *** [src/Syscall/CMakeFiles/WasmVM_Syscall.dir/Call20.cpp.o] Error 1
brk
function which return a void pointer is not compatible type for variable ret
Do I miss something causing the error?
目前並沒有將 Java bytecode 轉換成 Webassembly 的工具, 主要的原因是 Java 在瀏覽器上執行時會造成一些安全性問題
但是 WasmVM 是運行在原生環境, 所以可以不用像瀏覽器一樣在安全性上有額外的顧慮,
因此將 Java bytecode 轉換成 Webassembly 是可行的, 而且這樣感覺很酷
Fetch & Decode is to:
As we discussed, Fetch & Decode can be independent function, or merged together.
Memory and Program Counter should be passed by parameters of reference.
Definition can be stored in an independent header file.
One or more functions, within Fetch, Decode namespace
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.