18 lines
459 B
Python
18 lines
459 B
Python
import wasm3 # type: ignore
|
|
|
|
from phasmplatform.common.exceptions import PhashPlatformNonIntMainReturnError
|
|
|
|
|
|
def run_once(wasm_bin: bytes) -> int:
|
|
env = wasm3.Environment()
|
|
rtime = env.new_runtime(1024 * 1024)
|
|
rtime.load(env.parse_module(wasm_bin))
|
|
result = rtime.find_function('main')()
|
|
if result is None:
|
|
return 0
|
|
|
|
if not isinstance(result, int):
|
|
raise PhashPlatformNonIntMainReturnError(result)
|
|
|
|
return result
|