You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/18-virtual-machine-instruction.md
+57-39Lines changed: 57 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
# Virtual machine (instruction-level)
2
2
3
-
An LLVM pass that replaces arithmetic instructions with calls to a register-based VM. Instead of executing `add`, `sub`, `mul`, etc. directly, operands are stored into a global register file. Then `__vm_dispatch(opcode, dst, src0, src1)` executes the operation via the proper VM handler and writes the result back to a destination register. This means that before calling `__vm_dispatch`, the inputs must be copied into the `src0` and `src1` registers, and the result must be read from the `dst` register.
3
+
An LLVM pass that replaces arithmetic instructions with calls to a register-based VM. Instead of executing `add`, `sub`, `mul`, etc. directly, operands are stored into a global register file and a bytecode blob is created for each instruction. Then `__vm_exec(bytecode_ptr)` reads the bytecode `[opcode, dst, src0, src1]`, executes the operation via the proper VM handler and writes the result back to a destination register. This means that before calling `__vm_exec`, the inputs must be copied into the `src0` and `src1` registers and the result must be read from the `dst` register.
4
4
5
-
This is a simplified, instruction-level approach. Commercial tools usually virtualize entire functions or regionsand hide control flow inside the VM. Here, we only virtualize individual operations while keeping branches and loops native.
5
+
This is a simplified, instruction-level approach. Commercial tools usually virtualize entire functions or regions, use a single bytecode stream with a fetch-decode-execute (FDE) loop and hide control flow inside the VM. Here, we create separate bytecode blobs per instruction and keep branches and loops native.
6
6
7
7
Known limitations:
8
8
- significantly increased code size
9
9
- significantly increased runtime penalty
10
+
- control flow remains visible (not virtualized)
11
+
- no bytecode encryption
10
12
- the VM can be easily reversed
11
13
12
14
The source code is available [here](https://github.com/gemesa/phantom-pass/tree/main/src/18-virtual-machine-instruction).
0 commit comments