diff --git a/Makefile b/Makefile index 39537590f..8e1e367fe 100644 --- a/Makefile +++ b/Makefile @@ -16,14 +16,9 @@ endif cp ./cmd/vmserver/vmserver ${VMSERVER_PATH} test: - go clean -cache -testcache - VMEXECUTOR="wasmer1" go test ./... go clean -cache -testcache VMEXECUTOR="wasmer2" go test ./... -test-w1: clean - VMEXECUTOR="wasmer1" go test ./... - test-w2: clean VMEXECUTOR="wasmer2" go test ./... diff --git a/cmd/scenariostest/scenariosTest.go b/cmd/scenariostest/scenariosTest.go index 468c56abe..caa7dba29 100644 --- a/cmd/scenariostest/scenariosTest.go +++ b/cmd/scenariostest/scenariosTest.go @@ -3,9 +3,7 @@ package main import ( scenclibase "github.com/multiversx/mx-chain-scenario-go/clibase" scenio "github.com/multiversx/mx-chain-scenario-go/scenario/io" - vmscenario "github.com/multiversx/mx-chain-vm-go/scenario" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/multiversx/mx-chain-vm-go/wasmer2" cli "github.com/urfave/cli/v2" ) @@ -42,9 +40,6 @@ func (*vm15Flags) ParseFlags(cCtx *cli.Context) scenclibase.CLIRunOptions { } vmBuilder := vmscenario.NewScenarioVMHostBuilder() - if cCtx.Bool("wasmer1") { - vmBuilder.OverrideVMExecutor = wasmer.ExecutorFactory() - } if cCtx.Bool("wasmer2") { vmBuilder.OverrideVMExecutor = wasmer2.ExecutorFactory() } diff --git a/integrationTests/json/scenariosExecutorLogs_test.go b/integrationTests/json/scenariosExecutorLogs_test.go deleted file mode 100644 index 1bd25880f..000000000 --- a/integrationTests/json/scenariosExecutorLogs_test.go +++ /dev/null @@ -1,362 +0,0 @@ -package vmjsonintegrationtest - -import ( - "testing" - - "github.com/multiversx/mx-chain-scenario-go/worldmock" - "github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor" - "github.com/multiversx/mx-chain-vm-go/wasmer" - "github.com/multiversx/mx-chain-vm-go/wasmer2" -) - -func TestRustCompareAdderLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("adder/scenarios"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("adder/scenarios"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestRustFactorialLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("factorial/scenarios"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("factorial/scenarios"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestRustErc20Log(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("erc20-rust/scenarios"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("erc20-rust/scenarios"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestCErc20Log(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("erc20-c"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("erc20-c"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestDigitalCashLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("digital-cash"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("digital-cash"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestESDTMultiTransferOnCallbackLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("features/composability/scenarios"). - File("forw_raw_call_async_retrieve_multi_transfer.scen.json"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("features/composability/scenarios"). - File("forw_raw_call_async_retrieve_multi_transfer.scen.json"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestCreateAsyncCallLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("features/composability/scenarios"). - File("promises_single_transfer.scen.json"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("features/composability/scenarios"). - File("promises_single_transfer.scen.json"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestESDTMultiTransferOnCallAndCallbackLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("features/composability/scenarios"). - File("forw_raw_async_send_and_retrieve_multi_transfer_funds.scen.json"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("features/composability/scenarios"). - File("forw_raw_async_send_and_retrieve_multi_transfer_funds.scen.json"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestMultisigLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("multisig/scenarios"). - Exclude("multisig/scenarios/interactor*"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("multisig/scenarios"). - Exclude("multisig/scenarios/interactor*"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestDnsContractLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - if testing.Short() { - t.Skip("not a short test") - } - - expected := ScenariosTest(t). - Folder("dns"). - WithEnableEpochsHandler(worldmock.EnableEpochsHandlerStubNoFlags()). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("dns"). - WithEnableEpochsHandler(worldmock.EnableEpochsHandlerStubNoFlags()). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestCrowdfundingEsdtLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("crowdfunding-esdt"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("crowdfunding-esdt"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestEgldEsdtSwapLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("egld-esdt-swap"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("egld-esdt-swap"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestPingPongEgldLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - expected := ScenariosTest(t). - Folder("ping-pong-egld"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("ping-pong-egld"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestRustAttestationLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - if testing.Short() { - t.Skip("not a short test") - } - - expected := ScenariosTest(t). - Folder("attestation-rust"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("attestation-rust"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} - -func TestCAttestationLog(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - if testing.Short() { - t.Skip("not a short test") - } - - expected := ScenariosTest(t). - Folder("attestation-c"). - WithExecutorFactory(wasmer.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - ExtractLog() - - ScenariosTest(t). - Folder("attestation-c"). - WithExecutorFactory(wasmer2.ExecutorFactory()). - WithExecutorLogs(). - Run(). - CheckNoError(). - CheckLog(expected) -} diff --git a/integrationTests/json/scenariosExecutorVersions_test.go b/integrationTests/json/scenariosExecutorVersions_test.go index 58b892d2f..0ac9e8115 100644 --- a/integrationTests/json/scenariosExecutorVersions_test.go +++ b/integrationTests/json/scenariosExecutorVersions_test.go @@ -1,66 +1,14 @@ package vmjsonintegrationtest import ( - "runtime" "testing" "github.com/multiversx/mx-chain-vm-go/executor" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/multiversx/mx-chain-vm-go/wasmer2" ) func TestCErc20Executors_TwiceW1ThenTwiceW2(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") - } - - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) -} - -func TestCErc20Executors_W1W2W1W2(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") - } - - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) -} - -func TestCErc20Executors_W1W2W2W1W2(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") - } - - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) -} - -func TestCErc20Executors_W2W1W2(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") - } - - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) -} - -func TestCErc20Executors_W2W2W1W2(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") - } - - testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) - testCERC20WithExecutorFactory(t, wasmer.ExecutorFactory()) testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) } diff --git a/integrationTests/json/scenariosTestCommon.go b/integrationTests/json/scenariosTestCommon.go index e5eaf4cb3..e5aac54fd 100644 --- a/integrationTests/json/scenariosTestCommon.go +++ b/integrationTests/json/scenariosTestCommon.go @@ -124,13 +124,13 @@ func (mtb *ScenariosTestBuilder) Run() *ScenariosTestBuilder { mtb.executorFactory) } - executor := scenexec.NewScenarioExecutor(vmBuilder) - defer executor.Close() + scenarioExecutor := scenexec.NewScenarioExecutor(vmBuilder) + defer scenarioExecutor.Close() - executor.World.EnableEpochsHandler = mtb.enableEpochsHandler + scenarioExecutor.World.EnableEpochsHandler = mtb.enableEpochsHandler runner := scenio.NewScenarioController( - executor, + scenarioExecutor, scenio.NewDefaultFileResolver(), vmBuilder.GetVMType(), ) diff --git a/mock/context/executorMock.go b/mock/context/executorMock.go index 2650e2c95..c85651290 100644 --- a/mock/context/executorMock.go +++ b/mock/context/executorMock.go @@ -7,7 +7,7 @@ import ( vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-go/executor" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/wasmer" + "github.com/multiversx/mx-chain-vm-go/wasmer2" ) // ExecutorMockFactory is the factory for the ExecutorRecorderMock. @@ -40,15 +40,18 @@ func (emf *ExecutorMockFactory) IsInterfaceNil() bool { // ExecutorMock can be passed to RuntimeContext as an InstanceBuilder to // create mocked Wasmer instances. type ExecutorMock struct { - InstanceMap map[string]InstanceMock - World *worldmock.MockWorld + InstanceMap map[string]InstanceMock + World *worldmock.MockWorld + WasmerExecutor *wasmer2.Wasmer2Executor } // NewExecutorMock constructs a new InstanceBuilderMock func NewExecutorMock(world *worldmock.MockWorld) *ExecutorMock { + exec, _ := wasmer2.CreateExecutor() return &ExecutorMock{ - InstanceMap: make(map[string]InstanceMock), - World: world, + InstanceMap: make(map[string]InstanceMock), + World: world, + WasmerExecutor: exec, } } @@ -106,7 +109,7 @@ func (executorMock *ExecutorMock) NewInstanceWithOptions( if ok { return instance, nil } - return wasmer.NewInstanceWithOptions(contractCode, options) + return executorMock.WasmerExecutor.NewInstanceWithOptions(contractCode, options) } // NewInstanceFromCompiledCodeWithOptions attempts to load a prepared instance @@ -120,7 +123,7 @@ func (executorMock *ExecutorMock) NewInstanceFromCompiledCodeWithOptions( if ok { return instance, nil } - return wasmer.NewInstanceFromCompiledCodeWithOptions(compiledCode, options) + return executorMock.WasmerExecutor.NewInstanceFromCompiledCodeWithOptions(compiledCode, options) } // IsInterfaceNil returns true if there is no value under the interface diff --git a/mock/context/instanceMock.go b/mock/context/instanceMock.go index ee9fdb733..912e0831b 100644 --- a/mock/context/instanceMock.go +++ b/mock/context/instanceMock.go @@ -7,7 +7,6 @@ import ( "github.com/multiversx/mx-chain-vm-go/executor" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/wasmer" ) var _ executor.Instance = (*InstanceMock)(nil) @@ -18,7 +17,7 @@ type mockMethod func() *InstanceMock // contracts within tests, without needing actual WASM smart contracts. type InstanceMock struct { Code []byte - Exports wasmer.ExportsMap + Exports map[string]string DefaultErrors map[string]error Methods map[string]mockMethod Points uint64 @@ -36,7 +35,7 @@ type InstanceMock struct { func NewInstanceMock(code []byte) *InstanceMock { return &InstanceMock{ Code: code, - Exports: make(wasmer.ExportsMap), + Exports: make(map[string]string), DefaultErrors: make(map[string]error), Methods: make(map[string]mockMethod), Points: 0, @@ -57,7 +56,7 @@ func (instance *InstanceMock) AddMockMethod(name string, method mockMethod) { func (instance *InstanceMock) AddMockMethodWithError(name string, method mockMethod, err error) { instance.Methods[name] = method instance.DefaultErrors[name] = err - instance.Exports[name] = &wasmer.ExportedFunctionCallInfo{} + instance.Exports[name] = name } // CallFunction mocked method diff --git a/testcommon/testexecutor/defaultTestExecutor.go b/testcommon/testexecutor/defaultTestExecutor.go index 577f71a7b..960efbc1c 100644 --- a/testcommon/testexecutor/defaultTestExecutor.go +++ b/testcommon/testexecutor/defaultTestExecutor.go @@ -7,16 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-vm-go/executor" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/multiversx/mx-chain-vm-go/wasmer2" ) // EnvVMEXECUTOR is the name of the environment variable that controls the default test executor var EnvVMEXECUTOR = "VMEXECUTOR" -// ExecWasmer1 is the value of the EnvVMEXECUTOR variable which selects Wasmer 1 -var ExecWasmer1 = "wasmer1" - // ExecWasmer2 is the value of the EnvVMEXECUTOR variable which selects Wasmer 2 var ExecWasmer2 = "wasmer2" @@ -26,9 +22,6 @@ var defaultExecutorString = ExecWasmer2 func NewDefaultTestExecutorFactory(tb testing.TB) executor.ExecutorAbstractFactory { execStr := getVMExecutorString() - if execStr == ExecWasmer1 { - return wasmer.ExecutorFactory() - } if execStr == ExecWasmer2 { return wasmer2.ExecutorFactory() } @@ -41,13 +34,6 @@ func NewDefaultTestExecutorFactory(tb testing.TB) executor.ExecutorAbstractFacto return nil } -// IsWasmer1Allowed returns true if the default test executor is Wasmer 1. -// If the default test executor is Wasmer 2, it is not allowed to instantiate a -// Wasmer 1 executor due to low-level conflicts between Wasmer 1 and 2. -func IsWasmer1Allowed() bool { - return getVMExecutorString() == ExecWasmer1 -} - func getVMExecutorString() string { execStr := os.Getenv(EnvVMEXECUTOR) diff --git a/vmhost/contexts/async_test.go b/vmhost/contexts/async_test.go index 31a148bf5..579693bdc 100644 --- a/vmhost/contexts/async_test.go +++ b/vmhost/contexts/async_test.go @@ -2,6 +2,7 @@ package contexts import ( "errors" + "github.com/multiversx/mx-chain-vm-go/wasmer2" "math/big" "testing" @@ -18,7 +19,6 @@ import ( "github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor" "github.com/multiversx/mx-chain-vm-go/vmhost" "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/stretchr/testify/require" ) @@ -58,7 +58,8 @@ func initializeVMAndWasmerAsyncContextWithBuiltIn(tb testing.TB, isBuiltinFunc b gasSchedule := config.MakeGasMapForTests() gasCostConfig, err := config.CreateGasConfig(gasSchedule) require.Nil(tb, err) - wasmer.SetOpcodeCosts(gasCostConfig.WASMOpcodeCost) + wasmerExecutor, _ := wasmer2.CreateExecutor() + wasmerExecutor.SetOpcodeCosts(gasCostConfig.WASMOpcodeCost) host := &contextmock.VMHostMock{ EnableEpochsHandlerField: &worldmock.EnableEpochsHandlerStub{}, diff --git a/vmhost/contexts/instanceTracker.go b/vmhost/contexts/instanceTracker.go index 01201fee5..158f4d91b 100644 --- a/vmhost/contexts/instanceTracker.go +++ b/vmhost/contexts/instanceTracker.go @@ -59,11 +59,7 @@ func NewInstanceTracker() (*instanceTracker, error) { var err error instanceEvictedCallback := tracker.makeInstanceEvictionCallback() - if WarmInstancesEnabled { - tracker.warmInstanceCache, err = lrucache.NewCacheWithEviction(warmCacheSize, instanceEvictedCallback) - } else { - tracker.warmInstanceCache = nil - } + tracker.warmInstanceCache, err = lrucache.NewCacheWithEviction(warmCacheSize, instanceEvictedCallback) if err != nil { return nil, err } @@ -100,9 +96,7 @@ func (tracker *instanceTracker) PopSetActiveState() { onStack := tracker.IsCodeHashOnTheStack(activeCodeHash) activeInstanceIsTopOfStack := stackedPrevInstance == activeInstance - cold := !WarmInstancesEnabled - - if !activeInstanceIsTopOfStack && (onStack || cold) { + if !activeInstanceIsTopOfStack && onStack { tracker.cleanPoppedInstance(activeInstance, activeCodeHash) } @@ -169,9 +163,7 @@ func (tracker *instanceTracker) CodeHash() []byte { // ClearWarmInstanceCache clears the internal warm instance cache func (tracker *instanceTracker) ClearWarmInstanceCache() { - if WarmInstancesEnabled { - tracker.warmInstanceCache.Clear() - } + tracker.warmInstanceCache.Clear() } // TrackedInstances returns the internal map of tracked instances @@ -227,8 +219,7 @@ func (tracker *instanceTracker) ForceCleanInstance(bypassWarmAndStackChecks bool } onStack := tracker.IsCodeHashOnTheStack(tracker.codeHash) - coldOnlyEnabled := !WarmInstancesEnabled - if onStack || coldOnlyEnabled { + if onStack { if tracker.instance.Clean() { tracker.updateNumRunningInstances(-1) } @@ -348,10 +339,7 @@ func (tracker *instanceTracker) LogCounts() { // NumRunningInstances returns the number of currently running instances (cold and warm) func (tracker *instanceTracker) NumRunningInstances() (int, int) { numWarmInstances := 0 - if WarmInstancesEnabled { - numWarmInstances = tracker.warmInstanceCache.Len() - } - + numWarmInstances = tracker.warmInstanceCache.Len() numColdInstances := tracker.numRunningInstances - numWarmInstances return numWarmInstances, numColdInstances } diff --git a/vmhost/contexts/instanceTracker_test.go b/vmhost/contexts/instanceTracker_test.go index 0aaf4b152..ff8544e38 100644 --- a/vmhost/contexts/instanceTracker_test.go +++ b/vmhost/contexts/instanceTracker_test.go @@ -5,7 +5,7 @@ import ( "testing" mock "github.com/multiversx/mx-chain-vm-go/mock/context" - "github.com/multiversx/mx-chain-vm-go/wasmer" + "github.com/multiversx/mx-chain-vm-go/wasmer2" "github.com/stretchr/testify/require" ) @@ -13,9 +13,8 @@ func TestInstanceTracker_TrackInstance(t *testing.T) { iTracker, err := NewInstanceTracker() require.Nil(t, err) - newInstance := &wasmer.WasmerInstance{ - AlreadyClean: false, - } + newInstance := &wasmer2.Wasmer2Instance{ + AlreadyClean: false} _ = iTracker.SetNewInstance(newInstance, Bytecode) iTracker.codeHash = []byte("testinst") @@ -338,7 +337,7 @@ func TestInstanceTracker_UnsetInstance_Ok(t *testing.T) { iTracker, err := NewInstanceTracker() require.Nil(t, err) - iTracker.instance = &wasmer.WasmerInstance{ + iTracker.instance = &wasmer2.Wasmer2Instance{ AlreadyClean: true, } iTracker.UnsetInstance() diff --git a/vmhost/contexts/runtime.go b/vmhost/contexts/runtime.go index 4ffc46ffa..9449c430f 100644 --- a/vmhost/contexts/runtime.go +++ b/vmhost/contexts/runtime.go @@ -28,9 +28,6 @@ var mapNewCryptoAPI = map[string]struct{}{ const warmCacheSize = 100 -// WarmInstancesEnabled controls the usage of warm instances -const WarmInstancesEnabled = true - type runtimeContext struct { host vmhost.VMHost vmInput *vmcommon.ContractCallInput @@ -270,10 +267,6 @@ func (context *runtimeContext) makeInstanceFromContractByteCode(contract []byte, } func (context *runtimeContext) useWarmInstanceIfExists(gasLimit uint64, newCode bool) (bool, error) { - if !WarmInstancesEnabled { - return false, nil - } - codeHash := context.iTracker.CodeHash() if newCode || len(codeHash) == 0 { return false, nil @@ -337,10 +330,6 @@ func (context *runtimeContext) saveCompiledCode() { } func (context *runtimeContext) saveWarmInstance() { - if !WarmInstancesEnabled { - return - } - codeHash := context.iTracker.CodeHash() if context.iTracker.IsCodeHashOnTheStack(codeHash) { return @@ -830,10 +819,6 @@ func (context *runtimeContext) EndExecution() { // ValidateInstances checks the state of the instances after execution func (context *runtimeContext) ValidateInstances() error { - if !WarmInstancesEnabled { - return nil - } - err := context.iTracker.CheckInstances() if err != nil { return err diff --git a/vmhost/contexts/runtime_test.go b/vmhost/contexts/runtime_test.go index 96cb131fb..ddfd0bee0 100644 --- a/vmhost/contexts/runtime_test.go +++ b/vmhost/contexts/runtime_test.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "github.com/multiversx/mx-chain-vm-go/wasmer2" "math/big" "testing" @@ -19,7 +20,6 @@ import ( "github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor" "github.com/multiversx/mx-chain-vm-go/vmhost" "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/stretchr/testify/require" ) @@ -32,7 +32,8 @@ var vmType = []byte("type") func InitializeVMAndWasmer() *contextmock.VMHostMock { gasSchedule := config.MakeGasMapForTests() gasCostConfig, _ := config.CreateGasConfig(gasSchedule) - wasmer.SetOpcodeCosts(gasCostConfig.WASMOpcodeCost) + wasmerExecutor, _ := wasmer2.CreateExecutor() + wasmerExecutor.SetOpcodeCosts(gasCostConfig.WASMOpcodeCost) host := &contextmock.VMHostMock{} @@ -276,7 +277,7 @@ func TestRuntimeContext_PushPopInstance(t *testing.T) { instance := runtimeCtx.iTracker.instance runtimeCtx.pushInstance() - runtimeCtx.iTracker.instance = &wasmer.WasmerInstance{} + runtimeCtx.iTracker.instance = &wasmer2.Wasmer2Instance{} runtimeCtx.iTracker.codeSize = newCodeSize require.Equal(t, newCodeSize, runtimeCtx.GetSCCodeSize()) require.Equal(t, 1, len(runtimeCtx.iTracker.instanceStack)) @@ -315,7 +316,7 @@ func TestRuntimeContext_PushPopState(t *testing.T) { } runtimeCtx.InitStateFromContractCallInput(input) - runtimeCtx.iTracker.instance = &wasmer.WasmerInstance{} + runtimeCtx.iTracker.instance = &wasmer2.Wasmer2Instance{} runtimeCtx.PushState() require.Equal(t, 1, len(runtimeCtx.stateStack)) @@ -337,11 +338,11 @@ func TestRuntimeContext_PushPopState(t *testing.T) { require.False(t, runtimeCtx.ReadOnly()) require.Nil(t, runtimeCtx.Arguments()) - runtimeCtx.iTracker.instance = &wasmer.WasmerInstance{} + runtimeCtx.iTracker.instance = &wasmer2.Wasmer2Instance{} runtimeCtx.PushState() require.Equal(t, 1, len(runtimeCtx.stateStack)) - runtimeCtx.iTracker.instance = &wasmer.WasmerInstance{} + runtimeCtx.iTracker.instance = &wasmer2.Wasmer2Instance{} runtimeCtx.PushState() require.Equal(t, 2, len(runtimeCtx.stateStack)) @@ -389,7 +390,7 @@ func TestRuntimeContext_CountContractInstancesOnStack(t *testing.T) { require.Equal(t, uint64(0), runtime.CountSameContractInstancesOnStack(beta)) require.Equal(t, uint64(0), runtime.CountSameContractInstancesOnStack(gamma)) - runtime.iTracker.instance = &wasmer.WasmerInstance{} + runtime.iTracker.instance = &wasmer2.Wasmer2Instance{} runtime.PushState() input.RecipientAddr = beta runtime.InitStateFromContractCallInput(input) @@ -397,7 +398,7 @@ func TestRuntimeContext_CountContractInstancesOnStack(t *testing.T) { require.Equal(t, uint64(0), runtime.CountSameContractInstancesOnStack(beta)) require.Equal(t, uint64(0), runtime.CountSameContractInstancesOnStack(gamma)) - runtime.iTracker.instance = &wasmer.WasmerInstance{} + runtime.iTracker.instance = &wasmer2.Wasmer2Instance{} runtime.PushState() input.RecipientAddr = gamma runtime.InitStateFromContractCallInput(input) @@ -405,7 +406,7 @@ func TestRuntimeContext_CountContractInstancesOnStack(t *testing.T) { require.Equal(t, uint64(1), runtime.CountSameContractInstancesOnStack(beta)) require.Equal(t, uint64(0), runtime.CountSameContractInstancesOnStack(gamma)) - runtime.iTracker.instance = &wasmer.WasmerInstance{} + runtime.iTracker.instance = &wasmer2.Wasmer2Instance{} runtime.PushState() input.RecipientAddr = alpha runtime.InitStateFromContractCallInput(input) diff --git a/vmhost/hosttest/bad_test.go b/vmhost/hosttest/bad_test.go index ba5c9f9aa..d662d6cf5 100644 --- a/vmhost/hosttest/bad_test.go +++ b/vmhost/hosttest/bad_test.go @@ -9,9 +9,7 @@ import ( "github.com/multiversx/mx-chain-vm-go/executor" contextmock "github.com/multiversx/mx-chain-vm-go/mock/context" test "github.com/multiversx/mx-chain-vm-go/testcommon" - "github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/multiversx/mx-chain-vm-go/wasmer2" "github.com/stretchr/testify/require" ) @@ -263,14 +261,6 @@ func TestBadContract_NoPanic_NonExistingFunction(t *testing.T) { }) } -func TestBadContractExtra_LongIntLoop_Wasmer1(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - testBadContractExtraLongIntLoop(t, wasmer.ExecutorFactory()) -} - func TestBadContractExtra_LongIntLoop_Wasmer2(t *testing.T) { testBadContractExtraLongIntLoop(t, wasmer2.ExecutorFactory()) } diff --git a/vmhost/hosttest/execution_benchmark_test.go b/vmhost/hosttest/execution_benchmark_test.go index 8b01602bb..2c6d3768c 100644 --- a/vmhost/hosttest/execution_benchmark_test.go +++ b/vmhost/hosttest/execution_benchmark_test.go @@ -16,7 +16,6 @@ import ( gasSchedules "github.com/multiversx/mx-chain-vm-go/scenario/gasSchedules" "github.com/multiversx/mx-chain-vm-go/testcommon" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/contexts" "github.com/multiversx/mx-chain-vm-go/vmhost/hostCore" "github.com/multiversx/mx-chain-vm-go/vmhost/mock" "github.com/stretchr/testify/assert" @@ -49,9 +48,6 @@ func Test_RunERC20BenchmarkFail(t *testing.T) { } func Test_WarmInstancesMemoryUsage(t *testing.T) { - if !contexts.WarmInstancesEnabled { - t.Skip("this test is only relevant with warm instances") - } if testing.Short() { t.Skip("not a short test") } @@ -60,9 +56,6 @@ func Test_WarmInstancesMemoryUsage(t *testing.T) { } func Test_WarmInstancesFuzzyMemoryUsage(t *testing.T) { - if !contexts.WarmInstancesEnabled { - t.Skip("this test is only relevant with warm instances") - } if testing.Short() { t.Skip("not a short test") } diff --git a/vmhost/hosttest/execution_test.go b/vmhost/hosttest/execution_test.go index 7b6e245fa..563d91a78 100644 --- a/vmhost/hosttest/execution_test.go +++ b/vmhost/hosttest/execution_test.go @@ -23,7 +23,6 @@ import ( "github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor" "github.com/multiversx/mx-chain-vm-go/vmhost" "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" - "github.com/multiversx/mx-chain-vm-go/wasmer" "github.com/multiversx/mx-chain-vm-go/wasmer2" twoscomplement "github.com/multiversx/mx-components-big-int/twos-complement" "github.com/stretchr/testify/assert" @@ -140,14 +139,6 @@ func TestExecution_DeployNotWASM(t *testing.T) { }) } -func TestExecution_DeployWASM_WrongInit_Wasmer1(t *testing.T) { - if !testexecutor.IsWasmer1Allowed() { - t.Skip("run exclusively with wasmer1") - } - - testExecutionDeployWASMWrongInit(t, wasmer.ExecutorFactory()) -} - func TestExecution_DeployWASM_WrongInit_Wasmer2(t *testing.T) { testExecutionDeployWASMWrongInit(t, wasmer2.ExecutorFactory()) } diff --git a/vmhost/hosttest/wasmer_test.go b/vmhost/hosttest/wasmer_test.go index 26d5d27f9..f081b6425 100644 --- a/vmhost/hosttest/wasmer_test.go +++ b/vmhost/hosttest/wasmer_test.go @@ -9,7 +9,6 @@ import ( contextmock "github.com/multiversx/mx-chain-vm-go/mock/context" test "github.com/multiversx/mx-chain-vm-go/testcommon" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/contexts" "github.com/multiversx/mx-chain-vm-go/wasmer2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -241,10 +240,6 @@ func TestWASMMemories_MultipleMemories(t *testing.T) { } func TestWASMMemories_ResetContent(t *testing.T) { - if !contexts.WarmInstancesEnabled { - t.Skip("test only relevant with warm instances") - } - testCase := test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). @@ -271,10 +266,6 @@ func TestWASMMemories_ResetContent(t *testing.T) { } func TestWASMMemories_ResetDataInitializers(t *testing.T) { - if !contexts.WarmInstancesEnabled { - t.Skip("test only relevant with warm instances") - } - testCase := test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). diff --git a/vmhost/vmhooks/generate/cmd/eiGenMain.go b/vmhost/vmhooks/generate/cmd/eiGenMain.go index 1579d0748..b20216e6d 100644 --- a/vmhost/vmhooks/generate/cmd/eiGenMain.go +++ b/vmhost/vmhooks/generate/cmd/eiGenMain.go @@ -44,7 +44,6 @@ func main() { writeVMHooks(eiMetadata) writeVMHooksWrapper(eiMetadata) - writeWasmer1ImportsCgo(eiMetadata) writeWasmer2ImportsCgo(eiMetadata) writeWasmer2Names(eiMetadata) @@ -85,12 +84,6 @@ func writeVMHooksWrapper(eiMetadata *eapigen.EIMetadata) { eapigen.WriteVMHooksWrapper(out, eiMetadata) } -func writeWasmer1ImportsCgo(eiMetadata *eapigen.EIMetadata) { - out := eapigen.NewEIGenWriter(pathToApiPackage, "../../wasmer/wasmerImportsCgo.go") - defer out.Close() - eapigen.WriteWasmer1Cgo(out, eiMetadata) -} - func writeWasmer2ImportsCgo(eiMetadata *eapigen.EIMetadata) { out := eapigen.NewEIGenWriter(pathToApiPackage, "../../wasmer2/wasmer2ImportsCgo.go") defer out.Close() diff --git a/wasmer/bridge.go b/wasmer/bridge.go deleted file mode 100644 index b00918dff..000000000 --- a/wasmer/bridge.go +++ /dev/null @@ -1,382 +0,0 @@ -package wasmer - -// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -// #cgo linux,amd64 LDFLAGS:-lwasmer_linux_amd64 -// #cgo linux,arm64 LDFLAGS:-lwasmer_linux_arm64_shim -// #cgo darwin,amd64 LDFLAGS:-lwasmer_darwin_amd64 -// #cgo darwin,arm64 LDFLAGS:-lwasmer_darwin_arm64_shim -// #include "./wasmer.h" -// -import "C" -import ( - "unsafe" -) - -type cBool C.bool -type cChar C.char -type cInt C.int -type cUchar C.uchar -type cUint C.uint -type cUint32T C.uint32_t -type cUint8T C.uint8_t -type cWasmerByteArray C.wasmer_byte_array -type cWasmerExportFuncT C.wasmer_export_func_t -type cWasmerExportT C.wasmer_export_t -type cWasmerExportsT C.wasmer_exports_t -type cWasmerImportExportKind C.wasmer_import_export_kind -type cWasmerImportExportValue C.wasmer_import_export_value -type cWasmerImportFuncT C.wasmer_import_func_t -type cWasmerImportT C.wasmer_import_t -type cWasmerInstanceContextT C.wasmer_instance_context_t -type cWasmerInstanceT C.wasmer_instance_t -type cWasmerMemoryT C.wasmer_memory_t -type cWasmerResultT C.wasmer_result_t -type cWasmerValueT C.wasmer_value_t -type cWasmerValueTag C.wasmer_value_tag -type cWasmerCompilationOptions C.wasmer_compilation_options_t - -const cWasmFunction = C.WASM_FUNCTION -const cWasmGlobal = C.WASM_GLOBAL -const cWasmI32 = C.WASM_I32 -const cWasmI64 = C.WASM_I64 -const cWasmMemory = C.WASM_MEMORY -const cWasmTable = C.WASM_TABLE -const cWasmerOk = C.WASMER_OK - -func cNewWasmerImportT(moduleName string, importName string, function *cWasmerImportFuncT) cWasmerImportT { - var importedFunction C.wasmer_import_t - importedFunction.module_name = (C.wasmer_byte_array)(cGoStringToWasmerByteArray(moduleName)) - importedFunction.import_name = (C.wasmer_byte_array)(cGoStringToWasmerByteArray(importName)) - importedFunction.tag = cWasmFunction - - var pointer = (**C.wasmer_import_func_t)(unsafe.Pointer(&importedFunction.value)) - *pointer = (*C.wasmer_import_func_t)(function) - - return (cWasmerImportT)(importedFunction) -} - -func cWasmerInstanceGetPointsUsed(instance *cWasmerInstanceT) uint64 { - return uint64(C.wasmer_instance_get_points_used( - (*C.wasmer_instance_t)(instance), - )) -} - -func cWasmerInstanceSetPointsUsed(instance *cWasmerInstanceT, points uint64) { - C.wasmer_instance_set_points_used( - (*C.wasmer_instance_t)(instance), - (C.uint64_t)(points), - ) -} - -func cWasmerInstanceSetGasLimit(instance *cWasmerInstanceT, gasLimit uint64) { - C.wasmer_instance_set_points_limit( - (*C.wasmer_instance_t)(instance), - (C.uint64_t)(gasLimit), - ) -} - -func cWasmerInstanceSetBreakpointValue(instance *cWasmerInstanceT, value uint64) { - C.wasmer_instance_set_runtime_breakpoint_value( - (*C.wasmer_instance_t)(instance), - (C.uint64_t)(value), - ) -} - -func cWasmerInstanceGetBreakpointValue(instance *cWasmerInstanceT) uint64 { - return uint64(C.wasmer_instance_get_runtime_breakpoint_value( - (*C.wasmer_instance_t)(instance), - )) -} - -func cWasmerInstanceIsFunctionImported(instance *cWasmerInstanceT, name string) bool { - var functionName = cCString(name) - return bool(C.wasmer_instance_is_function_imported( - (*C.wasmer_instance_t)(instance), - (*C.char)(unsafe.Pointer(functionName)), - )) -} - -func cWasmerInstanceEnableRkyv() { - C.wasmer_instance_enable_rkyv() -} - -func cWasmerInstanceDisableRkyv() { - C.wasmer_instance_disable_rkyv() -} - -func cWasmerSetSIGSEGVPassthrough() { - C.wasmer_set_sigsegv_passthrough() -} - -func cWasmerForceInstallSighandlers() { - C.wasmer_force_install_sighandlers() -} - -func cWasmerInstanceCache( - instance *cWasmerInstanceT, - cacheBytes **cUchar, - cacheLen *cUint32T, -) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_instance_cache( - (*C.wasmer_instance_t)(instance), - (**C.uchar)(unsafe.Pointer(cacheBytes)), - (*C.uint32_t)(cacheLen), - )) -} - -func cWasmerInstanceFromCache( - instance **cWasmerInstanceT, - cacheBytes *cUchar, - cacheLen cUint32T, - options *cWasmerCompilationOptions, -) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_instance_from_cache( - (**C.wasmer_instance_t)(unsafe.Pointer(instance)), - (*C.uchar)(cacheBytes), - (C.uint32_t)(cacheLen), - (*C.wasmer_compilation_options_t)(options), - )) -} - -func cWasmerCacheImportObjectFromImports( - imports *cWasmerImportT, - importsLength cInt, -) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_import_object_cache_from_imports( - (*C.wasmer_import_t)(imports), - (C.uint32_t)(importsLength), - )) -} - -func cWasmerSetOpcodeCosts(opcodeCostArray *[opcodeCount]uint32) { - C.wasmer_set_opcode_costs( - (*C.uint32_t)(unsafe.Pointer(opcodeCostArray)), - ) -} - -func cWasmerExportFuncParams(function *cWasmerExportFuncT, parameters *cWasmerValueTag, parametersLength cUint32T) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_export_func_params( - (*C.wasmer_export_func_t)(function), - (*C.wasmer_value_tag)(parameters), - (C.uint32_t)(parametersLength), - )) -} - -func cWasmerExportFuncParamsArity(function *cWasmerExportFuncT, result *cUint32T) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_export_func_params_arity( - (*C.wasmer_export_func_t)(function), - (*C.uint32_t)(result), - )) -} - -func cWasmerExportFuncResultsArity(function *cWasmerExportFuncT, result *cUint32T) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_export_func_returns_arity( - (*C.wasmer_export_func_t)(function), - (*C.uint32_t)(result), - )) -} - -func cWasmerExportKind(export *cWasmerExportT) cWasmerImportExportKind { - return (cWasmerImportExportKind)(C.wasmer_export_kind( - (*C.wasmer_export_t)(export), - )) -} - -func cWasmerExportName(export *cWasmerExportT) cWasmerByteArray { - return (cWasmerByteArray)(C.wasmer_export_name( - (*C.wasmer_export_t)(export), - )) -} - -func cWasmerExportToFunc(export *cWasmerExportT) *cWasmerExportFuncT { - return (*cWasmerExportFuncT)(C.wasmer_export_to_func( - (*C.wasmer_export_t)(export), - )) -} - -func cWasmerExportToMemory(export *cWasmerExportT, memory **cWasmerMemoryT) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_export_to_memory( - (*C.wasmer_export_t)(export), - (**C.wasmer_memory_t)(unsafe.Pointer(memory)), - )) -} - -func cWasmerExportsDestroy(exports *cWasmerExportsT) { - C.wasmer_exports_destroy( - (*C.wasmer_exports_t)(exports), - ) -} - -func cWasmerExportsGet(exports *cWasmerExportsT, index cInt) *cWasmerExportT { - return (*cWasmerExportT)(C.wasmer_exports_get( - (*C.wasmer_exports_t)(exports), - (C.int)(index), - )) -} - -func cWasmerExportsLen(exports *cWasmerExportsT) cInt { - return (cInt)(C.wasmer_exports_len( - (*C.wasmer_exports_t)(exports), - )) -} - -func cWasmerImportFuncDestroy(function *cWasmerImportFuncT) { - C.wasmer_import_func_destroy( - (*C.wasmer_import_func_t)(function), - ) -} - -func cWasmerImportFuncNew( - function unsafe.Pointer, - parametersSignature *cWasmerValueTag, - parametersLength cUint, - resultsSignature *cWasmerValueTag, - resultsLength cUint, -) *cWasmerImportFuncT { - return (*cWasmerImportFuncT)(C.wasmer_import_func_new( - (*[0]byte)(function), - (*C.wasmer_value_tag)(parametersSignature), - (C.uint)(parametersLength), - (*C.wasmer_value_tag)(resultsSignature), - (C.uint)(resultsLength), - )) -} - -func cWasmerInstanceCall( - instance *cWasmerInstanceT, - name *cChar, - parameters *cWasmerValueT, - parametersLength cUint32T, - results *cWasmerValueT, - resultsLength cUint32T, -) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_instance_call( - (*C.wasmer_instance_t)(instance), - (*C.char)(name), - (*C.wasmer_value_t)(parameters), - (C.uint32_t)(parametersLength), - (*C.wasmer_value_t)(results), - (C.uint32_t)(resultsLength), - )) -} - -func cWasmerInstanceContextGet(instance *cWasmerInstanceT) *cWasmerInstanceContextT { - return (*cWasmerInstanceContextT)(C.wasmer_instance_context_get( - (*C.wasmer_instance_t)(instance), - )) -} - -func cWasmerInstanceContextDataGet(instanceContext *cWasmerInstanceContextT) unsafe.Pointer { - return unsafe.Pointer(C.wasmer_instance_context_data_get( - (*C.wasmer_instance_context_t)(instanceContext), - )) -} - -func cWasmerInstanceContextDataSet(instance *cWasmerInstanceT, dataPointer unsafe.Pointer) { - C.wasmer_instance_context_data_set( - (*C.wasmer_instance_t)(instance), - dataPointer, - ) -} - -func cWasmerInstanceContextMemory(instanceContext *cWasmerInstanceContextT) *cWasmerMemoryT { - return (*cWasmerMemoryT)(C.wasmer_instance_context_memory( - (*C.wasmer_instance_context_t)(instanceContext), - 0, - )) -} - -func cWasmerInstanceReset(instance *cWasmerInstanceT) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_instance_reset( - (*C.wasmer_instance_t)(instance), - )) -} - -func cWasmerInstanceDestroy(instance *cWasmerInstanceT) { - C.wasmer_instance_destroy( - (*C.wasmer_instance_t)(instance), - ) -} - -func cWasmerInstanceExports(instance *cWasmerInstanceT, exports **cWasmerExportsT) { - C.wasmer_instance_exports( - (*C.wasmer_instance_t)(instance), - (**C.wasmer_exports_t)(unsafe.Pointer(exports)), - ) -} - -func cWasmerInstantiateWithOptions( - instance **cWasmerInstanceT, - wasmBytes *cUchar, - wasmBytesLength cUint, - options *cWasmerCompilationOptions, -) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_instantiate_with_options( - (**C.wasmer_instance_t)(unsafe.Pointer(instance)), - (*C.uchar)(wasmBytes), - (C.uint)(wasmBytesLength), - (*C.wasmer_compilation_options_t)(options), - )) -} - -func cWasmerLastErrorLength() cInt { - return (cInt)(C.wasmer_last_error_length()) -} - -func cWasmerLastErrorMessage(buffer *cChar, length cInt) cInt { - return (cInt)(C.wasmer_last_error_message( - (*C.char)(buffer), - (C.int)(length), - )) -} - -func cWasmerMemoryData(memory *cWasmerMemoryT) *cUint8T { - return (*cUint8T)(C.wasmer_memory_data( - (*C.wasmer_memory_t)(memory), - )) -} - -func cWasmerMemoryDataLength(memory *cWasmerMemoryT) cUint32T { - return (cUint32T)(C.wasmer_memory_data_length( - (*C.wasmer_memory_t)(memory), - )) -} - -func cWasmerMemoryGrow(memory *cWasmerMemoryT, numberOfPages cUint32T) cWasmerResultT { - return (cWasmerResultT)(C.wasmer_memory_grow( - (*C.wasmer_memory_t)(memory), - (C.uint32_t)(numberOfPages), - )) -} - -func cWasmerMemoryDestroy(memory *cWasmerMemoryT) { - C.wasmer_memory_destroy( - (*C.wasmer_memory_t)(memory), - ) -} - -func cCString(string string) *cChar { - return (*cChar)(C.CString(string)) -} - -func cFree(pointer unsafe.Pointer) { - C.free(pointer) -} - -func cGoString(string *cChar) string { - return C.GoString((*C.char)(string)) -} - -func cGoStringN(string *cChar, length cInt) string { - return C.GoStringN((*C.char)(string), (C.int)(length)) -} - -func cGoStringToWasmerByteArray(string string) cWasmerByteArray { - var cString = cCString(string) - - var byteArray cWasmerByteArray - byteArray.bytes = (*C.uchar)(unsafe.Pointer(cString)) - byteArray.bytes_len = (C.uint)(len(string)) - - return byteArray -} diff --git a/wasmer/error.go b/wasmer/error.go deleted file mode 100644 index 10db0e336..000000000 --- a/wasmer/error.go +++ /dev/null @@ -1,38 +0,0 @@ -package wasmer - -import ( - "errors" - "unsafe" -) - -// ErrFailedInstantiation indicates that a Wasmer instance could not be created -var ErrFailedInstantiation = errors.New("could not create wasmer instance") - -// ErrFailedCacheImports indicates that the imports could not be cached -var ErrFailedCacheImports = errors.New("could not cache imports") - -// ErrInvalidBytecode indicates that the bytecode is invalid -var ErrInvalidBytecode = errors.New("invalid bytecode") - -// ErrCachingFailed indicates that creating the precompilation cache of an instance has failed -var ErrCachingFailed = errors.New("instance caching failed") - -// GetLastError returns the last error message if any, otherwise returns an error. -func GetLastError() (string, error) { - var errorLength = cWasmerLastErrorLength() - - if errorLength == 0 { - return "", nil - } - - var errorMessage = make([]cChar, errorLength) - var errorMessagePointer = (*cChar)(unsafe.Pointer(&errorMessage[0])) - - var errorResult = cWasmerLastErrorMessage(errorMessagePointer, errorLength) - - if -1 == errorResult { - return "", errors.New("cannot read last error") - } - - return cGoString(errorMessagePointer), nil -} diff --git a/wasmer/function_wrapper_helpers.go b/wasmer/function_wrapper_helpers.go deleted file mode 100644 index 8d6c7c502..000000000 --- a/wasmer/function_wrapper_helpers.go +++ /dev/null @@ -1,194 +0,0 @@ -package wasmer - -import ( - "fmt" - "unsafe" -) - -func getExportedFunctionSignature( - wasmFunction *cWasmerExportFuncT, - exportedFunctionName string, -) ([]cWasmerValueTag, cUint32T, error) { - var wasmFunctionInputsArity cUint32T - if cWasmerExportFuncParamsArity(wasmFunction, &wasmFunctionInputsArity) != cWasmerOk { - return nil, 0, NewExportedFunctionError(exportedFunctionName, "Failed to read the input arity of the `%s` exported function.") - } - - var wasmFunctionInputSignatures = make([]cWasmerValueTag, int(wasmFunctionInputsArity)) - - if wasmFunctionInputsArity > 0 { - var wasmFunctionInputSignaturesCPointer = (*cWasmerValueTag)(unsafe.Pointer(&wasmFunctionInputSignatures[0])) - - if cWasmerExportFuncParams(wasmFunction, wasmFunctionInputSignaturesCPointer, wasmFunctionInputsArity) != cWasmerOk { - return nil, 0, NewExportedFunctionError(exportedFunctionName, "Failed to read the signature of the `%s` exported function.") - } - } - - return wasmFunctionInputSignatures, wasmFunctionInputsArity, nil -} - -func getExportedFunctionOutputArity( - wasmFunction *cWasmerExportFuncT, - exportedFunctionName string, -) (cUint32T, error) { - var wasmFunctionOutputsArity cUint32T - if cWasmerExportFuncResultsArity(wasmFunction, &wasmFunctionOutputsArity) != cWasmerOk { - return cUint32T(0), NewExportedFunctionError(exportedFunctionName, "Failed to read the output arity of the `%s` exported function.") - } - return wasmFunctionOutputsArity, nil -} - -func validateGivenArguments( - exportedFunctionName string, - arguments []interface{}, - wasmFunctionInputsArity cUint32T, -) error { - var numberOfGivenArguments = len(arguments) - var diff = int(wasmFunctionInputsArity) - numberOfGivenArguments - - if diff > 0 { - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Missing %d argument(s) when calling the `%%s` exported function; Expect %d argument(s), given %d.", diff, int(wasmFunctionInputsArity), numberOfGivenArguments)) - } else if diff < 0 { - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Given %d extra argument(s) when calling the `%%s` exported function; Expect %d argument(s), given %d.", -diff, int(wasmFunctionInputsArity), numberOfGivenArguments)) - } - return nil -} - -func callWasmFunction( - cInstance *cWasmerInstanceT, - exportedFunctionName string, - wasmFunctionInputsArity cUint32T, - wasmFunctionOutputsArity cUint32T, - wasmInputs []cWasmerValueT, -) ([]cWasmerValueT, cWasmerResultT) { - var wasmFunctionName = cCString(exportedFunctionName) - defer cFree(unsafe.Pointer(wasmFunctionName)) - - var wasmInputsCPointer *cWasmerValueT - if wasmFunctionInputsArity > 0 { - wasmInputsCPointer = (*cWasmerValueT)(unsafe.Pointer(&wasmInputs[0])) - } else { - wasmInputsCPointer = (*cWasmerValueT)(unsafe.Pointer(&wasmInputs)) - } - - var wasmOutputs = make([]cWasmerValueT, wasmFunctionOutputsArity) - var wasmOutputsCPointer *cWasmerValueT - if wasmFunctionOutputsArity > 0 { - wasmOutputsCPointer = (*cWasmerValueT)(unsafe.Pointer(&wasmOutputs[0])) - } else { - wasmOutputsCPointer = (*cWasmerValueT)(unsafe.Pointer(&wasmOutputs)) - } - - var callResult = cWasmerInstanceCall( - cInstance, - wasmFunctionName, - wasmInputsCPointer, - wasmFunctionInputsArity, - wasmOutputsCPointer, - wasmFunctionOutputsArity, - ) - - return wasmOutputs, callResult -} - -func createWasmInputsFromArguments( - arguments []interface{}, - wasmFunctionInputsArity cUint32T, - wasmFunctionInputSignatures []cWasmerValueTag, - exportedFunctionName string, -) ([]cWasmerValueT, error) { - var err error - var wasmInputs = make([]cWasmerValueT, wasmFunctionInputsArity) - for index, value := range arguments { - var wasmInputType = wasmFunctionInputSignatures[index] - - switch wasmInputType { - case cWasmI32: - err = writeInt32ToWasmInputs(wasmInputs, index, value, exportedFunctionName) - if err != nil { - return nil, err - } - case cWasmI64: - err = writeInt64ToWasmInputs(wasmInputs, index, value, exportedFunctionName) - if err != nil { - return nil, err - } - default: - return nil, NewExportedFunctionError(exportedFunctionName, "Invalid arguments type when calling the `%s` exported function.") - } - } - - return wasmInputs, nil -} - -func writeInt32ToWasmInputs(wasmInputs []cWasmerValueT, index int, value interface{}, exportedFunctionName string) error { - wasmInputs[index].tag = cWasmI32 - var pointer = (*int32)(unsafe.Pointer(&wasmInputs[index].value)) - - switch typedValue := value.(type) { - case int8: - *pointer = int32(typedValue) - case uint8: - *pointer = int32(typedValue) - case int16: - *pointer = int32(typedValue) - case uint16: - *pointer = int32(typedValue) - case int32: - *pointer = typedValue - case int: - *pointer = int32(typedValue) - case uint: - *pointer = int32(typedValue) - case Value: - var val = value.(Value) - - if val.GetType() != TypeI32 { - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Argument #%d of the `%%s` exported function must be of type `i32`, cannot cast given value to this type.", index+1)) - } - - *pointer = val.ToI32() - default: - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Argument #%d of the `%%s` exported function must be of type `i32`, cannot cast given value to this type.", index+1)) - } - - return nil -} - -func writeInt64ToWasmInputs(wasmInputs []cWasmerValueT, index int, value interface{}, exportedFunctionName string) error { - wasmInputs[index].tag = cWasmI64 - var pointer = (*int64)(unsafe.Pointer(&wasmInputs[index].value)) - - switch typedValue := value.(type) { - case int8: - *pointer = int64(typedValue) - case uint8: - *pointer = int64(typedValue) - case int16: - *pointer = int64(typedValue) - case uint16: - *pointer = int64(typedValue) - case int32: - *pointer = int64(typedValue) - case uint32: - *pointer = int64(typedValue) - case int64: - *pointer = typedValue - case int: - *pointer = int64(typedValue) - case uint: - *pointer = int64(typedValue) - case Value: - var val = value.(Value) - - if val.GetType() != TypeI64 { - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Argument #%d of the `%%s` exported function must be of type `i64`, cannot cast given value to this type.", index+1)) - } - - *pointer = val.ToI64() - default: - return NewExportedFunctionError(exportedFunctionName, fmt.Sprintf("Argument #%d of the `%%s` exported function must be of type `i64`, cannot cast given value to this type.", index+1)) - } - - return nil -} diff --git a/wasmer/libwasmer_darwin_amd64.dylib b/wasmer/libwasmer_darwin_amd64.dylib deleted file mode 100755 index 6c89493cc..000000000 Binary files a/wasmer/libwasmer_darwin_amd64.dylib and /dev/null differ diff --git a/wasmer/libwasmer_darwin_arm64_shim.dylib b/wasmer/libwasmer_darwin_arm64_shim.dylib deleted file mode 100644 index 3adf25f49..000000000 Binary files a/wasmer/libwasmer_darwin_arm64_shim.dylib and /dev/null differ diff --git a/wasmer/libwasmer_linux_amd64.so b/wasmer/libwasmer_linux_amd64.so deleted file mode 100644 index 6aa7463d4..000000000 Binary files a/wasmer/libwasmer_linux_amd64.so and /dev/null differ diff --git a/wasmer/libwasmer_linux_arm64_shim.so b/wasmer/libwasmer_linux_arm64_shim.so deleted file mode 100644 index 79842a313..000000000 Binary files a/wasmer/libwasmer_linux_arm64_shim.so and /dev/null differ diff --git a/wasmer/memory.go b/wasmer/memory.go deleted file mode 100644 index 02ce5b270..000000000 --- a/wasmer/memory.go +++ /dev/null @@ -1,101 +0,0 @@ -package wasmer - -import ( - "fmt" - "reflect" - "unsafe" -) - -// MemoryError represents any kind of errors related to a WebAssembly memory. It -// is returned by `Memory` functions only. -type MemoryError struct { - // Error message. - message string -} - -// NewMemoryError constructs a new `MemoryError`. -func NewMemoryError(message string) *MemoryError { - return &MemoryError{message} -} - -// `MemoryError` is an actual error. The `Error` function returns -// the error message. -func (error *MemoryError) Error() string { - return error.message -} - -// Memory represents an exported memory of a WebAssembly instance. To read -// and write data, please see the `Data` function. -type Memory struct { - memory *cWasmerMemoryT -} - -// Instantiates a new WebAssembly exported memory. -func newMemory(memory *cWasmerMemoryT) Memory { - return Memory{memory} -} - -// Length calculates the memory length (in bytes). -func (memory *Memory) Length() uint32 { - if nil == memory.memory { - return 0 - } - - return uint32(cWasmerMemoryDataLength(memory.memory)) -} - -// Data returns a slice of bytes over the WebAssembly memory. -//nolint:all -func (memory *Memory) Data() []byte { - if nil == memory.memory { - return make([]byte, 0) - } - - var length = memory.Length() - var data = (*uint8)(cWasmerMemoryData(memory.memory)) - - var header reflect.SliceHeader - header = *(*reflect.SliceHeader)(unsafe.Pointer(&header)) - - header.Data = uintptr(unsafe.Pointer(data)) - header.Len = int(length) - header.Cap = int(length) - - return *(*[]byte)(unsafe.Pointer(&header)) -} - -// Grow the memory by a number of pages (65kb each). -func (memory *Memory) Grow(numberOfPages uint32) error { - if nil == memory.memory { - return nil - } - - var growResult = cWasmerMemoryGrow(memory.memory, cUint32T(numberOfPages)) - - if growResult != cWasmerOk { - var lastError, err = GetLastError() - var errorMessage = "Failed to grow the memory:\n %s" - - if err != nil { - errorMessage = fmt.Sprintf(errorMessage, "(unknown details)") - } else { - errorMessage = fmt.Sprintf(errorMessage, lastError) - } - - return NewMemoryError(errorMessage) - } - - return nil -} - -// Destroy destroys inner memory -func (memory *Memory) Destroy() { - if memory.memory != nil { - cWasmerMemoryDestroy(memory.memory) - } -} - -// IsInterfaceNil returns true if underlying object is nil -func (memory *Memory) IsInterfaceNil() bool { - return memory == nil -} diff --git a/wasmer/value.go b/wasmer/value.go deleted file mode 100644 index fd53b4e31..000000000 --- a/wasmer/value.go +++ /dev/null @@ -1,97 +0,0 @@ -package wasmer - -import ( - "fmt" -) - -// ValueType represents the `Value` type. -type ValueType int - -const ( - // TypeI32 represents the WebAssembly `i32` type. - TypeI32 ValueType = iota - - // TypeI64 represents the WebAssembly `i64` type. - TypeI64 - - // TypeVoid represents nothing. - // WebAssembly doesn't have “void” type, but it is introduced - // here to represent the returned value of a WebAssembly exported - // function that returns nothing. - TypeVoid -) - -// Value represents a WebAssembly value of a particular type. -type Value struct { - // The WebAssembly value (as bits). - value uint64 - - // The WebAssembly value type. - ty ValueType -} - -// I32 constructs a WebAssembly value of type `i32`. -func I32(value int32) Value { - return Value{ - value: uint64(value), - ty: TypeI32, - } -} - -// I64 constructs a WebAssembly value of type `i64`. -func I64(value int64) Value { - return Value{ - value: uint64(value), - ty: TypeI64, - } -} - -// Void constructs an empty WebAssembly value. -func Void() Value { - return Value{ - value: 0, - ty: TypeVoid, - } -} - -// GetType gets the type of the WebAssembly value. -func (value Value) GetType() ValueType { - return value.ty -} - -// ToI32 reads the WebAssembly value bits as an `int32`. The WebAssembly -// value type is ignored. -func (value Value) ToI32() int32 { - return int32(value.value) -} - -// ToI64 reads the WebAssembly value bits as an `int64`. The WebAssembly -// value type is ignored. -func (value Value) ToI64() int64 { - return int64(value.value) -} - -// ToVoid reads the WebAssembly value bits as a `nil`. The WebAssembly -// value type is ignored. -func (value Value) ToVoid() interface{} { - return nil -} - -// String formats the WebAssembly value as a Go string. -func (value Value) String() string { - switch value.ty { - case TypeI32: - return fmt.Sprintf("%d", value.ToI32()) - case TypeI64: - return fmt.Sprintf("%d", value.ToI64()) - case TypeVoid: - return "void" - default: - return "" - } -} - -// IsVoid returns true if the type is void -func (value Value) IsVoid() bool { - return value.ty == TypeVoid -} diff --git a/wasmer/wasmer.go b/wasmer/wasmer.go deleted file mode 100644 index b5461c601..000000000 --- a/wasmer/wasmer.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package wasmer is a Go library to run WebAssembly binaries. -package wasmer - -import logger "github.com/multiversx/mx-chain-logger-go" - -var logWasmer = logger.GetOrCreate("vm/wasmer") diff --git a/wasmer/wasmer.h b/wasmer/wasmer.h deleted file mode 100644 index e3d92cfdf..000000000 --- a/wasmer/wasmer.h +++ /dev/null @@ -1,1602 +0,0 @@ - -#if !defined(WASMER_H_MACROS) - -#define WASMER_H_MACROS - -// Define the `ARCH_X86_X64` constant. -#if defined(MSVC) && defined(_M_AMD64) -# define ARCH_X86_64 -#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) -# define ARCH_X86_64 -#endif - -// Compatibility with non-Clang compilers. -#if !defined(__has_attribute) -# define __has_attribute(x) 0 -#endif - -// Compatibility with non-Clang compilers. -#if !defined(__has_declspec_attribute) -# define __has_declspec_attribute(x) 0 -#endif - -// Define the `DEPRECATED` macro. -#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated) -# define DEPRECATED(message) __attribute__((deprecated(message))) -#elif defined(MSVC) || __has_declspec_attribute(deprecated) -# define DEPRECATED(message) __declspec(deprecated(message)) -#endif - -#endif // WASMER_H_MACROS - - -#ifndef WASMER_H -#define WASMER_H - -#include -#include -#include -#include - -#define OPCODE_COUNT 448 - -#if defined(WASMER_WASI_ENABLED) -enum Version { - /** - * Version cannot be detected or is unknown. - */ - Unknown = 0, - /** - * Latest version. See `wasmer_wasi::WasiVersion::Latest` to - * learn more. - */ - Latest = 1, - /** - * `wasi_unstable`. - */ - Snapshot0 = 2, - /** - * `wasi_snapshot_preview1`. - */ - Snapshot1 = 3, -}; -typedef uint8_t Version; -#endif - -/** - * List of export/import kinds. - */ -enum wasmer_import_export_kind { - /** - * The export/import is a function. - */ - WASM_FUNCTION = 0, - /** - * The export/import is a global. - */ - WASM_GLOBAL = 1, - /** - * The export/import is a memory. - */ - WASM_MEMORY = 2, - /** - * The export/import is a table. - */ - WASM_TABLE = 3, -}; -typedef uint32_t wasmer_import_export_kind; - -/** - * The `wasmer_result_t` enum is a type that represents either a - * success, or a failure. - */ -typedef enum { - /** - * Represents a success. - */ - WASMER_OK = 1, - /** - * Represents a failure. - */ - WASMER_ERROR = 2, -} wasmer_result_t; - -/** - * Represents all possibles WebAssembly value types. - * - * See `wasmer_value_t` to get a complete example. - */ -enum wasmer_value_tag { - /** - * Represents the `i32` WebAssembly type. - */ - WASM_I32, - /** - * Represents the `i64` WebAssembly type. - */ - WASM_I64, - /** - * Represents the `f32` WebAssembly type. - */ - WASM_F32, - /** - * Represents the `f64` WebAssembly type. - */ - WASM_F64, -}; -typedef uint32_t wasmer_value_tag; - -typedef struct { - -} wasmer_module_t; - -/** - * Opaque pointer to a `wasmer_runtime::Instance` value in Rust. - * - * A `wasmer_runtime::Instance` represents a WebAssembly instance. It - * is generally generated by the `wasmer_instantiate()` function, or by - * the `wasmer_module_instantiate()` function for the most common paths. - */ -typedef struct { - -} wasmer_instance_t; - -typedef struct { - const uint8_t *bytes; - uint32_t bytes_len; -} wasmer_byte_array; - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Type used to construct an import_object_t with Emscripten imports. - */ -typedef struct { - -} wasmer_emscripten_globals_t; -#endif - -typedef struct { - -} wasmer_import_object_t; - -/** - * Opaque pointer to `NamedExportDescriptor`. - */ -typedef struct { - -} wasmer_export_descriptor_t; - -/** - * Opaque pointer to `NamedExportDescriptors`. - */ -typedef struct { - -} wasmer_export_descriptors_t; - -/** - * Opaque pointer to `wasmer_export_t`. - */ -typedef struct { - -} wasmer_export_func_t; - -/** - * Represents a WebAssembly value. - * - * This is a [Rust union][rust-union], which is equivalent to the C - * union. See `wasmer_value_t` to get a complete example. - * - * [rust-union]: https://doc.rust-lang.org/reference/items/unions.html - */ -typedef union { - int32_t I32; - int64_t I64; - float F32; - double F64; -} wasmer_value; - -/** - * Represents a WebAssembly type and value pair, - * i.e. `wasmer_value_tag` and `wasmer_value`. Since the latter is an - * union, it's the safe way to read or write a WebAssembly value in - * C. - * - * Example: - * - * ```c - * // Create a WebAssembly value. - * wasmer_value_t wasm_value = { - * .tag = WASM_I32, - * .value.I32 = 42, - * }; - * - * // Read a WebAssembly value. - * if (wasm_value.tag == WASM_I32) { - * int32_t x = wasm_value.value.I32; - * // … - * } - * ``` - */ -typedef struct { - /** - * The value type. - */ - wasmer_value_tag tag; - /** - * The value. - */ - wasmer_value value; -} wasmer_value_t; - -/** - * Opaque pointer to `NamedExport`. - */ -typedef struct { - -} wasmer_export_t; - -/** - * Opaque pointer to a `wasmer_runtime::Memory` value in Rust. - * - * A `wasmer_runtime::Memory` represents a WebAssembly memory. It is - * possible to create one with `wasmer_memory_new()` and pass it as - * imports of an instance, or to read it from exports of an instance - * with `wasmer_export_to_memory()`. - */ -typedef struct { - -} wasmer_memory_t; - -/** - * Opaque pointer to the opaque structure `crate::NamedExports`, - * which is a wrapper around a vector of the opaque structure - * `crate::NamedExport`. - * - * Check the `wasmer_instance_exports()` function to learn more. - */ -typedef struct { - -} wasmer_exports_t; - -typedef struct { - -} wasmer_global_t; - -typedef struct { - bool mutable_; - wasmer_value_tag kind; -} wasmer_global_descriptor_t; - -typedef struct { - -} wasmer_import_descriptor_t; - -typedef struct { - -} wasmer_import_descriptors_t; - -typedef struct { - -} wasmer_import_func_t; - -typedef struct { - -} wasmer_table_t; - -/** - * Union of import/export value. - */ -typedef union { - const wasmer_import_func_t *func; - const wasmer_table_t *table; - const wasmer_memory_t *memory; - const wasmer_global_t *global; -} wasmer_import_export_value; - -typedef struct { - wasmer_byte_array module_name; - wasmer_byte_array import_name; - wasmer_import_export_kind tag; - wasmer_import_export_value value; -} wasmer_import_t; - -typedef struct { - -} wasmer_import_object_iter_t; - -/** - * Opaque pointer to a `wasmer_runtime::Ctx` value in Rust. - * - * An instance context is passed to any host function (aka imported - * function) as the first argument. It is necessary to read the - * instance data or the memory, respectively with the - * `wasmer_instance_context_data_get()` function, and the - * `wasmer_instance_context_memory()` function. - * - * It is also possible to get the instance context outside a host - * function by using the `wasmer_instance_context_get()` - * function. See also `wasmer_instance_context_data_set()` to set the - * instance context data. - * - * Example: - * - * ```c - * // A host function that prints data from the WebAssembly memory to - * // the standard output. - * void print(wasmer_instance_context_t *context, int32_t pointer, int32_t length) { - * // Use `wasmer_instance_context` to get back the first instance memory. - * const wasmer_memory_t *memory = wasmer_instance_context_memory(context, 0); - * - * // Continue… - * } - * ``` - */ -typedef struct { - -} wasmer_instance_context_t; - -typedef struct { - -} wasmer_compilation_options_t; - -/** - * The `wasmer_limit_option_t` struct represents an optional limit - * for `wasmer_limits_t`. - */ -typedef struct { - /** - * Whether the limit is set. - */ - bool has_some; - /** - * The limit value. - */ - uint32_t some; -} wasmer_limit_option_t; - -/** - * The `wasmer_limits_t` struct is a type that describes a memory - * options. See the `wasmer_memory_t` struct or the - * `wasmer_memory_new()` function to get more information. - */ -typedef struct { - /** - * The minimum number of allowed pages. - */ - uint32_t min; - /** - * The maximum number of allowed pages. - */ - wasmer_limit_option_t max; -} wasmer_limits_t; - -typedef struct { - -} wasmer_serialized_module_t; - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -typedef struct { - -} wasmer_trampoline_buffer_builder_t; -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -typedef struct { - -} wasmer_trampoline_callable_t; -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -typedef struct { - -} wasmer_trampoline_buffer_t; -#endif - -#if defined(WASMER_WASI_ENABLED) -/** - * Opens a directory that's visible to the WASI module as `alias` but - * is backed by the host file at `host_file_path` - */ -typedef struct { - /** - * What the WASI module will see in its virtual root - */ - wasmer_byte_array alias; - /** - * The backing file that the WASI module will interact with via the alias - */ - wasmer_byte_array host_file_path; -} wasmer_wasi_map_dir_entry_t; -#endif - -/** - * Creates a new Module from the given wasm bytes. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_compile(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len); - -/** - * Creates a new Module with gas limit from the given wasm bytes. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len); - -wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len); - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Convenience function for setting up arguments and calling the Emscripten - * main function. - * - * WARNING: - * - * Do not call this function on untrusted code when operating without - * additional sandboxing in place. - * Emscripten has access to many host system calls and therefore may do very - * bad things. - */ -wasmer_result_t wasmer_emscripten_call_main(wasmer_instance_t *instance, - const wasmer_byte_array *args, - unsigned int args_len); -#endif - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Destroy `wasmer_emscrpten_globals_t` created by - * `wasmer_emscripten_get_emscripten_globals`. - */ -void wasmer_emscripten_destroy_globals(wasmer_emscripten_globals_t *globals); -#endif - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Create a `wasmer_import_object_t` with Emscripten imports, use - * `wasmer_emscripten_get_emscripten_globals` to get a - * `wasmer_emscripten_globals_t` from a `wasmer_module_t`. - * - * WARNING: - * - * This `import_object_t` contains thin-wrappers around host system calls. - * Do not use this to execute untrusted code without additional sandboxing. - */ -wasmer_import_object_t *wasmer_emscripten_generate_import_object(wasmer_emscripten_globals_t *globals); -#endif - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Create a `wasmer_emscripten_globals_t` from a Wasm module. - */ -wasmer_emscripten_globals_t *wasmer_emscripten_get_globals(const wasmer_module_t *module); -#endif - -#if defined(WASMER_EMSCRIPTEN_ENABLED) -/** - * Execute global constructors (required if the module is compiled from C++) - * and sets up the internal environment. - * - * This function sets the data pointer in the same way that - * [`wasmer_instance_context_data_set`] does. - */ -wasmer_result_t wasmer_emscripten_set_up(wasmer_instance_t *instance, - wasmer_emscripten_globals_t *globals); -#endif - -/** - * Gets export descriptor kind - */ -wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); - -/** - * Gets name for the export descriptor - */ -wasmer_byte_array wasmer_export_descriptor_name(wasmer_export_descriptor_t *export_descriptor); - -/** - * Gets export descriptors for the given module - * - * The caller owns the object and should call `wasmer_export_descriptors_destroy` to free it. - */ -void wasmer_export_descriptors(const wasmer_module_t *module, - wasmer_export_descriptors_t **export_descriptors); - -/** - * Frees the memory for the given export descriptors - */ -void wasmer_export_descriptors_destroy(wasmer_export_descriptors_t *export_descriptors); - -/** - * Gets export descriptor by index - */ -wasmer_export_descriptor_t *wasmer_export_descriptors_get(wasmer_export_descriptors_t *export_descriptors, - int idx); - -/** - * Gets the length of the export descriptors - */ -int wasmer_export_descriptors_len(wasmer_export_descriptors_t *exports); - -/** - * Calls a `func` with the provided parameters. - * Results are set using the provided `results` pointer. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_func_call(const wasmer_export_func_t *func, - const wasmer_value_t *params, - unsigned int params_len, - wasmer_value_t *results, - unsigned int results_len); - -/** - * Sets the params buffer to the parameter types of the given wasmer_export_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_func_params(const wasmer_export_func_t *func, - wasmer_value_tag *params, - uint32_t params_len); - -/** - * Sets the result parameter to the arity of the params of the wasmer_export_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_func_params_arity(const wasmer_export_func_t *func, uint32_t *result); - -/** - * Sets the returns buffer to the parameter types of the given wasmer_export_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_func_returns(const wasmer_export_func_t *func, - wasmer_value_tag *returns, - uint32_t returns_len); - -/** - * Sets the result parameter to the arity of the returns of the wasmer_export_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_func_returns_arity(const wasmer_export_func_t *func, - uint32_t *result); - -/** - * Gets wasmer_export kind - */ -wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_); - -/** - * Gets name from wasmer_export - */ -wasmer_byte_array wasmer_export_name(wasmer_export_t *export_); - -/** - * Gets export func from export - */ -const wasmer_export_func_t *wasmer_export_to_func(const wasmer_export_t *export_); - -/** - * Gets a memory pointer from an export pointer. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_export_to_memory(const wasmer_export_t *export_, wasmer_memory_t **memory); - -/** - * Frees the memory for the given exports. - * - * Check the `wasmer_instance_exports()` function to get a complete - * example. - * - * If `exports` is a null pointer, this function does nothing. - * - * Example: - * - * ```c - * // Get some exports. - * wasmer_exports_t *exports = NULL; - * wasmer_instance_exports(instance, &exports); - * - * // Destroy the exports. - * wasmer_exports_destroy(exports); - * ``` - */ -void wasmer_exports_destroy(wasmer_exports_t *exports); - -/** - * Gets wasmer_export by index - */ -wasmer_export_t *wasmer_exports_get(wasmer_exports_t *exports, int idx); - -/** - * Gets the length of the exports - */ -int wasmer_exports_len(wasmer_exports_t *exports); - -void wasmer_force_install_sighandlers(void); - -/** - * Frees memory for the given Global - */ -void wasmer_global_destroy(wasmer_global_t *global); - -/** - * Gets the value stored by the given Global - */ -wasmer_value_t wasmer_global_get(wasmer_global_t *global); - -/** - * Returns a descriptor (type, mutability) of the given Global - */ -wasmer_global_descriptor_t wasmer_global_get_descriptor(wasmer_global_t *global); - -/** - * Creates a new Global and returns a pointer to it. - * The caller owns the object and should call `wasmer_global_destroy` to free it. - */ -wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_); - -/** - * Sets the value stored by the given Global - */ -void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value); - -/** - * Gets export descriptor kind - */ -wasmer_import_export_kind wasmer_import_descriptor_kind(wasmer_import_descriptor_t *export_); - -/** - * Gets module name for the import descriptor - */ -wasmer_byte_array wasmer_import_descriptor_module_name(wasmer_import_descriptor_t *import_descriptor); - -/** - * Gets name for the import descriptor - */ -wasmer_byte_array wasmer_import_descriptor_name(wasmer_import_descriptor_t *import_descriptor); - -/** - * Gets import descriptors for the given module - * - * The caller owns the object and should call `wasmer_import_descriptors_destroy` to free it. - */ -void wasmer_import_descriptors(const wasmer_module_t *module, - wasmer_import_descriptors_t **import_descriptors); - -/** - * Frees the memory for the given import descriptors - */ -void wasmer_import_descriptors_destroy(wasmer_import_descriptors_t *import_descriptors); - -/** - * Gets import descriptor by index - */ -wasmer_import_descriptor_t *wasmer_import_descriptors_get(wasmer_import_descriptors_t *import_descriptors, - unsigned int idx); - -/** - * Gets the length of the import descriptors - */ -unsigned int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports); - -/** - * Frees memory for the given Func - */ -void wasmer_import_func_destroy(wasmer_import_func_t *func); - -/** - * Creates new host function, aka imported function. `func` is a - * function pointer, where the first argument is the famous `vm::Ctx` - * (in Rust), or `wasmer_instance_context_t` (in C). All arguments - * must be typed with compatible WebAssembly native types: - * - * | WebAssembly type | C/C++ type | - * | ---------------- | ---------- | - * | `i32` | `int32_t` | - * | `i64` | `int64_t` | - * | `f32` | `float` | - * | `f64` | `double` | - * - * The function pointer must have a lifetime greater than the - * WebAssembly instance lifetime. - * - * The caller owns the object and should call - * `wasmer_import_func_destroy` to free it. - */ -wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data), - const wasmer_value_tag *params, - unsigned int params_len, - const wasmer_value_tag *returns, - unsigned int returns_len); - -/** - * Sets the params buffer to the parameter types of the given wasmer_import_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_import_func_params(const wasmer_import_func_t *func, - wasmer_value_tag *params, - unsigned int params_len); - -/** - * Sets the result parameter to the arity of the params of the wasmer_import_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_import_func_params_arity(const wasmer_import_func_t *func, uint32_t *result); - -/** - * Sets the returns buffer to the parameter types of the given wasmer_import_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func, - wasmer_value_tag *returns, - unsigned int returns_len); - -/** - * Sets the result parameter to the arity of the returns of the wasmer_import_func_t - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *func, - uint32_t *result); - -wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, - unsigned int imports_len); - -/** - * Frees memory of the given ImportObject - */ -void wasmer_import_object_destroy(wasmer_import_object_t *import_object); - -/** - * Extends an existing import object with new imports - */ -wasmer_result_t wasmer_import_object_extend(wasmer_import_object_t *import_object, - const wasmer_import_t *imports, - unsigned int imports_len); - -/** - * Gets an entry from an ImportObject at the name and namespace. - * Stores `name`, `namespace`, and `import_export_value` in `import`. - * Thus these must remain valid for the lifetime of `import`. - * - * The caller owns all data involved. - * `import_export_value` will be written to based on `tag`. - */ -wasmer_result_t wasmer_import_object_get_import(const wasmer_import_object_t *import_object, - wasmer_byte_array namespace_, - wasmer_byte_array name, - wasmer_import_t *import, - wasmer_import_export_value *import_export_value, - uint32_t tag); - -/** - * Frees the memory allocated in `wasmer_import_object_iter_next` - * - * This function does not free the memory in `wasmer_import_object_t`; - * it only frees memory allocated while querying a `wasmer_import_object_t`. - */ -void wasmer_import_object_imports_destroy(wasmer_import_t *imports, uint32_t imports_len); - -/** - * Returns true if further calls to `wasmer_import_object_iter_next` will - * not return any new data - */ -bool wasmer_import_object_iter_at_end(wasmer_import_object_iter_t *import_object_iter); - -/** - * Frees the memory allocated by `wasmer_import_object_iterate_functions` - */ -void wasmer_import_object_iter_destroy(wasmer_import_object_iter_t *import_object_iter); - -/** - * Writes the next value to `import`. `WASMER_ERROR` is returned if there - * was an error or there's nothing left to return. - * - * To free the memory allocated here, pass the import to `wasmer_import_object_imports_destroy`. - * To check if the iterator is done, use `wasmer_import_object_iter_at_end`. - */ -wasmer_result_t wasmer_import_object_iter_next(wasmer_import_object_iter_t *import_object_iter, - wasmer_import_t *import); - -/** - * Create an iterator over the functions in the import object. - * Get the next import with `wasmer_import_object_iter_next` - * Free the iterator with `wasmer_import_object_iter_destroy` - */ -wasmer_import_object_iter_t *wasmer_import_object_iterate_functions(const wasmer_import_object_t *import_object); - -/** - * Creates a new empty import object. - * See also `wasmer_import_object_append` - */ -wasmer_import_object_t *wasmer_import_object_new(void); - -wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, - const uint8_t **cache_bytes, - uint32_t *cache_len); - -/** - * Calls an exported function of a WebAssembly instance by `name` - * with the provided parameters. The exported function results are - * stored on the provided `results` pointer. - * - * This function returns `wasmer_result_t::WASMER_OK` upon success, - * `wasmer_result_t::WASMER_ERROR` otherwise. You can use - * `wasmer_last_error_message()` to get the generated error message. - * - * Potential errors are the following: - * - * * `instance` is a null pointer, - * * `name` is a null pointer, - * * `params` is a null pointer. - * - * Example of calling an exported function that needs two parameters, and returns one value: - * - * ```c - * // First argument. - * wasmer_value_t argument_one = { - * .tag = WASM_I32, - * .value.I32 = 3, - * }; - * - * // Second argument. - * wasmer_value_t argument_two = { - * .tag = WASM_I32, - * .value.I32 = 4, - * }; - * - * // First result. - * wasmer_value_t result_one; - * - * // All arguments and results. - * wasmer_value_t arguments[] = {argument_one, argument_two}; - * wasmer_value_t results[] = {result_one}; - * - * wasmer_result_t call_result = wasmer_instance_call( - * instance, // instance pointer - * "sum", // the exported function name - * arguments, // the arguments - * 2, // the number of arguments - * results, // the results - * 1 // the number of results - * ); - * - * if (call_result == WASMER_OK) { - * printf("Result is: %d\n", results[0].value.I32); - * } - * ``` - */ -wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance, - const char *name, - const wasmer_value_t *params, - uint32_t params_len, - wasmer_value_t *results, - uint32_t results_len); - -/** - * Gets the data that can be hold by an instance. - * - * This function is complementary of - * `wasmer_instance_context_data_set()`. Please read its - * documentation. You can also read the documentation of - * `wasmer_instance_context_t` to get other examples. - * - * This function returns nothing if `ctx` is a null pointer. - */ -void *wasmer_instance_context_data_get(const wasmer_instance_context_t *ctx); - -/** - * Sets the data that can be hold by an instance context. - * - * An instance context (represented by the opaque - * `wasmer_instance_context_t` structure) can hold user-defined - * data. This function sets the data. This function is complementary - * of `wasmer_instance_context_data_get()`. - * - * This function does nothing if `instance` is a null pointer. - * - * Example: - * - * ```c - * // Define your own data. - * typedef struct { - * // … - * } my_data; - * - * // Allocate them and set them on the given instance. - * my_data *data = malloc(sizeof(my_data)); - * data->… = …; - * wasmer_instance_context_data_set(instance, (void*) my_data); - * - * // You can read your data. - * { - * my_data *data = (my_data*) wasmer_instance_context_data_get(wasmer_instance_context_get(instance)); - * // … - * } - * ``` - */ -void wasmer_instance_context_data_set(wasmer_instance_t *instance, - void *data_ptr); - -/** - * Returns the instance context. Learn more by looking at the - * `wasmer_instance_context_t` struct. - * - * This function returns `null` if `instance` is a null pointer. - * - * Example: - * - * ```c - * const wasmer_instance_context_get *context = wasmer_instance_context_get(instance); - * my_data *data = (my_data *) wasmer_instance_context_data_get(context); - * // Do something with `my_data`. - * ``` - * - * It is often useful with `wasmer_instance_context_data_set()`. - */ -const wasmer_instance_context_t *wasmer_instance_context_get(wasmer_instance_t *instance); - -/** - * Gets the `memory_idx`th memory of the instance. - * - * Note that the index is always `0` until multiple memories are supported. - * - * This function is mostly used inside host functions (aka imported - * functions) to read the instance memory. - * - * Example of a _host function_ that reads and prints a string based on a pointer and a length: - * - * ```c - * void print_string(const wasmer_instance_context_t *context, int32_t pointer, int32_t length) { - * // Get the 0th memory. - * const wasmer_memory_t *memory = wasmer_instance_context_memory(context, 0); - * - * // Get the memory data as a pointer. - * uint8_t *memory_bytes = wasmer_memory_data(memory); - * - * // Print what we assumed to be a string! - * printf("%.*s", length, memory_bytes + pointer); - * } - * ``` - */ -const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_context_t *ctx, - uint32_t _memory_idx); - -/** - * Frees memory for the given `wasmer_instance_t`. - * - * Check the `wasmer_instantiate()` function to get a complete - * example. - * - * If `instance` is a null pointer, this function does nothing. - * - * Example: - * - * ```c - * // Get an instance. - * wasmer_instance_t *instance = NULL; - * wasmer_instantiate(&instance, bytes, bytes_length, imports, 0); - * - * // Destroy the instance. - * wasmer_instance_destroy(instance); - * ``` - */ -void wasmer_instance_destroy(wasmer_instance_t *instance); - -void wasmer_instance_disable_rkyv(void); - -void wasmer_instance_enable_rkyv(void); - -/** - * Gets all the exports of the given WebAssembly instance. - * - * This function stores a Rust vector of exports into `exports` as an - * opaque pointer of kind `wasmer_exports_t`. - * - * As is, you can do anything with `exports` except using the - * companion functions, like `wasmer_exports_len()`, - * `wasmer_exports_get()` or `wasmer_export_kind()`. See the example below. - * - * **Warning**: The caller owns the object and should call - * `wasmer_exports_destroy()` to free it. - * - * Example: - * - * ```c - * // Get the exports. - * wasmer_exports_t *exports = NULL; - * wasmer_instance_exports(instance, &exports); - * - * // Get the number of exports. - * int exports_length = wasmer_exports_len(exports); - * printf("Number of exports: %d\n", exports_length); - * - * // Read the first export. - * wasmer_export_t *export = wasmer_exports_get(exports, 0); - * - * // Get the kind of the export. - * wasmer_import_export_kind export_kind = wasmer_export_kind(export); - * - * // Assert it is a function (why not). - * assert(export_kind == WASM_FUNCTION); - * - * // Read the export name. - * wasmer_byte_array name_bytes = wasmer_export_name(export); - * - * assert(name_bytes.bytes_len == sizeof("sum") - 1); - * assert(memcmp(name_bytes.bytes, "sum", sizeof("sum") - 1) == 0); - * - * // Destroy the exports. - * wasmer_exports_destroy(exports); - * ``` - */ -void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); - -wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, - uint8_t *cache_bytes, - uint32_t cache_len, - const wasmer_compilation_options_t *options); - -uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); - -uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); - -/** - * Verifies whether the specified function name is imported by the given instance. - */ -bool wasmer_instance_is_function_imported(wasmer_instance_t *instance, const char *name); - -/** - * Reset an WebAssembly instance, cleaning memories and globals - */ -wasmer_result_t wasmer_instance_reset(wasmer_instance_t *instance); - -void wasmer_instance_set_points_limit(wasmer_instance_t *instance, uint64_t limit); - -void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); - -void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); - -/** - * Creates a new WebAssembly instance from the given bytes and imports. - * - * The result is stored in the first argument `instance` if - * successful, i.e. when the function returns - * `wasmer_result_t::WASMER_OK`. Otherwise - * `wasmer_result_t::WASMER_ERROR` is returned, and - * `wasmer_last_error_length()` with `wasmer_last_error_message()` must - * be used to read the error message. - * - * The caller is responsible to free the instance with - * `wasmer_instance_destroy()`. - * - * Example: - * - * ```c - * // 1. Read a WebAssembly module from a file. - * FILE *file = fopen("sum.wasm", "r"); - * fseek(file, 0, SEEK_END); - * long bytes_length = ftell(file); - * uint8_t *bytes = malloc(bytes_length); - * fseek(file, 0, SEEK_SET); - * fread(bytes, 1, bytes_length, file); - * fclose(file); - * - * // 2. Declare the imports (here, none). - * wasmer_import_t imports[] = {}; - * - * // 3. Instantiate the WebAssembly module. - * wasmer_instance_t *instance = NULL; - * wasmer_result_t result = wasmer_instantiate(&instance, bytes, bytes_length, imports, 0); - * - * // 4. Check for errors. - * if (result != WASMER_OK) { - * int error_length = wasmer_last_error_length(); - * char *error = malloc(error_length); - * wasmer_last_error_message(error, error_length); - * // Do something with `error`… - * } - * - * // 5. Free the memory! - * wasmer_instance_destroy(instance); - * ``` - */ -wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - wasmer_import_t *imports, - int imports_len); - -wasmer_result_t wasmer_instantiate_with_options(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - const wasmer_compilation_options_t *options); - -/** - * Gets the length in bytes of the last error if any. - * - * This can be used to dynamically allocate a buffer with the correct number of - * bytes needed to store a message. - * - * See `wasmer_last_error_message()` to get a full example. - */ -int wasmer_last_error_length(void); - -/** - * Gets the last error message if any into the provided buffer - * `buffer` up to the given `length`. - * - * The `length` parameter must be large enough to store the last - * error message. Ideally, the value should come from - * `wasmer_last_error_length()`. - * - * The function returns the length of the string in bytes, `-1` if an - * error occurs. Potential errors are: - * - * * The buffer is a null pointer, - * * The buffer is too smal to hold the error message. - * - * Note: The error message always has a trailing null character. - * - * Example: - * - * ```c - * int error_length = wasmer_last_error_length(); - * - * if (error_length > 0) { - * char *error_message = malloc(error_length); - * wasmer_last_error_message(error_message, error_length); - * printf("Error message: `%s`\n", error_message); - * } else { - * printf("No error message\n"); - * } - * ``` - */ -int wasmer_last_error_message(char *buffer, int length); - -/** - * Gets a pointer to the beginning of the contiguous memory data - * bytes. - * - * The function returns `NULL` if `memory` is a null pointer. - * - * Note that when the memory grows, it can be reallocated, and thus - * the returned pointer can be invalidated. - * - * Example: - * - * ```c - * uint8_t *memory_data = wasmer_memory_data(memory); - * char *str = (char*) malloc(sizeof(char) * 7); - * - * for (uint32_t nth = 0; nth < 7; ++nth) { - * str[nth] = (char) memory_data[nth]; - * } - * ``` - */ -uint8_t *wasmer_memory_data(const wasmer_memory_t *memory); - -/** - * Gets the size in bytes of the memory data. - * - * This function returns 0 if `memory` is a null pointer. - * - * Example: - * - * ```c - * uint32_t memory_data_length = wasmer_memory_data_length(memory); - * ``` - */ -uint32_t wasmer_memory_data_length(wasmer_memory_t *memory); - -/** - * Frees memory for the given `wasmer_memory_t`. - * - * Check the `wasmer_memory_new()` function to get a complete - * example. - * - * If `memory` is a null pointer, this function does nothing. - * - * Example: - * - * ```c - * // Get a memory. - * wasmer_memory_t *memory = NULL; - * wasmer_result_t result = wasmer_memory_new(&memory, memory_descriptor); - * - * // Destroy the memory. - * wasmer_memory_destroy(memory); - * ``` - */ -void wasmer_memory_destroy(wasmer_memory_t *memory); - -/** - * Grows a memory by the given number of pages (of 65Kb each). - * - * The functions return `wasmer_result_t::WASMER_OK` upon success, - * `wasmer_result_t::WASMER_ERROR` otherwise. Use - * `wasmer_last_error_length()` with `wasmer_last_error_message()` to - * read the error message. - * - * Example: - * - * ```c - * wasmer_result_t result = wasmer_memory_grow(memory, 10); - * - * if (result != WASMER_OK) { - * // … - * } - * ``` - */ -wasmer_result_t wasmer_memory_grow(wasmer_memory_t *memory, uint32_t delta); - -/** - * Reads the current length (in pages) of the given memory. - * - * The function returns zero if `memory` is a null pointer. - * - * Example: - * - * ```c - * uint32_t memory_length = wasmer_memory_length(memory); - * - * printf("Memory pages length: %d\n", memory_length); - * ``` - */ -uint32_t wasmer_memory_length(const wasmer_memory_t *memory); - -/** - * Creates a new empty WebAssembly memory for the given descriptor. - * - * The result is stored in the first argument `memory` if successful, - * i.e. when the function returns - * `wasmer_result_t::WASMER_OK`. Otherwise, - * `wasmer_result_t::WASMER_ERROR` is returned, and - * `wasmer_last_error_length()` with `wasmer_last_error_message()` - * must be used to read the error message. - * - * The caller owns the memory and is responsible to free it with - * `wasmer_memory_destroy()`. - * - * Example: - * - * ```c - * // 1. The memory object. - * wasmer_memory_t *memory = NULL; - * - * // 2. The memory descriptor. - * wasmer_limits_t memory_descriptor = { - * .min = 10, - * .max = { - * .has_some = true, - * .some = 15, - * }, - * }; - * - * // 3. Initialize the memory. - * wasmer_result_t result = wasmer_memory_new(&memory, memory_descriptor); - * - * if (result != WASMER_OK) { - * int error_length = wasmer_last_error_length(); - * char *error = malloc(error_length); - * wasmer_last_error_message(error, error_length); - * // Do something with `error`… - * } - * - * // 4. Free the memory! - * wasmer_memory_destroy(memory); - * ``` - */ -wasmer_result_t wasmer_memory_new(wasmer_memory_t **memory, wasmer_limits_t limits); - -/** - * Deserialize the given serialized module. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_module_deserialize(wasmer_module_t **module, - const wasmer_serialized_module_t *serialized_module); - -/** - * Frees memory for the given Module - */ -void wasmer_module_destroy(wasmer_module_t *module); - -/** - * Given: - * * A prepared `wasmer` import-object - * * A compiled wasmer module - * - * Instantiates a wasmer instance - */ -wasmer_result_t wasmer_module_import_instantiate(wasmer_instance_t **instance, - const wasmer_module_t *module, - const wasmer_import_object_t *import_object); - -/** - * Creates a new Instance from the given module and imports. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_module_instantiate(const wasmer_module_t *module, - wasmer_instance_t **instance, - wasmer_import_t *imports, - int imports_len); - -/** - * Serialize the given Module. - * - * The caller owns the object and should call `wasmer_serialized_module_destroy` to free it. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_module_serialize(wasmer_serialized_module_t **serialized_module, - const wasmer_module_t *module); - -/** - * Get bytes of the serialized module. - */ -wasmer_byte_array wasmer_serialized_module_bytes(const wasmer_serialized_module_t *serialized_module); - -/** - * Frees memory for the given serialized Module. - */ -void wasmer_serialized_module_destroy(wasmer_serialized_module_t *serialized_module); - -/** - * Transform a sequence of bytes into a serialized module. - * - * The caller owns the object and should call `wasmer_serialized_module_destroy` to free it. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_serialized_module_from_bytes(wasmer_serialized_module_t **serialized_module, - const uint8_t *serialized_module_bytes, - uint32_t serialized_module_bytes_length); - -void wasmer_set_opcode_costs(const uint32_t *opcode_costs_pointer); - -void wasmer_set_sigsegv_passthrough(void); - -/** - * Frees memory for the given Table - */ -void wasmer_table_destroy(wasmer_table_t *table); - -/** - * Grows a Table by the given number of elements. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_table_grow(wasmer_table_t *table, uint32_t delta); - -/** - * Returns the current length of the given Table - */ -uint32_t wasmer_table_length(wasmer_table_t *table); - -/** - * Creates a new Table for the given descriptor and initializes the given - * pointer to pointer to a pointer to the new Table. - * - * The caller owns the object and should call `wasmer_table_destroy` to free it. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits); - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Adds a callinfo trampoline to the builder. - */ -uintptr_t wasmer_trampoline_buffer_builder_add_callinfo_trampoline(wasmer_trampoline_buffer_builder_t *builder, - const wasmer_trampoline_callable_t *func, - const void *ctx, - uint32_t num_params); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Adds a context trampoline to the builder. - */ -uintptr_t wasmer_trampoline_buffer_builder_add_context_trampoline(wasmer_trampoline_buffer_builder_t *builder, - const wasmer_trampoline_callable_t *func, - const void *ctx); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Finalizes the trampoline builder into an executable buffer. - */ -wasmer_trampoline_buffer_t *wasmer_trampoline_buffer_builder_build(wasmer_trampoline_buffer_builder_t *builder); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Creates a new trampoline builder. - */ -wasmer_trampoline_buffer_builder_t *wasmer_trampoline_buffer_builder_new(void); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Destroys the trampoline buffer if not null. - */ -void wasmer_trampoline_buffer_destroy(wasmer_trampoline_buffer_t *buffer); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Returns the callable pointer for the trampoline with index `idx`. - */ -const wasmer_trampoline_callable_t *wasmer_trampoline_buffer_get_trampoline(const wasmer_trampoline_buffer_t *buffer, - uintptr_t idx); -#endif - -#if (!defined(_WIN32) && defined(ARCH_X86_64)) -/** - * Returns the context added by `add_context_trampoline`, from within the callee function. - */ -void *wasmer_trampoline_get_context(void); -#endif - -/** - * Stop the execution of a host function, aka imported function. The - * function must be used _only_ inside a host function. - * - * The pointer to `wasmer_instance_context_t` is received by the host - * function as its first argument. Just passing it to `ctx` is fine. - * - * The error message must have a greater lifetime than the host - * function itself since the error is read outside the host function - * with `wasmer_last_error_message`. - * - * This function returns `wasmer_result_t::WASMER_ERROR` if `ctx` or - * `error_message` are null. - * - * This function never returns otherwise. - */ -wasmer_result_t wasmer_trap(const wasmer_instance_context_t *ctx, const char *error_message); - -/** - * Validates a sequence of bytes hoping it represents a valid WebAssembly module. - * - * The function returns true if the bytes are valid, false otherwise. - * - * Example: - * - * ```c - * bool result = wasmer_validate(bytes, bytes_length); - * - * if (false == result) { - * // Do something… - * } - * ``` - */ -bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); - -#if defined(WASMER_WASI_ENABLED) -/** - * Convenience function that creates a WASI import object with no arguments, - * environment variables, preopened files, or mapped directories. - * - * This function is the same as calling [`wasmer_wasi_generate_import_object`] with all - * empty values. - */ -wasmer_import_object_t *wasmer_wasi_generate_default_import_object(void); -#endif - -#if defined(WASMER_WASI_ENABLED) -/** - * Creates a WASI import object. - * - * This function treats null pointers as empty collections. - * For example, passing null for a string in `args`, will lead to a zero - * length argument in that position. - */ -wasmer_import_object_t *wasmer_wasi_generate_import_object(const wasmer_byte_array *args, - unsigned int args_len, - const wasmer_byte_array *envs, - unsigned int envs_len, - const wasmer_byte_array *preopened_files, - unsigned int preopened_files_len, - const wasmer_wasi_map_dir_entry_t *mapped_dirs, - unsigned int mapped_dirs_len); -#endif - -#if defined(WASMER_WASI_ENABLED) -/** - * Creates a WASI import object for a specific version. - * - * This function is similar to `wasmer_wasi_generate_import_object` - * except that the first argument describes the WASI version. - * - * The version is expected to be of kind `Version`. - */ -wasmer_import_object_t *wasmer_wasi_generate_import_object_for_version(unsigned char version, - const wasmer_byte_array *args, - unsigned int args_len, - const wasmer_byte_array *envs, - unsigned int envs_len, - const wasmer_byte_array *preopened_files, - unsigned int preopened_files_len, - const wasmer_wasi_map_dir_entry_t *mapped_dirs, - unsigned int mapped_dirs_len); -#endif - -#if defined(WASMER_WASI_ENABLED) -/** - * Find the version of WASI used by the module. - * - * In case of error, the returned version is `Version::Unknown`. - */ -Version wasmer_wasi_get_version(const wasmer_module_t *module); -#endif - -#endif /* WASMER_H */ diff --git a/wasmer/wasmerExecutor.go b/wasmer/wasmerExecutor.go deleted file mode 100644 index f8ac13c32..000000000 --- a/wasmer/wasmerExecutor.go +++ /dev/null @@ -1,79 +0,0 @@ -package wasmer - -import ( - "unsafe" - - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-go/executor" -) - -var _ executor.Executor = (*WasmerExecutor)(nil) - -// WasmerExecutor oversees the creation of Wasmer instances and execution. -type WasmerExecutor struct { - eiFunctionNames vmcommon.FunctionNames - vmHooks executor.VMHooks - vmHooksPtr uintptr -} - -// CreateExecutor creates a new wasmer executor. -func CreateExecutor() (*WasmerExecutor, error) { - functionNames, err := injectCgoFunctionPointers() - if err != nil { - return nil, err - } - - ForceInstallSighandlers() - - return &WasmerExecutor{ - eiFunctionNames: functionNames, - }, nil -} - -// SetOpcodeCosts sets gas costs globally inside the Wasmer executor. -func (wasmerExecutor *WasmerExecutor) SetOpcodeCosts(opcodeCosts *executor.WASMOpcodeCost) { - SetOpcodeCosts(opcodeCosts) -} - -// FunctionNames returns the function names -func (wasmerExecutor *WasmerExecutor) FunctionNames() vmcommon.FunctionNames { - return wasmerExecutor.eiFunctionNames -} - -// NewInstanceWithOptions creates a new Wasmer instance from WASM bytecode, -// respecting the provided options -func (wasmerExecutor *WasmerExecutor) NewInstanceWithOptions( - contractCode []byte, - options executor.CompilationOptions, -) (executor.Instance, error) { - instance, err := NewInstanceWithOptions(contractCode, options) - if err == nil { - instance.SetVMHooksPtr(wasmerExecutor.vmHooksPtr) - } - - return instance, err -} - -// NewInstanceFromCompiledCodeWithOptions creates a new Wasmer instance from -// precompiled machine code, respecting the provided options -func (wasmerExecutor *WasmerExecutor) NewInstanceFromCompiledCodeWithOptions( - compiledCode []byte, - options executor.CompilationOptions, -) (executor.Instance, error) { - instance, err := NewInstanceFromCompiledCodeWithOptions(compiledCode, options) - if err == nil { - instance.SetVMHooksPtr(wasmerExecutor.vmHooksPtr) - } - return instance, err -} - -// initVMHooks inits the VM hooks -func (wasmerExecutor *WasmerExecutor) initVMHooks(vmHooks executor.VMHooks) { - wasmerExecutor.vmHooks = vmHooks - wasmerExecutor.vmHooksPtr = uintptr(unsafe.Pointer(&wasmerExecutor.vmHooks)) -} - -// IsInterfaceNil returns true if there is no value under the interface -func (wasmerExecutor *WasmerExecutor) IsInterfaceNil() bool { - return wasmerExecutor == nil -} diff --git a/wasmer/wasmerExecutorFactory.go b/wasmer/wasmerExecutorFactory.go deleted file mode 100644 index 70a92dc0c..000000000 --- a/wasmer/wasmerExecutorFactory.go +++ /dev/null @@ -1,38 +0,0 @@ -package wasmer - -import ( - "github.com/multiversx/mx-chain-vm-go/executor" -) - -// WasmerExecutorFactory builds Wasmer Executors. -type WasmerExecutorFactory struct{} - -// ExecutorFactory returns the Wasmer executor factory. -func ExecutorFactory() *WasmerExecutorFactory { - return &WasmerExecutorFactory{} -} - -// CreateExecutor creates a new Executor instance. -func (wef *WasmerExecutorFactory) CreateExecutor(args executor.ExecutorFactoryArgs) (executor.Executor, error) { - if args.WasmerSIGSEGVPassthrough { - SetSIGSEGVPassthrough() - } - - exec, err := CreateExecutor() - if err != nil { - return nil, err - } - exec.initVMHooks(args.VMHooks) - if args.OpcodeCosts != nil { - // opcode costs are sometimes not initialized at this point in certain tests - exec.SetOpcodeCosts(args.OpcodeCosts) - } - - SetRkyvSerializationEnabled(args.RkyvSerializationEnabled) - return exec, nil -} - -// IsInterfaceNil returns true if there is no value under the interface -func (wef *WasmerExecutorFactory) IsInterfaceNil() bool { - return wef == nil -} diff --git a/wasmer/wasmerImport.go b/wasmer/wasmerImport.go deleted file mode 100644 index eedf177f4..000000000 --- a/wasmer/wasmerImport.go +++ /dev/null @@ -1,194 +0,0 @@ -package wasmer - -import ( - "fmt" - "reflect" - "unsafe" - - "github.com/multiversx/mx-chain-vm-go/executor" -) - -// ImportedFunctionError represents any kind of errors related to a -// WebAssembly imported function. It is returned by `Import` or `Imports` -// functions only. -type ImportedFunctionError struct { - functionName string - message string -} - -// NewImportedFunctionError constructs a new `ImportedFunctionError`, -// where `functionName` is the name of the imported function, and -// `message` is the error message. If the error message contains `%s`, -// then this parameter will be replaced by `functionName`. -func NewImportedFunctionError(functionName string, message string) *ImportedFunctionError { - return &ImportedFunctionError{functionName, message} -} - -// ImportedFunctionError is an actual error. The `Error` function -// returns the error message. -func (error *ImportedFunctionError) Error() string { - return fmt.Sprintf(error.message, error.functionName) -} - -// wasmerImport represents an WebAssembly instance imported function. -type wasmerImport struct { - // An implementation must be of type: - // `func(context unsafe.Pointer, arguments ...interface{}) interface{}`. - // It represents the real function implementation written in Go. - implementation interface{} - - // The pointer to the cgo function implementation, something - // like `C.foo`. - cgoPointer unsafe.Pointer - - // The pointer to the Wasmer imported function. - importedFunctionPointer *cWasmerImportFuncT - - // The function implementation signature as a WebAssembly signature. - wasmInputs []cWasmerValueTag - - // The function implementation signature as a WebAssembly signature. - wasmOutputs []cWasmerValueTag - - // The namespace of the imported function. - namespace string -} - -// wasmerImports represents a set of imported functions for a WebAssembly instance. -type wasmerImports struct { - // All imports. - imports map[string]map[string]wasmerImport - - // Current namespace where to register the import. - currentNamespace string -} - -// newWasmerImports constructs a new empty `wasmerImports`. -func newWasmerImports() *wasmerImports { - var imports = make(map[string]map[string]wasmerImport) - var currentNamespace = "env" - - return &wasmerImports{imports, currentNamespace} -} - -// Count returns the number of imports -func (imports *wasmerImports) Count() int { - count := 0 - for _, namespacedImports := range imports.imports { - count += len(namespacedImports) - } - return count -} - -// Append adds a new imported function to the current set. -func (imports *wasmerImports) append(importName string, implementation interface{}, cgoPointer unsafe.Pointer) error { - var importType = reflect.TypeOf(implementation) - - if importType.Kind() != reflect.Func { - return NewImportedFunctionError(importName, fmt.Sprintf("Imported function `%%s` must be a function; given `%s`.", importType.Kind())) - } - - var importInputsArity = importType.NumIn() - - if importInputsArity < 1 { - return NewImportedFunctionError(importName, "Imported function `%s` must at least have one argument for the instance context.") - } - - if importType.In(0).Kind() != reflect.UnsafePointer { - return NewImportedFunctionError(importName, fmt.Sprintf("The instance context of the `%%s` imported function must be of kind `unsafe.Pointer`; given `%s`; is it missing?", importType.In(0).Kind())) - } - - importInputsArity-- - var importOutputsArity = importType.NumOut() - var wasmInputs = make([]cWasmerValueTag, importInputsArity) - var wasmOutputs = make([]cWasmerValueTag, importOutputsArity) - - for nth := 0; nth < importInputsArity; nth++ { - var importInput = importType.In(nth + 1) - - switch importInput.Kind() { - case reflect.Int32: - wasmInputs[nth] = cWasmI32 - case reflect.Int64: - wasmInputs[nth] = cWasmI64 - default: - return NewImportedFunctionError(importName, fmt.Sprintf("Invalid input type for the `%%s` imported function; given `%s`; only accept `int32`, `int64`, `float32`, and `float64`.", importInput.Kind())) - } - } - - if importOutputsArity > 1 { - return NewImportedFunctionError(importName, "The `%s` imported function must have at most one output value.") - } else if importOutputsArity == 1 { - switch importType.Out(0).Kind() { - case reflect.Int32: - wasmOutputs[0] = cWasmI32 - case reflect.Int64: - wasmOutputs[0] = cWasmI64 - default: - return NewImportedFunctionError(importName, fmt.Sprintf("Invalid output type for the `%%s` imported function; given `%s`; only accept `int32`, `int64`, `float32`, and `float64`.", importType.Out(0).Kind())) - } - } - - var importedFunctionPointer *cWasmerImportFuncT - var namespace = imports.currentNamespace - - if imports.imports[namespace] == nil { - imports.imports[namespace] = make(map[string]wasmerImport) - } - - imports.imports[namespace][importName] = wasmerImport{ - implementation, - cgoPointer, - importedFunctionPointer, - wasmInputs, - wasmOutputs, - namespace, - } - - return nil -} - -// Close closes/frees all imported functions that have been registered by Wasmer. -func (imports *wasmerImports) Close() { - for _, namespacedImports := range imports.imports { - for _, importFunction := range namespacedImports { - if nil != importFunction.importedFunctionPointer { - cWasmerImportFuncDestroy(importFunction.importedFunctionPointer) - } - } - } -} - -// InstanceContext represents a way to access instance API from within -// an imported context. -type InstanceContext struct { - context *cWasmerInstanceContextT - memory executor.Memory -} - -// IntoInstanceContext casts the first `context unsafe.Pointer` -// argument of an imported function into an `InstanceContext`. -func IntoInstanceContext(instanceContext unsafe.Pointer) InstanceContext { - context := (*cWasmerInstanceContextT)(instanceContext) - memory := newMemory(cWasmerInstanceContextMemory(context)) - - return InstanceContext{context, &memory} -} - -// IntoInstanceContextDirect retrieves the Wasmer instance context directly -// from the Wasmer instance. This context can be stored as long as the instance itself. -func IntoInstanceContextDirect(instanceContext *cWasmerInstanceContextT) InstanceContext { - memory := newMemory(cWasmerInstanceContextMemory(instanceContext)) - return InstanceContext{instanceContext, &memory} -} - -// Memory returns the current instance memory. -func (instanceContext *InstanceContext) Memory() executor.Memory { - return instanceContext.memory -} - -// Data returns the instance context data as an `unsafe.Pointer`. It's -// up to the user to cast it appropriately as a pointer to a data. -func (instanceContext *InstanceContext) Data() unsafe.Pointer { - return cWasmerInstanceContextDataGet(instanceContext.context) -} diff --git a/wasmer/wasmerImportsCgo.go b/wasmer/wasmerImportsCgo.go deleted file mode 100644 index 2b8a14a64..000000000 --- a/wasmer/wasmerImportsCgo.go +++ /dev/null @@ -1,3218 +0,0 @@ -package wasmer - -// Code generated by vmhooks generator. DO NOT EDIT. - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// // Declare the function signatures (see [cgo](https://golang.org/cmd/cgo/)). -// -// #include -// typedef int int32_t; -// -// extern long long v1_5_getGasLeft(void* context); -// extern void v1_5_getSCAddress(void* context, int32_t resultOffset); -// extern void v1_5_getOwnerAddress(void* context, int32_t resultOffset); -// extern int32_t v1_5_getShardOfAddress(void* context, int32_t addressOffset); -// extern int32_t v1_5_isSmartContract(void* context, int32_t addressOffset); -// extern void v1_5_signalError(void* context, int32_t messageOffset, int32_t messageLength); -// extern void v1_5_getExternalBalance(void* context, int32_t addressOffset, int32_t resultOffset); -// extern int32_t v1_5_getBlockHash(void* context, long long nonce, int32_t resultOffset); -// extern int32_t v1_5_getESDTBalance(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce, int32_t resultOffset); -// extern int32_t v1_5_getESDTNFTNameLength(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce); -// extern int32_t v1_5_getESDTNFTAttributeLength(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce); -// extern int32_t v1_5_getESDTNFTURILength(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce); -// extern int32_t v1_5_getESDTTokenData(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce, int32_t valueHandle, int32_t propertiesOffset, int32_t hashOffset, int32_t nameOffset, int32_t attributesOffset, int32_t creatorOffset, int32_t royaltiesHandle, int32_t urisOffset); -// extern long long v1_5_getESDTLocalRoles(void* context, int32_t tokenIdHandle); -// extern int32_t v1_5_validateTokenIdentifier(void* context, int32_t tokenIdHandle); -// extern int32_t v1_5_transferValue(void* context, int32_t destOffset, int32_t valueOffset, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_transferValueExecute(void* context, int32_t destOffset, int32_t valueOffset, long long gasLimit, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_transferESDTExecute(void* context, int32_t destOffset, int32_t tokenIDOffset, int32_t tokenIDLen, int32_t valueOffset, long long gasLimit, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_transferESDTNFTExecute(void* context, int32_t destOffset, int32_t tokenIDOffset, int32_t tokenIDLen, int32_t valueOffset, long long nonce, long long gasLimit, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_multiTransferESDTNFTExecute(void* context, int32_t destOffset, int32_t numTokenTransfers, int32_t tokenTransfersArgsLengthOffset, int32_t tokenTransferDataOffset, long long gasLimit, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_createAsyncCall(void* context, int32_t destOffset, int32_t valueOffset, int32_t dataOffset, int32_t dataLength, int32_t successOffset, int32_t successLength, int32_t errorOffset, int32_t errorLength, long long gas, long long extraGasForCallback); -// extern int32_t v1_5_setAsyncContextCallback(void* context, int32_t callback, int32_t callbackLength, int32_t data, int32_t dataLength, long long gas); -// extern void v1_5_upgradeContract(void* context, int32_t destOffset, long long gasLimit, int32_t valueOffset, int32_t codeOffset, int32_t codeMetadataOffset, int32_t length, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern void v1_5_upgradeFromSourceContract(void* context, int32_t destOffset, long long gasLimit, int32_t valueOffset, int32_t sourceContractAddressOffset, int32_t codeMetadataOffset, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern void v1_5_deleteContract(void* context, int32_t destOffset, long long gasLimit, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern void v1_5_asyncCall(void* context, int32_t destOffset, int32_t valueOffset, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_getArgumentLength(void* context, int32_t id); -// extern int32_t v1_5_getArgument(void* context, int32_t id, int32_t argOffset); -// extern int32_t v1_5_getFunction(void* context, int32_t functionOffset); -// extern int32_t v1_5_getNumArguments(void* context); -// extern int32_t v1_5_storageStore(void* context, int32_t keyOffset, int32_t keyLength, int32_t dataOffset, int32_t dataLength); -// extern int32_t v1_5_storageLoadLength(void* context, int32_t keyOffset, int32_t keyLength); -// extern int32_t v1_5_storageLoadFromAddress(void* context, int32_t addressOffset, int32_t keyOffset, int32_t keyLength, int32_t dataOffset); -// extern int32_t v1_5_storageLoad(void* context, int32_t keyOffset, int32_t keyLength, int32_t dataOffset); -// extern int32_t v1_5_setStorageLock(void* context, int32_t keyOffset, int32_t keyLength, long long lockTimestamp); -// extern long long v1_5_getStorageLock(void* context, int32_t keyOffset, int32_t keyLength); -// extern int32_t v1_5_isStorageLocked(void* context, int32_t keyOffset, int32_t keyLength); -// extern int32_t v1_5_clearStorageLock(void* context, int32_t keyOffset, int32_t keyLength); -// extern void v1_5_getCaller(void* context, int32_t resultOffset); -// extern void v1_5_checkNoPayment(void* context); -// extern int32_t v1_5_getCallValue(void* context, int32_t resultOffset); -// extern int32_t v1_5_getESDTValue(void* context, int32_t resultOffset); -// extern int32_t v1_5_getESDTValueByIndex(void* context, int32_t resultOffset, int32_t index); -// extern int32_t v1_5_getESDTTokenName(void* context, int32_t resultOffset); -// extern int32_t v1_5_getESDTTokenNameByIndex(void* context, int32_t resultOffset, int32_t index); -// extern long long v1_5_getESDTTokenNonce(void* context); -// extern long long v1_5_getESDTTokenNonceByIndex(void* context, int32_t index); -// extern long long v1_5_getCurrentESDTNFTNonce(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen); -// extern int32_t v1_5_getESDTTokenType(void* context); -// extern int32_t v1_5_getESDTTokenTypeByIndex(void* context, int32_t index); -// extern int32_t v1_5_getNumESDTTransfers(void* context); -// extern int32_t v1_5_getCallValueTokenName(void* context, int32_t callValueOffset, int32_t tokenNameOffset); -// extern int32_t v1_5_getCallValueTokenNameByIndex(void* context, int32_t callValueOffset, int32_t tokenNameOffset, int32_t index); -// extern int32_t v1_5_isReservedFunctionName(void* context, int32_t nameHandle); -// extern void v1_5_writeLog(void* context, int32_t dataPointer, int32_t dataLength, int32_t topicPtr, int32_t numTopics); -// extern void v1_5_writeEventLog(void* context, int32_t numTopics, int32_t topicLengthsOffset, int32_t topicOffset, int32_t dataOffset, int32_t dataLength); -// extern long long v1_5_getBlockTimestamp(void* context); -// extern long long v1_5_getBlockNonce(void* context); -// extern long long v1_5_getBlockRound(void* context); -// extern long long v1_5_getBlockEpoch(void* context); -// extern void v1_5_getBlockRandomSeed(void* context, int32_t pointer); -// extern void v1_5_getStateRootHash(void* context, int32_t pointer); -// extern long long v1_5_getPrevBlockTimestamp(void* context); -// extern long long v1_5_getPrevBlockNonce(void* context); -// extern long long v1_5_getPrevBlockRound(void* context); -// extern long long v1_5_getPrevBlockEpoch(void* context); -// extern void v1_5_getPrevBlockRandomSeed(void* context, int32_t pointer); -// extern void v1_5_finish(void* context, int32_t pointer, int32_t length); -// extern int32_t v1_5_executeOnSameContext(void* context, long long gasLimit, int32_t addressOffset, int32_t valueOffset, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_executeOnDestContext(void* context, long long gasLimit, int32_t addressOffset, int32_t valueOffset, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_executeReadOnly(void* context, long long gasLimit, int32_t addressOffset, int32_t functionOffset, int32_t functionLength, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_createContract(void* context, long long gasLimit, int32_t valueOffset, int32_t codeOffset, int32_t codeMetadataOffset, int32_t length, int32_t resultOffset, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_deployFromSourceContract(void* context, long long gasLimit, int32_t valueOffset, int32_t sourceContractAddressOffset, int32_t codeMetadataOffset, int32_t resultAddressOffset, int32_t numArguments, int32_t argumentsLengthOffset, int32_t dataOffset); -// extern int32_t v1_5_getNumReturnData(void* context); -// extern int32_t v1_5_getReturnDataSize(void* context, int32_t resultID); -// extern int32_t v1_5_getReturnData(void* context, int32_t resultID, int32_t dataOffset); -// extern void v1_5_cleanReturnData(void* context); -// extern void v1_5_deleteFromReturnData(void* context, int32_t resultID); -// extern void v1_5_getOriginalTxHash(void* context, int32_t dataOffset); -// extern void v1_5_getCurrentTxHash(void* context, int32_t dataOffset); -// extern void v1_5_getPrevTxHash(void* context, int32_t dataOffset); -// extern void v1_5_managedSCAddress(void* context, int32_t destinationHandle); -// extern void v1_5_managedOwnerAddress(void* context, int32_t destinationHandle); -// extern void v1_5_managedCaller(void* context, int32_t destinationHandle); -// extern void v1_5_managedGetOriginalCallerAddr(void* context, int32_t destinationHandle); -// extern void v1_5_managedGetRelayerAddr(void* context, int32_t destinationHandle); -// extern void v1_5_managedSignalError(void* context, int32_t errHandle); -// extern void v1_5_managedWriteLog(void* context, int32_t topicsHandle, int32_t dataHandle); -// extern void v1_5_managedGetOriginalTxHash(void* context, int32_t resultHandle); -// extern void v1_5_managedGetStateRootHash(void* context, int32_t resultHandle); -// extern void v1_5_managedGetBlockRandomSeed(void* context, int32_t resultHandle); -// extern void v1_5_managedGetPrevBlockRandomSeed(void* context, int32_t resultHandle); -// extern void v1_5_managedGetReturnData(void* context, int32_t resultID, int32_t resultHandle); -// extern void v1_5_managedGetMultiESDTCallValue(void* context, int32_t multiCallValueHandle); -// extern void v1_5_managedGetBackTransfers(void* context, int32_t esdtTransfersValueHandle, int32_t egldValueHandle); -// extern void v1_5_managedGetESDTBalance(void* context, int32_t addressHandle, int32_t tokenIDHandle, long long nonce, int32_t valueHandle); -// extern void v1_5_managedGetESDTTokenData(void* context, int32_t addressHandle, int32_t tokenIDHandle, long long nonce, int32_t valueHandle, int32_t propertiesHandle, int32_t hashHandle, int32_t nameHandle, int32_t attributesHandle, int32_t creatorHandle, int32_t royaltiesHandle, int32_t urisHandle); -// extern void v1_5_managedAsyncCall(void* context, int32_t destHandle, int32_t valueHandle, int32_t functionHandle, int32_t argumentsHandle); -// extern int32_t v1_5_managedCreateAsyncCall(void* context, int32_t destHandle, int32_t valueHandle, int32_t functionHandle, int32_t argumentsHandle, int32_t successOffset, int32_t successLength, int32_t errorOffset, int32_t errorLength, long long gas, long long extraGasForCallback, int32_t callbackClosureHandle); -// extern void v1_5_managedGetCallbackClosure(void* context, int32_t callbackClosureHandle); -// extern void v1_5_managedUpgradeFromSourceContract(void* context, int32_t destHandle, long long gas, int32_t valueHandle, int32_t addressHandle, int32_t codeMetadataHandle, int32_t argumentsHandle, int32_t resultHandle); -// extern void v1_5_managedUpgradeContract(void* context, int32_t destHandle, long long gas, int32_t valueHandle, int32_t codeHandle, int32_t codeMetadataHandle, int32_t argumentsHandle, int32_t resultHandle); -// extern void v1_5_managedDeleteContract(void* context, int32_t destHandle, long long gasLimit, int32_t argumentsHandle); -// extern int32_t v1_5_managedDeployFromSourceContract(void* context, long long gas, int32_t valueHandle, int32_t addressHandle, int32_t codeMetadataHandle, int32_t argumentsHandle, int32_t resultAddressHandle, int32_t resultHandle); -// extern int32_t v1_5_managedCreateContract(void* context, long long gas, int32_t valueHandle, int32_t codeHandle, int32_t codeMetadataHandle, int32_t argumentsHandle, int32_t resultAddressHandle, int32_t resultHandle); -// extern int32_t v1_5_managedExecuteReadOnly(void* context, long long gas, int32_t addressHandle, int32_t functionHandle, int32_t argumentsHandle, int32_t resultHandle); -// extern int32_t v1_5_managedExecuteOnSameContext(void* context, long long gas, int32_t addressHandle, int32_t valueHandle, int32_t functionHandle, int32_t argumentsHandle, int32_t resultHandle); -// extern int32_t v1_5_managedExecuteOnDestContext(void* context, long long gas, int32_t addressHandle, int32_t valueHandle, int32_t functionHandle, int32_t argumentsHandle, int32_t resultHandle); -// extern int32_t v1_5_managedMultiTransferESDTNFTExecute(void* context, int32_t dstHandle, int32_t tokenTransfersHandle, long long gasLimit, int32_t functionHandle, int32_t argumentsHandle); -// extern int32_t v1_5_managedMultiTransferESDTNFTExecuteByUser(void* context, int32_t userHandle, int32_t dstHandle, int32_t tokenTransfersHandle, long long gasLimit, int32_t functionHandle, int32_t argumentsHandle); -// extern int32_t v1_5_managedTransferValueExecute(void* context, int32_t dstHandle, int32_t valueHandle, long long gasLimit, int32_t functionHandle, int32_t argumentsHandle); -// extern int32_t v1_5_managedIsESDTFrozen(void* context, int32_t addressHandle, int32_t tokenIDHandle, long long nonce); -// extern int32_t v1_5_managedIsESDTLimitedTransfer(void* context, int32_t tokenIDHandle); -// extern int32_t v1_5_managedIsESDTPaused(void* context, int32_t tokenIDHandle); -// extern void v1_5_managedBufferToHex(void* context, int32_t sourceHandle, int32_t destHandle); -// extern void v1_5_managedGetCodeMetadata(void* context, int32_t addressHandle, int32_t responseHandle); -// extern int32_t v1_5_managedIsBuiltinFunction(void* context, int32_t functionNameHandle); -// extern int32_t v1_5_bigFloatNewFromParts(void* context, int32_t integralPart, int32_t fractionalPart, int32_t exponent); -// extern int32_t v1_5_bigFloatNewFromFrac(void* context, long long numerator, long long denominator); -// extern int32_t v1_5_bigFloatNewFromSci(void* context, long long significand, long long exponent); -// extern void v1_5_bigFloatAdd(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigFloatSub(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigFloatMul(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigFloatDiv(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigFloatNeg(void* context, int32_t destinationHandle, int32_t opHandle); -// extern void v1_5_bigFloatClone(void* context, int32_t destinationHandle, int32_t opHandle); -// extern int32_t v1_5_bigFloatCmp(void* context, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigFloatAbs(void* context, int32_t destinationHandle, int32_t opHandle); -// extern int32_t v1_5_bigFloatSign(void* context, int32_t opHandle); -// extern void v1_5_bigFloatSqrt(void* context, int32_t destinationHandle, int32_t opHandle); -// extern void v1_5_bigFloatPow(void* context, int32_t destinationHandle, int32_t opHandle, int32_t exponent); -// extern void v1_5_bigFloatFloor(void* context, int32_t destBigIntHandle, int32_t opHandle); -// extern void v1_5_bigFloatCeil(void* context, int32_t destBigIntHandle, int32_t opHandle); -// extern void v1_5_bigFloatTruncate(void* context, int32_t destBigIntHandle, int32_t opHandle); -// extern void v1_5_bigFloatSetInt64(void* context, int32_t destinationHandle, long long value); -// extern int32_t v1_5_bigFloatIsInt(void* context, int32_t opHandle); -// extern void v1_5_bigFloatSetBigInt(void* context, int32_t destinationHandle, int32_t bigIntHandle); -// extern void v1_5_bigFloatGetConstPi(void* context, int32_t destinationHandle); -// extern void v1_5_bigFloatGetConstE(void* context, int32_t destinationHandle); -// extern void v1_5_bigIntGetUnsignedArgument(void* context, int32_t id, int32_t destinationHandle); -// extern void v1_5_bigIntGetSignedArgument(void* context, int32_t id, int32_t destinationHandle); -// extern int32_t v1_5_bigIntStorageStoreUnsigned(void* context, int32_t keyOffset, int32_t keyLength, int32_t sourceHandle); -// extern int32_t v1_5_bigIntStorageLoadUnsigned(void* context, int32_t keyOffset, int32_t keyLength, int32_t destinationHandle); -// extern void v1_5_bigIntGetCallValue(void* context, int32_t destinationHandle); -// extern void v1_5_bigIntGetESDTCallValue(void* context, int32_t destination); -// extern void v1_5_bigIntGetESDTCallValueByIndex(void* context, int32_t destinationHandle, int32_t index); -// extern void v1_5_bigIntGetExternalBalance(void* context, int32_t addressOffset, int32_t result); -// extern void v1_5_bigIntGetESDTExternalBalance(void* context, int32_t addressOffset, int32_t tokenIDOffset, int32_t tokenIDLen, long long nonce, int32_t resultHandle); -// extern int32_t v1_5_bigIntNew(void* context, long long smallValue); -// extern int32_t v1_5_bigIntUnsignedByteLength(void* context, int32_t referenceHandle); -// extern int32_t v1_5_bigIntSignedByteLength(void* context, int32_t referenceHandle); -// extern int32_t v1_5_bigIntGetUnsignedBytes(void* context, int32_t referenceHandle, int32_t byteOffset); -// extern int32_t v1_5_bigIntGetSignedBytes(void* context, int32_t referenceHandle, int32_t byteOffset); -// extern void v1_5_bigIntSetUnsignedBytes(void* context, int32_t destinationHandle, int32_t byteOffset, int32_t byteLength); -// extern void v1_5_bigIntSetSignedBytes(void* context, int32_t destinationHandle, int32_t byteOffset, int32_t byteLength); -// extern int32_t v1_5_bigIntIsInt64(void* context, int32_t destinationHandle); -// extern long long v1_5_bigIntGetInt64(void* context, int32_t destinationHandle); -// extern void v1_5_bigIntSetInt64(void* context, int32_t destinationHandle, long long value); -// extern void v1_5_bigIntAdd(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntSub(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntMul(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntTDiv(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntTMod(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntEDiv(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntEMod(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntSqrt(void* context, int32_t destinationHandle, int32_t opHandle); -// extern void v1_5_bigIntPow(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern int32_t v1_5_bigIntLog2(void* context, int32_t op1Handle); -// extern void v1_5_bigIntAbs(void* context, int32_t destinationHandle, int32_t opHandle); -// extern void v1_5_bigIntNeg(void* context, int32_t destinationHandle, int32_t opHandle); -// extern int32_t v1_5_bigIntSign(void* context, int32_t opHandle); -// extern int32_t v1_5_bigIntCmp(void* context, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntNot(void* context, int32_t destinationHandle, int32_t opHandle); -// extern void v1_5_bigIntAnd(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntOr(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntXor(void* context, int32_t destinationHandle, int32_t op1Handle, int32_t op2Handle); -// extern void v1_5_bigIntShr(void* context, int32_t destinationHandle, int32_t opHandle, int32_t bits); -// extern void v1_5_bigIntShl(void* context, int32_t destinationHandle, int32_t opHandle, int32_t bits); -// extern void v1_5_bigIntFinishUnsigned(void* context, int32_t referenceHandle); -// extern void v1_5_bigIntFinishSigned(void* context, int32_t referenceHandle); -// extern void v1_5_bigIntToString(void* context, int32_t bigIntHandle, int32_t destinationHandle); -// extern int32_t v1_5_mBufferNew(void* context); -// extern int32_t v1_5_mBufferNewFromBytes(void* context, int32_t dataOffset, int32_t dataLength); -// extern int32_t v1_5_mBufferGetLength(void* context, int32_t mBufferHandle); -// extern int32_t v1_5_mBufferGetBytes(void* context, int32_t mBufferHandle, int32_t resultOffset); -// extern int32_t v1_5_mBufferGetByteSlice(void* context, int32_t sourceHandle, int32_t startingPosition, int32_t sliceLength, int32_t resultOffset); -// extern int32_t v1_5_mBufferCopyByteSlice(void* context, int32_t sourceHandle, int32_t startingPosition, int32_t sliceLength, int32_t destinationHandle); -// extern int32_t v1_5_mBufferEq(void* context, int32_t mBufferHandle1, int32_t mBufferHandle2); -// extern int32_t v1_5_mBufferSetBytes(void* context, int32_t mBufferHandle, int32_t dataOffset, int32_t dataLength); -// extern int32_t v1_5_mBufferSetByteSlice(void* context, int32_t mBufferHandle, int32_t startingPosition, int32_t dataLength, int32_t dataOffset); -// extern int32_t v1_5_mBufferAppend(void* context, int32_t accumulatorHandle, int32_t dataHandle); -// extern int32_t v1_5_mBufferAppendBytes(void* context, int32_t accumulatorHandle, int32_t dataOffset, int32_t dataLength); -// extern int32_t v1_5_mBufferToBigIntUnsigned(void* context, int32_t mBufferHandle, int32_t bigIntHandle); -// extern int32_t v1_5_mBufferToBigIntSigned(void* context, int32_t mBufferHandle, int32_t bigIntHandle); -// extern int32_t v1_5_mBufferFromBigIntUnsigned(void* context, int32_t mBufferHandle, int32_t bigIntHandle); -// extern int32_t v1_5_mBufferFromBigIntSigned(void* context, int32_t mBufferHandle, int32_t bigIntHandle); -// extern long long v1_5_mBufferToSmallIntUnsigned(void* context, int32_t mBufferHandle); -// extern long long v1_5_mBufferToSmallIntSigned(void* context, int32_t mBufferHandle); -// extern void v1_5_mBufferFromSmallIntUnsigned(void* context, int32_t mBufferHandle, long long value); -// extern void v1_5_mBufferFromSmallIntSigned(void* context, int32_t mBufferHandle, long long value); -// extern int32_t v1_5_mBufferToBigFloat(void* context, int32_t mBufferHandle, int32_t bigFloatHandle); -// extern int32_t v1_5_mBufferFromBigFloat(void* context, int32_t mBufferHandle, int32_t bigFloatHandle); -// extern int32_t v1_5_mBufferStorageStore(void* context, int32_t keyHandle, int32_t sourceHandle); -// extern int32_t v1_5_mBufferStorageLoad(void* context, int32_t keyHandle, int32_t destinationHandle); -// extern void v1_5_mBufferStorageLoadFromAddress(void* context, int32_t addressHandle, int32_t keyHandle, int32_t destinationHandle); -// extern int32_t v1_5_mBufferGetArgument(void* context, int32_t id, int32_t destinationHandle); -// extern int32_t v1_5_mBufferFinish(void* context, int32_t sourceHandle); -// extern int32_t v1_5_mBufferSetRandom(void* context, int32_t destinationHandle, int32_t length); -// extern int32_t v1_5_managedMapNew(void* context); -// extern int32_t v1_5_managedMapPut(void* context, int32_t mMapHandle, int32_t keyHandle, int32_t valueHandle); -// extern int32_t v1_5_managedMapGet(void* context, int32_t mMapHandle, int32_t keyHandle, int32_t outValueHandle); -// extern int32_t v1_5_managedMapRemove(void* context, int32_t mMapHandle, int32_t keyHandle, int32_t outValueHandle); -// extern int32_t v1_5_managedMapContains(void* context, int32_t mMapHandle, int32_t keyHandle); -// extern long long v1_5_smallIntGetUnsignedArgument(void* context, int32_t id); -// extern long long v1_5_smallIntGetSignedArgument(void* context, int32_t id); -// extern void v1_5_smallIntFinishUnsigned(void* context, long long value); -// extern void v1_5_smallIntFinishSigned(void* context, long long value); -// extern int32_t v1_5_smallIntStorageStoreUnsigned(void* context, int32_t keyOffset, int32_t keyLength, long long value); -// extern int32_t v1_5_smallIntStorageStoreSigned(void* context, int32_t keyOffset, int32_t keyLength, long long value); -// extern long long v1_5_smallIntStorageLoadUnsigned(void* context, int32_t keyOffset, int32_t keyLength); -// extern long long v1_5_smallIntStorageLoadSigned(void* context, int32_t keyOffset, int32_t keyLength); -// extern long long v1_5_int64getArgument(void* context, int32_t id); -// extern void v1_5_int64finish(void* context, long long value); -// extern int32_t v1_5_int64storageStore(void* context, int32_t keyOffset, int32_t keyLength, long long value); -// extern long long v1_5_int64storageLoad(void* context, int32_t keyOffset, int32_t keyLength); -// extern int32_t v1_5_sha256(void* context, int32_t dataOffset, int32_t length, int32_t resultOffset); -// extern int32_t v1_5_managedSha256(void* context, int32_t inputHandle, int32_t outputHandle); -// extern int32_t v1_5_keccak256(void* context, int32_t dataOffset, int32_t length, int32_t resultOffset); -// extern int32_t v1_5_managedKeccak256(void* context, int32_t inputHandle, int32_t outputHandle); -// extern int32_t v1_5_ripemd160(void* context, int32_t dataOffset, int32_t length, int32_t resultOffset); -// extern int32_t v1_5_managedRipemd160(void* context, int32_t inputHandle, int32_t outputHandle); -// extern int32_t v1_5_verifyBLS(void* context, int32_t keyOffset, int32_t messageOffset, int32_t messageLength, int32_t sigOffset); -// extern int32_t v1_5_managedVerifyBLS(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -// extern int32_t v1_5_verifyEd25519(void* context, int32_t keyOffset, int32_t messageOffset, int32_t messageLength, int32_t sigOffset); -// extern int32_t v1_5_managedVerifyEd25519(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -// extern int32_t v1_5_verifyCustomSecp256k1(void* context, int32_t keyOffset, int32_t keyLength, int32_t messageOffset, int32_t messageLength, int32_t sigOffset, int32_t hashType); -// extern int32_t v1_5_managedVerifyCustomSecp256k1(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle, int32_t hashType); -// extern int32_t v1_5_verifySecp256k1(void* context, int32_t keyOffset, int32_t keyLength, int32_t messageOffset, int32_t messageLength, int32_t sigOffset); -// extern int32_t v1_5_managedVerifySecp256k1(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -// extern int32_t v1_5_encodeSecp256k1DerSignature(void* context, int32_t rOffset, int32_t rLength, int32_t sOffset, int32_t sLength, int32_t sigOffset); -// extern int32_t v1_5_managedEncodeSecp256k1DerSignature(void* context, int32_t rHandle, int32_t sHandle, int32_t sigHandle); -// extern void v1_5_addEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t fstPointXHandle, int32_t fstPointYHandle, int32_t sndPointXHandle, int32_t sndPointYHandle); -// extern void v1_5_doubleEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t pointXHandle, int32_t pointYHandle); -// extern int32_t v1_5_isOnCurveEC(void* context, int32_t ecHandle, int32_t pointXHandle, int32_t pointYHandle); -// extern int32_t v1_5_scalarBaseMultEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_managedScalarBaseMultEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataHandle); -// extern int32_t v1_5_scalarMultEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t pointXHandle, int32_t pointYHandle, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_managedScalarMultEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t pointXHandle, int32_t pointYHandle, int32_t dataHandle); -// extern int32_t v1_5_marshalEC(void* context, int32_t xPairHandle, int32_t yPairHandle, int32_t ecHandle, int32_t resultOffset); -// extern int32_t v1_5_managedMarshalEC(void* context, int32_t xPairHandle, int32_t yPairHandle, int32_t ecHandle, int32_t resultHandle); -// extern int32_t v1_5_marshalCompressedEC(void* context, int32_t xPairHandle, int32_t yPairHandle, int32_t ecHandle, int32_t resultOffset); -// extern int32_t v1_5_managedMarshalCompressedEC(void* context, int32_t xPairHandle, int32_t yPairHandle, int32_t ecHandle, int32_t resultHandle); -// extern int32_t v1_5_unmarshalEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_managedUnmarshalEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataHandle); -// extern int32_t v1_5_unmarshalCompressedEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataOffset, int32_t length); -// extern int32_t v1_5_managedUnmarshalCompressedEC(void* context, int32_t xResultHandle, int32_t yResultHandle, int32_t ecHandle, int32_t dataHandle); -// extern int32_t v1_5_generateKeyEC(void* context, int32_t xPubKeyHandle, int32_t yPubKeyHandle, int32_t ecHandle, int32_t resultOffset); -// extern int32_t v1_5_managedGenerateKeyEC(void* context, int32_t xPubKeyHandle, int32_t yPubKeyHandle, int32_t ecHandle, int32_t resultHandle); -// extern int32_t v1_5_createEC(void* context, int32_t dataOffset, int32_t dataLength); -// extern int32_t v1_5_managedCreateEC(void* context, int32_t dataHandle); -// extern int32_t v1_5_getCurveLengthEC(void* context, int32_t ecHandle); -// extern int32_t v1_5_getPrivKeyByteLengthEC(void* context, int32_t ecHandle); -// extern int32_t v1_5_ellipticCurveGetValues(void* context, int32_t ecHandle, int32_t fieldOrderHandle, int32_t basePointOrderHandle, int32_t eqConstantHandle, int32_t xBasePointHandle, int32_t yBasePointHandle); -// extern int32_t v1_5_managedVerifySecp256r1(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -// extern int32_t v1_5_managedVerifyBLSSignatureShare(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -// extern int32_t v1_5_managedVerifyBLSAggregatedSignature(void* context, int32_t keyHandle, int32_t messageHandle, int32_t sigHandle); -import "C" - -import ( - "unsafe" - - "github.com/multiversx/mx-chain-vm-go/executor" -) - -// populateWasmerImports populates imports with the BaseOpsAPI API methods -func populateWasmerImports(imports *wasmerImports) error { - var err error - err = imports.append("getGasLeft", v1_5_getGasLeft, C.v1_5_getGasLeft) - if err != nil { - return err - } - - err = imports.append("getSCAddress", v1_5_getSCAddress, C.v1_5_getSCAddress) - if err != nil { - return err - } - - err = imports.append("getOwnerAddress", v1_5_getOwnerAddress, C.v1_5_getOwnerAddress) - if err != nil { - return err - } - - err = imports.append("getShardOfAddress", v1_5_getShardOfAddress, C.v1_5_getShardOfAddress) - if err != nil { - return err - } - - err = imports.append("isSmartContract", v1_5_isSmartContract, C.v1_5_isSmartContract) - if err != nil { - return err - } - - err = imports.append("signalError", v1_5_signalError, C.v1_5_signalError) - if err != nil { - return err - } - - err = imports.append("getExternalBalance", v1_5_getExternalBalance, C.v1_5_getExternalBalance) - if err != nil { - return err - } - - err = imports.append("getBlockHash", v1_5_getBlockHash, C.v1_5_getBlockHash) - if err != nil { - return err - } - - err = imports.append("getESDTBalance", v1_5_getESDTBalance, C.v1_5_getESDTBalance) - if err != nil { - return err - } - - err = imports.append("getESDTNFTNameLength", v1_5_getESDTNFTNameLength, C.v1_5_getESDTNFTNameLength) - if err != nil { - return err - } - - err = imports.append("getESDTNFTAttributeLength", v1_5_getESDTNFTAttributeLength, C.v1_5_getESDTNFTAttributeLength) - if err != nil { - return err - } - - err = imports.append("getESDTNFTURILength", v1_5_getESDTNFTURILength, C.v1_5_getESDTNFTURILength) - if err != nil { - return err - } - - err = imports.append("getESDTTokenData", v1_5_getESDTTokenData, C.v1_5_getESDTTokenData) - if err != nil { - return err - } - - err = imports.append("getESDTLocalRoles", v1_5_getESDTLocalRoles, C.v1_5_getESDTLocalRoles) - if err != nil { - return err - } - - err = imports.append("validateTokenIdentifier", v1_5_validateTokenIdentifier, C.v1_5_validateTokenIdentifier) - if err != nil { - return err - } - - err = imports.append("transferValue", v1_5_transferValue, C.v1_5_transferValue) - if err != nil { - return err - } - - err = imports.append("transferValueExecute", v1_5_transferValueExecute, C.v1_5_transferValueExecute) - if err != nil { - return err - } - - err = imports.append("transferESDTExecute", v1_5_transferESDTExecute, C.v1_5_transferESDTExecute) - if err != nil { - return err - } - - err = imports.append("transferESDTNFTExecute", v1_5_transferESDTNFTExecute, C.v1_5_transferESDTNFTExecute) - if err != nil { - return err - } - - err = imports.append("multiTransferESDTNFTExecute", v1_5_multiTransferESDTNFTExecute, C.v1_5_multiTransferESDTNFTExecute) - if err != nil { - return err - } - - err = imports.append("createAsyncCall", v1_5_createAsyncCall, C.v1_5_createAsyncCall) - if err != nil { - return err - } - - err = imports.append("setAsyncContextCallback", v1_5_setAsyncContextCallback, C.v1_5_setAsyncContextCallback) - if err != nil { - return err - } - - err = imports.append("upgradeContract", v1_5_upgradeContract, C.v1_5_upgradeContract) - if err != nil { - return err - } - - err = imports.append("upgradeFromSourceContract", v1_5_upgradeFromSourceContract, C.v1_5_upgradeFromSourceContract) - if err != nil { - return err - } - - err = imports.append("deleteContract", v1_5_deleteContract, C.v1_5_deleteContract) - if err != nil { - return err - } - - err = imports.append("asyncCall", v1_5_asyncCall, C.v1_5_asyncCall) - if err != nil { - return err - } - - err = imports.append("getArgumentLength", v1_5_getArgumentLength, C.v1_5_getArgumentLength) - if err != nil { - return err - } - - err = imports.append("getArgument", v1_5_getArgument, C.v1_5_getArgument) - if err != nil { - return err - } - - err = imports.append("getFunction", v1_5_getFunction, C.v1_5_getFunction) - if err != nil { - return err - } - - err = imports.append("getNumArguments", v1_5_getNumArguments, C.v1_5_getNumArguments) - if err != nil { - return err - } - - err = imports.append("storageStore", v1_5_storageStore, C.v1_5_storageStore) - if err != nil { - return err - } - - err = imports.append("storageLoadLength", v1_5_storageLoadLength, C.v1_5_storageLoadLength) - if err != nil { - return err - } - - err = imports.append("storageLoadFromAddress", v1_5_storageLoadFromAddress, C.v1_5_storageLoadFromAddress) - if err != nil { - return err - } - - err = imports.append("storageLoad", v1_5_storageLoad, C.v1_5_storageLoad) - if err != nil { - return err - } - - err = imports.append("setStorageLock", v1_5_setStorageLock, C.v1_5_setStorageLock) - if err != nil { - return err - } - - err = imports.append("getStorageLock", v1_5_getStorageLock, C.v1_5_getStorageLock) - if err != nil { - return err - } - - err = imports.append("isStorageLocked", v1_5_isStorageLocked, C.v1_5_isStorageLocked) - if err != nil { - return err - } - - err = imports.append("clearStorageLock", v1_5_clearStorageLock, C.v1_5_clearStorageLock) - if err != nil { - return err - } - - err = imports.append("getCaller", v1_5_getCaller, C.v1_5_getCaller) - if err != nil { - return err - } - - err = imports.append("checkNoPayment", v1_5_checkNoPayment, C.v1_5_checkNoPayment) - if err != nil { - return err - } - - err = imports.append("getCallValue", v1_5_getCallValue, C.v1_5_getCallValue) - if err != nil { - return err - } - - err = imports.append("getESDTValue", v1_5_getESDTValue, C.v1_5_getESDTValue) - if err != nil { - return err - } - - err = imports.append("getESDTValueByIndex", v1_5_getESDTValueByIndex, C.v1_5_getESDTValueByIndex) - if err != nil { - return err - } - - err = imports.append("getESDTTokenName", v1_5_getESDTTokenName, C.v1_5_getESDTTokenName) - if err != nil { - return err - } - - err = imports.append("getESDTTokenNameByIndex", v1_5_getESDTTokenNameByIndex, C.v1_5_getESDTTokenNameByIndex) - if err != nil { - return err - } - - err = imports.append("getESDTTokenNonce", v1_5_getESDTTokenNonce, C.v1_5_getESDTTokenNonce) - if err != nil { - return err - } - - err = imports.append("getESDTTokenNonceByIndex", v1_5_getESDTTokenNonceByIndex, C.v1_5_getESDTTokenNonceByIndex) - if err != nil { - return err - } - - err = imports.append("getCurrentESDTNFTNonce", v1_5_getCurrentESDTNFTNonce, C.v1_5_getCurrentESDTNFTNonce) - if err != nil { - return err - } - - err = imports.append("getESDTTokenType", v1_5_getESDTTokenType, C.v1_5_getESDTTokenType) - if err != nil { - return err - } - - err = imports.append("getESDTTokenTypeByIndex", v1_5_getESDTTokenTypeByIndex, C.v1_5_getESDTTokenTypeByIndex) - if err != nil { - return err - } - - err = imports.append("getNumESDTTransfers", v1_5_getNumESDTTransfers, C.v1_5_getNumESDTTransfers) - if err != nil { - return err - } - - err = imports.append("getCallValueTokenName", v1_5_getCallValueTokenName, C.v1_5_getCallValueTokenName) - if err != nil { - return err - } - - err = imports.append("getCallValueTokenNameByIndex", v1_5_getCallValueTokenNameByIndex, C.v1_5_getCallValueTokenNameByIndex) - if err != nil { - return err - } - - err = imports.append("isReservedFunctionName", v1_5_isReservedFunctionName, C.v1_5_isReservedFunctionName) - if err != nil { - return err - } - - err = imports.append("writeLog", v1_5_writeLog, C.v1_5_writeLog) - if err != nil { - return err - } - - err = imports.append("writeEventLog", v1_5_writeEventLog, C.v1_5_writeEventLog) - if err != nil { - return err - } - - err = imports.append("getBlockTimestamp", v1_5_getBlockTimestamp, C.v1_5_getBlockTimestamp) - if err != nil { - return err - } - - err = imports.append("getBlockNonce", v1_5_getBlockNonce, C.v1_5_getBlockNonce) - if err != nil { - return err - } - - err = imports.append("getBlockRound", v1_5_getBlockRound, C.v1_5_getBlockRound) - if err != nil { - return err - } - - err = imports.append("getBlockEpoch", v1_5_getBlockEpoch, C.v1_5_getBlockEpoch) - if err != nil { - return err - } - - err = imports.append("getBlockRandomSeed", v1_5_getBlockRandomSeed, C.v1_5_getBlockRandomSeed) - if err != nil { - return err - } - - err = imports.append("getStateRootHash", v1_5_getStateRootHash, C.v1_5_getStateRootHash) - if err != nil { - return err - } - - err = imports.append("getPrevBlockTimestamp", v1_5_getPrevBlockTimestamp, C.v1_5_getPrevBlockTimestamp) - if err != nil { - return err - } - - err = imports.append("getPrevBlockNonce", v1_5_getPrevBlockNonce, C.v1_5_getPrevBlockNonce) - if err != nil { - return err - } - - err = imports.append("getPrevBlockRound", v1_5_getPrevBlockRound, C.v1_5_getPrevBlockRound) - if err != nil { - return err - } - - err = imports.append("getPrevBlockEpoch", v1_5_getPrevBlockEpoch, C.v1_5_getPrevBlockEpoch) - if err != nil { - return err - } - - err = imports.append("getPrevBlockRandomSeed", v1_5_getPrevBlockRandomSeed, C.v1_5_getPrevBlockRandomSeed) - if err != nil { - return err - } - - err = imports.append("finish", v1_5_finish, C.v1_5_finish) - if err != nil { - return err - } - - err = imports.append("executeOnSameContext", v1_5_executeOnSameContext, C.v1_5_executeOnSameContext) - if err != nil { - return err - } - - err = imports.append("executeOnDestContext", v1_5_executeOnDestContext, C.v1_5_executeOnDestContext) - if err != nil { - return err - } - - err = imports.append("executeReadOnly", v1_5_executeReadOnly, C.v1_5_executeReadOnly) - if err != nil { - return err - } - - err = imports.append("createContract", v1_5_createContract, C.v1_5_createContract) - if err != nil { - return err - } - - err = imports.append("deployFromSourceContract", v1_5_deployFromSourceContract, C.v1_5_deployFromSourceContract) - if err != nil { - return err - } - - err = imports.append("getNumReturnData", v1_5_getNumReturnData, C.v1_5_getNumReturnData) - if err != nil { - return err - } - - err = imports.append("getReturnDataSize", v1_5_getReturnDataSize, C.v1_5_getReturnDataSize) - if err != nil { - return err - } - - err = imports.append("getReturnData", v1_5_getReturnData, C.v1_5_getReturnData) - if err != nil { - return err - } - - err = imports.append("cleanReturnData", v1_5_cleanReturnData, C.v1_5_cleanReturnData) - if err != nil { - return err - } - - err = imports.append("deleteFromReturnData", v1_5_deleteFromReturnData, C.v1_5_deleteFromReturnData) - if err != nil { - return err - } - - err = imports.append("getOriginalTxHash", v1_5_getOriginalTxHash, C.v1_5_getOriginalTxHash) - if err != nil { - return err - } - - err = imports.append("getCurrentTxHash", v1_5_getCurrentTxHash, C.v1_5_getCurrentTxHash) - if err != nil { - return err - } - - err = imports.append("getPrevTxHash", v1_5_getPrevTxHash, C.v1_5_getPrevTxHash) - if err != nil { - return err - } - - err = imports.append("managedSCAddress", v1_5_managedSCAddress, C.v1_5_managedSCAddress) - if err != nil { - return err - } - - err = imports.append("managedOwnerAddress", v1_5_managedOwnerAddress, C.v1_5_managedOwnerAddress) - if err != nil { - return err - } - - err = imports.append("managedCaller", v1_5_managedCaller, C.v1_5_managedCaller) - if err != nil { - return err - } - - err = imports.append("managedGetOriginalCallerAddr", v1_5_managedGetOriginalCallerAddr, C.v1_5_managedGetOriginalCallerAddr) - if err != nil { - return err - } - - err = imports.append("managedGetRelayerAddr", v1_5_managedGetRelayerAddr, C.v1_5_managedGetRelayerAddr) - if err != nil { - return err - } - - err = imports.append("managedSignalError", v1_5_managedSignalError, C.v1_5_managedSignalError) - if err != nil { - return err - } - - err = imports.append("managedWriteLog", v1_5_managedWriteLog, C.v1_5_managedWriteLog) - if err != nil { - return err - } - - err = imports.append("managedGetOriginalTxHash", v1_5_managedGetOriginalTxHash, C.v1_5_managedGetOriginalTxHash) - if err != nil { - return err - } - - err = imports.append("managedGetStateRootHash", v1_5_managedGetStateRootHash, C.v1_5_managedGetStateRootHash) - if err != nil { - return err - } - - err = imports.append("managedGetBlockRandomSeed", v1_5_managedGetBlockRandomSeed, C.v1_5_managedGetBlockRandomSeed) - if err != nil { - return err - } - - err = imports.append("managedGetPrevBlockRandomSeed", v1_5_managedGetPrevBlockRandomSeed, C.v1_5_managedGetPrevBlockRandomSeed) - if err != nil { - return err - } - - err = imports.append("managedGetReturnData", v1_5_managedGetReturnData, C.v1_5_managedGetReturnData) - if err != nil { - return err - } - - err = imports.append("managedGetMultiESDTCallValue", v1_5_managedGetMultiESDTCallValue, C.v1_5_managedGetMultiESDTCallValue) - if err != nil { - return err - } - - err = imports.append("managedGetBackTransfers", v1_5_managedGetBackTransfers, C.v1_5_managedGetBackTransfers) - if err != nil { - return err - } - - err = imports.append("managedGetESDTBalance", v1_5_managedGetESDTBalance, C.v1_5_managedGetESDTBalance) - if err != nil { - return err - } - - err = imports.append("managedGetESDTTokenData", v1_5_managedGetESDTTokenData, C.v1_5_managedGetESDTTokenData) - if err != nil { - return err - } - - err = imports.append("managedAsyncCall", v1_5_managedAsyncCall, C.v1_5_managedAsyncCall) - if err != nil { - return err - } - - err = imports.append("managedCreateAsyncCall", v1_5_managedCreateAsyncCall, C.v1_5_managedCreateAsyncCall) - if err != nil { - return err - } - - err = imports.append("managedGetCallbackClosure", v1_5_managedGetCallbackClosure, C.v1_5_managedGetCallbackClosure) - if err != nil { - return err - } - - err = imports.append("managedUpgradeFromSourceContract", v1_5_managedUpgradeFromSourceContract, C.v1_5_managedUpgradeFromSourceContract) - if err != nil { - return err - } - - err = imports.append("managedUpgradeContract", v1_5_managedUpgradeContract, C.v1_5_managedUpgradeContract) - if err != nil { - return err - } - - err = imports.append("managedDeleteContract", v1_5_managedDeleteContract, C.v1_5_managedDeleteContract) - if err != nil { - return err - } - - err = imports.append("managedDeployFromSourceContract", v1_5_managedDeployFromSourceContract, C.v1_5_managedDeployFromSourceContract) - if err != nil { - return err - } - - err = imports.append("managedCreateContract", v1_5_managedCreateContract, C.v1_5_managedCreateContract) - if err != nil { - return err - } - - err = imports.append("managedExecuteReadOnly", v1_5_managedExecuteReadOnly, C.v1_5_managedExecuteReadOnly) - if err != nil { - return err - } - - err = imports.append("managedExecuteOnSameContext", v1_5_managedExecuteOnSameContext, C.v1_5_managedExecuteOnSameContext) - if err != nil { - return err - } - - err = imports.append("managedExecuteOnDestContext", v1_5_managedExecuteOnDestContext, C.v1_5_managedExecuteOnDestContext) - if err != nil { - return err - } - - err = imports.append("managedMultiTransferESDTNFTExecute", v1_5_managedMultiTransferESDTNFTExecute, C.v1_5_managedMultiTransferESDTNFTExecute) - if err != nil { - return err - } - - err = imports.append("managedMultiTransferESDTNFTExecuteByUser", v1_5_managedMultiTransferESDTNFTExecuteByUser, C.v1_5_managedMultiTransferESDTNFTExecuteByUser) - if err != nil { - return err - } - - err = imports.append("managedTransferValueExecute", v1_5_managedTransferValueExecute, C.v1_5_managedTransferValueExecute) - if err != nil { - return err - } - - err = imports.append("managedIsESDTFrozen", v1_5_managedIsESDTFrozen, C.v1_5_managedIsESDTFrozen) - if err != nil { - return err - } - - err = imports.append("managedIsESDTLimitedTransfer", v1_5_managedIsESDTLimitedTransfer, C.v1_5_managedIsESDTLimitedTransfer) - if err != nil { - return err - } - - err = imports.append("managedIsESDTPaused", v1_5_managedIsESDTPaused, C.v1_5_managedIsESDTPaused) - if err != nil { - return err - } - - err = imports.append("managedBufferToHex", v1_5_managedBufferToHex, C.v1_5_managedBufferToHex) - if err != nil { - return err - } - - err = imports.append("managedGetCodeMetadata", v1_5_managedGetCodeMetadata, C.v1_5_managedGetCodeMetadata) - if err != nil { - return err - } - - err = imports.append("managedIsBuiltinFunction", v1_5_managedIsBuiltinFunction, C.v1_5_managedIsBuiltinFunction) - if err != nil { - return err - } - - err = imports.append("bigFloatNewFromParts", v1_5_bigFloatNewFromParts, C.v1_5_bigFloatNewFromParts) - if err != nil { - return err - } - - err = imports.append("bigFloatNewFromFrac", v1_5_bigFloatNewFromFrac, C.v1_5_bigFloatNewFromFrac) - if err != nil { - return err - } - - err = imports.append("bigFloatNewFromSci", v1_5_bigFloatNewFromSci, C.v1_5_bigFloatNewFromSci) - if err != nil { - return err - } - - err = imports.append("bigFloatAdd", v1_5_bigFloatAdd, C.v1_5_bigFloatAdd) - if err != nil { - return err - } - - err = imports.append("bigFloatSub", v1_5_bigFloatSub, C.v1_5_bigFloatSub) - if err != nil { - return err - } - - err = imports.append("bigFloatMul", v1_5_bigFloatMul, C.v1_5_bigFloatMul) - if err != nil { - return err - } - - err = imports.append("bigFloatDiv", v1_5_bigFloatDiv, C.v1_5_bigFloatDiv) - if err != nil { - return err - } - - err = imports.append("bigFloatNeg", v1_5_bigFloatNeg, C.v1_5_bigFloatNeg) - if err != nil { - return err - } - - err = imports.append("bigFloatClone", v1_5_bigFloatClone, C.v1_5_bigFloatClone) - if err != nil { - return err - } - - err = imports.append("bigFloatCmp", v1_5_bigFloatCmp, C.v1_5_bigFloatCmp) - if err != nil { - return err - } - - err = imports.append("bigFloatAbs", v1_5_bigFloatAbs, C.v1_5_bigFloatAbs) - if err != nil { - return err - } - - err = imports.append("bigFloatSign", v1_5_bigFloatSign, C.v1_5_bigFloatSign) - if err != nil { - return err - } - - err = imports.append("bigFloatSqrt", v1_5_bigFloatSqrt, C.v1_5_bigFloatSqrt) - if err != nil { - return err - } - - err = imports.append("bigFloatPow", v1_5_bigFloatPow, C.v1_5_bigFloatPow) - if err != nil { - return err - } - - err = imports.append("bigFloatFloor", v1_5_bigFloatFloor, C.v1_5_bigFloatFloor) - if err != nil { - return err - } - - err = imports.append("bigFloatCeil", v1_5_bigFloatCeil, C.v1_5_bigFloatCeil) - if err != nil { - return err - } - - err = imports.append("bigFloatTruncate", v1_5_bigFloatTruncate, C.v1_5_bigFloatTruncate) - if err != nil { - return err - } - - err = imports.append("bigFloatSetInt64", v1_5_bigFloatSetInt64, C.v1_5_bigFloatSetInt64) - if err != nil { - return err - } - - err = imports.append("bigFloatIsInt", v1_5_bigFloatIsInt, C.v1_5_bigFloatIsInt) - if err != nil { - return err - } - - err = imports.append("bigFloatSetBigInt", v1_5_bigFloatSetBigInt, C.v1_5_bigFloatSetBigInt) - if err != nil { - return err - } - - err = imports.append("bigFloatGetConstPi", v1_5_bigFloatGetConstPi, C.v1_5_bigFloatGetConstPi) - if err != nil { - return err - } - - err = imports.append("bigFloatGetConstE", v1_5_bigFloatGetConstE, C.v1_5_bigFloatGetConstE) - if err != nil { - return err - } - - err = imports.append("bigIntGetUnsignedArgument", v1_5_bigIntGetUnsignedArgument, C.v1_5_bigIntGetUnsignedArgument) - if err != nil { - return err - } - - err = imports.append("bigIntGetSignedArgument", v1_5_bigIntGetSignedArgument, C.v1_5_bigIntGetSignedArgument) - if err != nil { - return err - } - - err = imports.append("bigIntStorageStoreUnsigned", v1_5_bigIntStorageStoreUnsigned, C.v1_5_bigIntStorageStoreUnsigned) - if err != nil { - return err - } - - err = imports.append("bigIntStorageLoadUnsigned", v1_5_bigIntStorageLoadUnsigned, C.v1_5_bigIntStorageLoadUnsigned) - if err != nil { - return err - } - - err = imports.append("bigIntGetCallValue", v1_5_bigIntGetCallValue, C.v1_5_bigIntGetCallValue) - if err != nil { - return err - } - - err = imports.append("bigIntGetESDTCallValue", v1_5_bigIntGetESDTCallValue, C.v1_5_bigIntGetESDTCallValue) - if err != nil { - return err - } - - err = imports.append("bigIntGetESDTCallValueByIndex", v1_5_bigIntGetESDTCallValueByIndex, C.v1_5_bigIntGetESDTCallValueByIndex) - if err != nil { - return err - } - - err = imports.append("bigIntGetExternalBalance", v1_5_bigIntGetExternalBalance, C.v1_5_bigIntGetExternalBalance) - if err != nil { - return err - } - - err = imports.append("bigIntGetESDTExternalBalance", v1_5_bigIntGetESDTExternalBalance, C.v1_5_bigIntGetESDTExternalBalance) - if err != nil { - return err - } - - err = imports.append("bigIntNew", v1_5_bigIntNew, C.v1_5_bigIntNew) - if err != nil { - return err - } - - err = imports.append("bigIntUnsignedByteLength", v1_5_bigIntUnsignedByteLength, C.v1_5_bigIntUnsignedByteLength) - if err != nil { - return err - } - - err = imports.append("bigIntSignedByteLength", v1_5_bigIntSignedByteLength, C.v1_5_bigIntSignedByteLength) - if err != nil { - return err - } - - err = imports.append("bigIntGetUnsignedBytes", v1_5_bigIntGetUnsignedBytes, C.v1_5_bigIntGetUnsignedBytes) - if err != nil { - return err - } - - err = imports.append("bigIntGetSignedBytes", v1_5_bigIntGetSignedBytes, C.v1_5_bigIntGetSignedBytes) - if err != nil { - return err - } - - err = imports.append("bigIntSetUnsignedBytes", v1_5_bigIntSetUnsignedBytes, C.v1_5_bigIntSetUnsignedBytes) - if err != nil { - return err - } - - err = imports.append("bigIntSetSignedBytes", v1_5_bigIntSetSignedBytes, C.v1_5_bigIntSetSignedBytes) - if err != nil { - return err - } - - err = imports.append("bigIntIsInt64", v1_5_bigIntIsInt64, C.v1_5_bigIntIsInt64) - if err != nil { - return err - } - - err = imports.append("bigIntGetInt64", v1_5_bigIntGetInt64, C.v1_5_bigIntGetInt64) - if err != nil { - return err - } - - err = imports.append("bigIntSetInt64", v1_5_bigIntSetInt64, C.v1_5_bigIntSetInt64) - if err != nil { - return err - } - - err = imports.append("bigIntAdd", v1_5_bigIntAdd, C.v1_5_bigIntAdd) - if err != nil { - return err - } - - err = imports.append("bigIntSub", v1_5_bigIntSub, C.v1_5_bigIntSub) - if err != nil { - return err - } - - err = imports.append("bigIntMul", v1_5_bigIntMul, C.v1_5_bigIntMul) - if err != nil { - return err - } - - err = imports.append("bigIntTDiv", v1_5_bigIntTDiv, C.v1_5_bigIntTDiv) - if err != nil { - return err - } - - err = imports.append("bigIntTMod", v1_5_bigIntTMod, C.v1_5_bigIntTMod) - if err != nil { - return err - } - - err = imports.append("bigIntEDiv", v1_5_bigIntEDiv, C.v1_5_bigIntEDiv) - if err != nil { - return err - } - - err = imports.append("bigIntEMod", v1_5_bigIntEMod, C.v1_5_bigIntEMod) - if err != nil { - return err - } - - err = imports.append("bigIntSqrt", v1_5_bigIntSqrt, C.v1_5_bigIntSqrt) - if err != nil { - return err - } - - err = imports.append("bigIntPow", v1_5_bigIntPow, C.v1_5_bigIntPow) - if err != nil { - return err - } - - err = imports.append("bigIntLog2", v1_5_bigIntLog2, C.v1_5_bigIntLog2) - if err != nil { - return err - } - - err = imports.append("bigIntAbs", v1_5_bigIntAbs, C.v1_5_bigIntAbs) - if err != nil { - return err - } - - err = imports.append("bigIntNeg", v1_5_bigIntNeg, C.v1_5_bigIntNeg) - if err != nil { - return err - } - - err = imports.append("bigIntSign", v1_5_bigIntSign, C.v1_5_bigIntSign) - if err != nil { - return err - } - - err = imports.append("bigIntCmp", v1_5_bigIntCmp, C.v1_5_bigIntCmp) - if err != nil { - return err - } - - err = imports.append("bigIntNot", v1_5_bigIntNot, C.v1_5_bigIntNot) - if err != nil { - return err - } - - err = imports.append("bigIntAnd", v1_5_bigIntAnd, C.v1_5_bigIntAnd) - if err != nil { - return err - } - - err = imports.append("bigIntOr", v1_5_bigIntOr, C.v1_5_bigIntOr) - if err != nil { - return err - } - - err = imports.append("bigIntXor", v1_5_bigIntXor, C.v1_5_bigIntXor) - if err != nil { - return err - } - - err = imports.append("bigIntShr", v1_5_bigIntShr, C.v1_5_bigIntShr) - if err != nil { - return err - } - - err = imports.append("bigIntShl", v1_5_bigIntShl, C.v1_5_bigIntShl) - if err != nil { - return err - } - - err = imports.append("bigIntFinishUnsigned", v1_5_bigIntFinishUnsigned, C.v1_5_bigIntFinishUnsigned) - if err != nil { - return err - } - - err = imports.append("bigIntFinishSigned", v1_5_bigIntFinishSigned, C.v1_5_bigIntFinishSigned) - if err != nil { - return err - } - - err = imports.append("bigIntToString", v1_5_bigIntToString, C.v1_5_bigIntToString) - if err != nil { - return err - } - - err = imports.append("mBufferNew", v1_5_mBufferNew, C.v1_5_mBufferNew) - if err != nil { - return err - } - - err = imports.append("mBufferNewFromBytes", v1_5_mBufferNewFromBytes, C.v1_5_mBufferNewFromBytes) - if err != nil { - return err - } - - err = imports.append("mBufferGetLength", v1_5_mBufferGetLength, C.v1_5_mBufferGetLength) - if err != nil { - return err - } - - err = imports.append("mBufferGetBytes", v1_5_mBufferGetBytes, C.v1_5_mBufferGetBytes) - if err != nil { - return err - } - - err = imports.append("mBufferGetByteSlice", v1_5_mBufferGetByteSlice, C.v1_5_mBufferGetByteSlice) - if err != nil { - return err - } - - err = imports.append("mBufferCopyByteSlice", v1_5_mBufferCopyByteSlice, C.v1_5_mBufferCopyByteSlice) - if err != nil { - return err - } - - err = imports.append("mBufferEq", v1_5_mBufferEq, C.v1_5_mBufferEq) - if err != nil { - return err - } - - err = imports.append("mBufferSetBytes", v1_5_mBufferSetBytes, C.v1_5_mBufferSetBytes) - if err != nil { - return err - } - - err = imports.append("mBufferSetByteSlice", v1_5_mBufferSetByteSlice, C.v1_5_mBufferSetByteSlice) - if err != nil { - return err - } - - err = imports.append("mBufferAppend", v1_5_mBufferAppend, C.v1_5_mBufferAppend) - if err != nil { - return err - } - - err = imports.append("mBufferAppendBytes", v1_5_mBufferAppendBytes, C.v1_5_mBufferAppendBytes) - if err != nil { - return err - } - - err = imports.append("mBufferToBigIntUnsigned", v1_5_mBufferToBigIntUnsigned, C.v1_5_mBufferToBigIntUnsigned) - if err != nil { - return err - } - - err = imports.append("mBufferToBigIntSigned", v1_5_mBufferToBigIntSigned, C.v1_5_mBufferToBigIntSigned) - if err != nil { - return err - } - - err = imports.append("mBufferFromBigIntUnsigned", v1_5_mBufferFromBigIntUnsigned, C.v1_5_mBufferFromBigIntUnsigned) - if err != nil { - return err - } - - err = imports.append("mBufferFromBigIntSigned", v1_5_mBufferFromBigIntSigned, C.v1_5_mBufferFromBigIntSigned) - if err != nil { - return err - } - - err = imports.append("mBufferToSmallIntUnsigned", v1_5_mBufferToSmallIntUnsigned, C.v1_5_mBufferToSmallIntUnsigned) - if err != nil { - return err - } - - err = imports.append("mBufferToSmallIntSigned", v1_5_mBufferToSmallIntSigned, C.v1_5_mBufferToSmallIntSigned) - if err != nil { - return err - } - - err = imports.append("mBufferFromSmallIntUnsigned", v1_5_mBufferFromSmallIntUnsigned, C.v1_5_mBufferFromSmallIntUnsigned) - if err != nil { - return err - } - - err = imports.append("mBufferFromSmallIntSigned", v1_5_mBufferFromSmallIntSigned, C.v1_5_mBufferFromSmallIntSigned) - if err != nil { - return err - } - - err = imports.append("mBufferToBigFloat", v1_5_mBufferToBigFloat, C.v1_5_mBufferToBigFloat) - if err != nil { - return err - } - - err = imports.append("mBufferFromBigFloat", v1_5_mBufferFromBigFloat, C.v1_5_mBufferFromBigFloat) - if err != nil { - return err - } - - err = imports.append("mBufferStorageStore", v1_5_mBufferStorageStore, C.v1_5_mBufferStorageStore) - if err != nil { - return err - } - - err = imports.append("mBufferStorageLoad", v1_5_mBufferStorageLoad, C.v1_5_mBufferStorageLoad) - if err != nil { - return err - } - - err = imports.append("mBufferStorageLoadFromAddress", v1_5_mBufferStorageLoadFromAddress, C.v1_5_mBufferStorageLoadFromAddress) - if err != nil { - return err - } - - err = imports.append("mBufferGetArgument", v1_5_mBufferGetArgument, C.v1_5_mBufferGetArgument) - if err != nil { - return err - } - - err = imports.append("mBufferFinish", v1_5_mBufferFinish, C.v1_5_mBufferFinish) - if err != nil { - return err - } - - err = imports.append("mBufferSetRandom", v1_5_mBufferSetRandom, C.v1_5_mBufferSetRandom) - if err != nil { - return err - } - - err = imports.append("managedMapNew", v1_5_managedMapNew, C.v1_5_managedMapNew) - if err != nil { - return err - } - - err = imports.append("managedMapPut", v1_5_managedMapPut, C.v1_5_managedMapPut) - if err != nil { - return err - } - - err = imports.append("managedMapGet", v1_5_managedMapGet, C.v1_5_managedMapGet) - if err != nil { - return err - } - - err = imports.append("managedMapRemove", v1_5_managedMapRemove, C.v1_5_managedMapRemove) - if err != nil { - return err - } - - err = imports.append("managedMapContains", v1_5_managedMapContains, C.v1_5_managedMapContains) - if err != nil { - return err - } - - err = imports.append("smallIntGetUnsignedArgument", v1_5_smallIntGetUnsignedArgument, C.v1_5_smallIntGetUnsignedArgument) - if err != nil { - return err - } - - err = imports.append("smallIntGetSignedArgument", v1_5_smallIntGetSignedArgument, C.v1_5_smallIntGetSignedArgument) - if err != nil { - return err - } - - err = imports.append("smallIntFinishUnsigned", v1_5_smallIntFinishUnsigned, C.v1_5_smallIntFinishUnsigned) - if err != nil { - return err - } - - err = imports.append("smallIntFinishSigned", v1_5_smallIntFinishSigned, C.v1_5_smallIntFinishSigned) - if err != nil { - return err - } - - err = imports.append("smallIntStorageStoreUnsigned", v1_5_smallIntStorageStoreUnsigned, C.v1_5_smallIntStorageStoreUnsigned) - if err != nil { - return err - } - - err = imports.append("smallIntStorageStoreSigned", v1_5_smallIntStorageStoreSigned, C.v1_5_smallIntStorageStoreSigned) - if err != nil { - return err - } - - err = imports.append("smallIntStorageLoadUnsigned", v1_5_smallIntStorageLoadUnsigned, C.v1_5_smallIntStorageLoadUnsigned) - if err != nil { - return err - } - - err = imports.append("smallIntStorageLoadSigned", v1_5_smallIntStorageLoadSigned, C.v1_5_smallIntStorageLoadSigned) - if err != nil { - return err - } - - err = imports.append("int64getArgument", v1_5_int64getArgument, C.v1_5_int64getArgument) - if err != nil { - return err - } - - err = imports.append("int64finish", v1_5_int64finish, C.v1_5_int64finish) - if err != nil { - return err - } - - err = imports.append("int64storageStore", v1_5_int64storageStore, C.v1_5_int64storageStore) - if err != nil { - return err - } - - err = imports.append("int64storageLoad", v1_5_int64storageLoad, C.v1_5_int64storageLoad) - if err != nil { - return err - } - - err = imports.append("sha256", v1_5_sha256, C.v1_5_sha256) - if err != nil { - return err - } - - err = imports.append("managedSha256", v1_5_managedSha256, C.v1_5_managedSha256) - if err != nil { - return err - } - - err = imports.append("keccak256", v1_5_keccak256, C.v1_5_keccak256) - if err != nil { - return err - } - - err = imports.append("managedKeccak256", v1_5_managedKeccak256, C.v1_5_managedKeccak256) - if err != nil { - return err - } - - err = imports.append("ripemd160", v1_5_ripemd160, C.v1_5_ripemd160) - if err != nil { - return err - } - - err = imports.append("managedRipemd160", v1_5_managedRipemd160, C.v1_5_managedRipemd160) - if err != nil { - return err - } - - err = imports.append("verifyBLS", v1_5_verifyBLS, C.v1_5_verifyBLS) - if err != nil { - return err - } - - err = imports.append("managedVerifyBLS", v1_5_managedVerifyBLS, C.v1_5_managedVerifyBLS) - if err != nil { - return err - } - - err = imports.append("verifyEd25519", v1_5_verifyEd25519, C.v1_5_verifyEd25519) - if err != nil { - return err - } - - err = imports.append("managedVerifyEd25519", v1_5_managedVerifyEd25519, C.v1_5_managedVerifyEd25519) - if err != nil { - return err - } - - err = imports.append("verifyCustomSecp256k1", v1_5_verifyCustomSecp256k1, C.v1_5_verifyCustomSecp256k1) - if err != nil { - return err - } - - err = imports.append("managedVerifyCustomSecp256k1", v1_5_managedVerifyCustomSecp256k1, C.v1_5_managedVerifyCustomSecp256k1) - if err != nil { - return err - } - - err = imports.append("verifySecp256k1", v1_5_verifySecp256k1, C.v1_5_verifySecp256k1) - if err != nil { - return err - } - - err = imports.append("managedVerifySecp256k1", v1_5_managedVerifySecp256k1, C.v1_5_managedVerifySecp256k1) - if err != nil { - return err - } - - err = imports.append("encodeSecp256k1DerSignature", v1_5_encodeSecp256k1DerSignature, C.v1_5_encodeSecp256k1DerSignature) - if err != nil { - return err - } - - err = imports.append("managedEncodeSecp256k1DerSignature", v1_5_managedEncodeSecp256k1DerSignature, C.v1_5_managedEncodeSecp256k1DerSignature) - if err != nil { - return err - } - - err = imports.append("addEC", v1_5_addEC, C.v1_5_addEC) - if err != nil { - return err - } - - err = imports.append("doubleEC", v1_5_doubleEC, C.v1_5_doubleEC) - if err != nil { - return err - } - - err = imports.append("isOnCurveEC", v1_5_isOnCurveEC, C.v1_5_isOnCurveEC) - if err != nil { - return err - } - - err = imports.append("scalarBaseMultEC", v1_5_scalarBaseMultEC, C.v1_5_scalarBaseMultEC) - if err != nil { - return err - } - - err = imports.append("managedScalarBaseMultEC", v1_5_managedScalarBaseMultEC, C.v1_5_managedScalarBaseMultEC) - if err != nil { - return err - } - - err = imports.append("scalarMultEC", v1_5_scalarMultEC, C.v1_5_scalarMultEC) - if err != nil { - return err - } - - err = imports.append("managedScalarMultEC", v1_5_managedScalarMultEC, C.v1_5_managedScalarMultEC) - if err != nil { - return err - } - - err = imports.append("marshalEC", v1_5_marshalEC, C.v1_5_marshalEC) - if err != nil { - return err - } - - err = imports.append("managedMarshalEC", v1_5_managedMarshalEC, C.v1_5_managedMarshalEC) - if err != nil { - return err - } - - err = imports.append("marshalCompressedEC", v1_5_marshalCompressedEC, C.v1_5_marshalCompressedEC) - if err != nil { - return err - } - - err = imports.append("managedMarshalCompressedEC", v1_5_managedMarshalCompressedEC, C.v1_5_managedMarshalCompressedEC) - if err != nil { - return err - } - - err = imports.append("unmarshalEC", v1_5_unmarshalEC, C.v1_5_unmarshalEC) - if err != nil { - return err - } - - err = imports.append("managedUnmarshalEC", v1_5_managedUnmarshalEC, C.v1_5_managedUnmarshalEC) - if err != nil { - return err - } - - err = imports.append("unmarshalCompressedEC", v1_5_unmarshalCompressedEC, C.v1_5_unmarshalCompressedEC) - if err != nil { - return err - } - - err = imports.append("managedUnmarshalCompressedEC", v1_5_managedUnmarshalCompressedEC, C.v1_5_managedUnmarshalCompressedEC) - if err != nil { - return err - } - - err = imports.append("generateKeyEC", v1_5_generateKeyEC, C.v1_5_generateKeyEC) - if err != nil { - return err - } - - err = imports.append("managedGenerateKeyEC", v1_5_managedGenerateKeyEC, C.v1_5_managedGenerateKeyEC) - if err != nil { - return err - } - - err = imports.append("createEC", v1_5_createEC, C.v1_5_createEC) - if err != nil { - return err - } - - err = imports.append("managedCreateEC", v1_5_managedCreateEC, C.v1_5_managedCreateEC) - if err != nil { - return err - } - - err = imports.append("getCurveLengthEC", v1_5_getCurveLengthEC, C.v1_5_getCurveLengthEC) - if err != nil { - return err - } - - err = imports.append("getPrivKeyByteLengthEC", v1_5_getPrivKeyByteLengthEC, C.v1_5_getPrivKeyByteLengthEC) - if err != nil { - return err - } - - err = imports.append("ellipticCurveGetValues", v1_5_ellipticCurveGetValues, C.v1_5_ellipticCurveGetValues) - if err != nil { - return err - } - - err = imports.append("managedVerifySecp256r1", v1_5_managedVerifySecp256r1, C.v1_5_managedVerifySecp256r1) - if err != nil { - return err - } - - err = imports.append("managedVerifyBLSSignatureShare", v1_5_managedVerifyBLSSignatureShare, C.v1_5_managedVerifyBLSSignatureShare) - if err != nil { - return err - } - - err = imports.append("managedVerifyBLSAggregatedSignature", v1_5_managedVerifyBLSAggregatedSignature, C.v1_5_managedVerifyBLSAggregatedSignature) - if err != nil { - return err - } - - return nil -} - -//export v1_5_getGasLeft -func v1_5_getGasLeft(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetGasLeft() -} - -//export v1_5_getSCAddress -func v1_5_getSCAddress(context unsafe.Pointer, resultOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetSCAddress(executor.MemPtr(resultOffset)) -} - -//export v1_5_getOwnerAddress -func v1_5_getOwnerAddress(context unsafe.Pointer, resultOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetOwnerAddress(executor.MemPtr(resultOffset)) -} - -//export v1_5_getShardOfAddress -func v1_5_getShardOfAddress(context unsafe.Pointer, addressOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetShardOfAddress(executor.MemPtr(addressOffset)) -} - -//export v1_5_isSmartContract -func v1_5_isSmartContract(context unsafe.Pointer, addressOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.IsSmartContract(executor.MemPtr(addressOffset)) -} - -//export v1_5_signalError -func v1_5_signalError(context unsafe.Pointer, messageOffset int32, messageLength int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.SignalError(executor.MemPtr(messageOffset), messageLength) -} - -//export v1_5_getExternalBalance -func v1_5_getExternalBalance(context unsafe.Pointer, addressOffset int32, resultOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetExternalBalance(executor.MemPtr(addressOffset), executor.MemPtr(resultOffset)) -} - -//export v1_5_getBlockHash -func v1_5_getBlockHash(context unsafe.Pointer, nonce int64, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetBlockHash(nonce, executor.MemPtr(resultOffset)) -} - -//export v1_5_getESDTBalance -func v1_5_getESDTBalance(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTBalance(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce, executor.MemPtr(resultOffset)) -} - -//export v1_5_getESDTNFTNameLength -func v1_5_getESDTNFTNameLength(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTNFTNameLength(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce) -} - -//export v1_5_getESDTNFTAttributeLength -func v1_5_getESDTNFTAttributeLength(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTNFTAttributeLength(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce) -} - -//export v1_5_getESDTNFTURILength -func v1_5_getESDTNFTURILength(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTNFTURILength(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce) -} - -//export v1_5_getESDTTokenData -func v1_5_getESDTTokenData(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64, valueHandle int32, propertiesOffset int32, hashOffset int32, nameOffset int32, attributesOffset int32, creatorOffset int32, royaltiesHandle int32, urisOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenData(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce, valueHandle, executor.MemPtr(propertiesOffset), executor.MemPtr(hashOffset), executor.MemPtr(nameOffset), executor.MemPtr(attributesOffset), executor.MemPtr(creatorOffset), royaltiesHandle, executor.MemPtr(urisOffset)) -} - -//export v1_5_getESDTLocalRoles -func v1_5_getESDTLocalRoles(context unsafe.Pointer, tokenIdHandle int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTLocalRoles(tokenIdHandle) -} - -//export v1_5_validateTokenIdentifier -func v1_5_validateTokenIdentifier(context unsafe.Pointer, tokenIdHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ValidateTokenIdentifier(tokenIdHandle) -} - -//export v1_5_transferValue -func v1_5_transferValue(context unsafe.Pointer, destOffset int32, valueOffset int32, dataOffset int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.TransferValue(executor.MemPtr(destOffset), executor.MemPtr(valueOffset), executor.MemPtr(dataOffset), length) -} - -//export v1_5_transferValueExecute -func v1_5_transferValueExecute(context unsafe.Pointer, destOffset int32, valueOffset int32, gasLimit int64, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.TransferValueExecute(executor.MemPtr(destOffset), executor.MemPtr(valueOffset), gasLimit, executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_transferESDTExecute -func v1_5_transferESDTExecute(context unsafe.Pointer, destOffset int32, tokenIDOffset int32, tokenIDLen int32, valueOffset int32, gasLimit int64, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.TransferESDTExecute(executor.MemPtr(destOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, executor.MemPtr(valueOffset), gasLimit, executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_transferESDTNFTExecute -func v1_5_transferESDTNFTExecute(context unsafe.Pointer, destOffset int32, tokenIDOffset int32, tokenIDLen int32, valueOffset int32, nonce int64, gasLimit int64, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.TransferESDTNFTExecute(executor.MemPtr(destOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, executor.MemPtr(valueOffset), nonce, gasLimit, executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_multiTransferESDTNFTExecute -func v1_5_multiTransferESDTNFTExecute(context unsafe.Pointer, destOffset int32, numTokenTransfers int32, tokenTransfersArgsLengthOffset int32, tokenTransferDataOffset int32, gasLimit int64, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MultiTransferESDTNFTExecute(executor.MemPtr(destOffset), numTokenTransfers, executor.MemPtr(tokenTransfersArgsLengthOffset), executor.MemPtr(tokenTransferDataOffset), gasLimit, executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_createAsyncCall -func v1_5_createAsyncCall(context unsafe.Pointer, destOffset int32, valueOffset int32, dataOffset int32, dataLength int32, successOffset int32, successLength int32, errorOffset int32, errorLength int32, gas int64, extraGasForCallback int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.CreateAsyncCall(executor.MemPtr(destOffset), executor.MemPtr(valueOffset), executor.MemPtr(dataOffset), dataLength, executor.MemPtr(successOffset), successLength, executor.MemPtr(errorOffset), errorLength, gas, extraGasForCallback) -} - -//export v1_5_setAsyncContextCallback -func v1_5_setAsyncContextCallback(context unsafe.Pointer, callback int32, callbackLength int32, data int32, dataLength int32, gas int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SetAsyncContextCallback(executor.MemPtr(callback), callbackLength, executor.MemPtr(data), dataLength, gas) -} - -//export v1_5_upgradeContract -func v1_5_upgradeContract(context unsafe.Pointer, destOffset int32, gasLimit int64, valueOffset int32, codeOffset int32, codeMetadataOffset int32, length int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.UpgradeContract(executor.MemPtr(destOffset), gasLimit, executor.MemPtr(valueOffset), executor.MemPtr(codeOffset), executor.MemPtr(codeMetadataOffset), length, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_upgradeFromSourceContract -func v1_5_upgradeFromSourceContract(context unsafe.Pointer, destOffset int32, gasLimit int64, valueOffset int32, sourceContractAddressOffset int32, codeMetadataOffset int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.UpgradeFromSourceContract(executor.MemPtr(destOffset), gasLimit, executor.MemPtr(valueOffset), executor.MemPtr(sourceContractAddressOffset), executor.MemPtr(codeMetadataOffset), numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_deleteContract -func v1_5_deleteContract(context unsafe.Pointer, destOffset int32, gasLimit int64, numArguments int32, argumentsLengthOffset int32, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.DeleteContract(executor.MemPtr(destOffset), gasLimit, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_asyncCall -func v1_5_asyncCall(context unsafe.Pointer, destOffset int32, valueOffset int32, dataOffset int32, length int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.AsyncCall(executor.MemPtr(destOffset), executor.MemPtr(valueOffset), executor.MemPtr(dataOffset), length) -} - -//export v1_5_getArgumentLength -func v1_5_getArgumentLength(context unsafe.Pointer, id int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetArgumentLength(id) -} - -//export v1_5_getArgument -func v1_5_getArgument(context unsafe.Pointer, id int32, argOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetArgument(id, executor.MemPtr(argOffset)) -} - -//export v1_5_getFunction -func v1_5_getFunction(context unsafe.Pointer, functionOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetFunction(executor.MemPtr(functionOffset)) -} - -//export v1_5_getNumArguments -func v1_5_getNumArguments(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetNumArguments() -} - -//export v1_5_storageStore -func v1_5_storageStore(context unsafe.Pointer, keyOffset int32, keyLength int32, dataOffset int32, dataLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.StorageStore(executor.MemPtr(keyOffset), keyLength, executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_storageLoadLength -func v1_5_storageLoadLength(context unsafe.Pointer, keyOffset int32, keyLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.StorageLoadLength(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_storageLoadFromAddress -func v1_5_storageLoadFromAddress(context unsafe.Pointer, addressOffset int32, keyOffset int32, keyLength int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.StorageLoadFromAddress(executor.MemPtr(addressOffset), executor.MemPtr(keyOffset), keyLength, executor.MemPtr(dataOffset)) -} - -//export v1_5_storageLoad -func v1_5_storageLoad(context unsafe.Pointer, keyOffset int32, keyLength int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.StorageLoad(executor.MemPtr(keyOffset), keyLength, executor.MemPtr(dataOffset)) -} - -//export v1_5_setStorageLock -func v1_5_setStorageLock(context unsafe.Pointer, keyOffset int32, keyLength int32, lockTimestamp int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SetStorageLock(executor.MemPtr(keyOffset), keyLength, lockTimestamp) -} - -//export v1_5_getStorageLock -func v1_5_getStorageLock(context unsafe.Pointer, keyOffset int32, keyLength int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetStorageLock(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_isStorageLocked -func v1_5_isStorageLocked(context unsafe.Pointer, keyOffset int32, keyLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.IsStorageLocked(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_clearStorageLock -func v1_5_clearStorageLock(context unsafe.Pointer, keyOffset int32, keyLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ClearStorageLock(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_getCaller -func v1_5_getCaller(context unsafe.Pointer, resultOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetCaller(executor.MemPtr(resultOffset)) -} - -//export v1_5_checkNoPayment -func v1_5_checkNoPayment(context unsafe.Pointer) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.CheckNoPayment() -} - -//export v1_5_getCallValue -func v1_5_getCallValue(context unsafe.Pointer, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetCallValue(executor.MemPtr(resultOffset)) -} - -//export v1_5_getESDTValue -func v1_5_getESDTValue(context unsafe.Pointer, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTValue(executor.MemPtr(resultOffset)) -} - -//export v1_5_getESDTValueByIndex -func v1_5_getESDTValueByIndex(context unsafe.Pointer, resultOffset int32, index int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTValueByIndex(executor.MemPtr(resultOffset), index) -} - -//export v1_5_getESDTTokenName -func v1_5_getESDTTokenName(context unsafe.Pointer, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenName(executor.MemPtr(resultOffset)) -} - -//export v1_5_getESDTTokenNameByIndex -func v1_5_getESDTTokenNameByIndex(context unsafe.Pointer, resultOffset int32, index int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenNameByIndex(executor.MemPtr(resultOffset), index) -} - -//export v1_5_getESDTTokenNonce -func v1_5_getESDTTokenNonce(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenNonce() -} - -//export v1_5_getESDTTokenNonceByIndex -func v1_5_getESDTTokenNonceByIndex(context unsafe.Pointer, index int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenNonceByIndex(index) -} - -//export v1_5_getCurrentESDTNFTNonce -func v1_5_getCurrentESDTNFTNonce(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetCurrentESDTNFTNonce(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen) -} - -//export v1_5_getESDTTokenType -func v1_5_getESDTTokenType(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenType() -} - -//export v1_5_getESDTTokenTypeByIndex -func v1_5_getESDTTokenTypeByIndex(context unsafe.Pointer, index int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetESDTTokenTypeByIndex(index) -} - -//export v1_5_getNumESDTTransfers -func v1_5_getNumESDTTransfers(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetNumESDTTransfers() -} - -//export v1_5_getCallValueTokenName -func v1_5_getCallValueTokenName(context unsafe.Pointer, callValueOffset int32, tokenNameOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetCallValueTokenName(executor.MemPtr(callValueOffset), executor.MemPtr(tokenNameOffset)) -} - -//export v1_5_getCallValueTokenNameByIndex -func v1_5_getCallValueTokenNameByIndex(context unsafe.Pointer, callValueOffset int32, tokenNameOffset int32, index int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetCallValueTokenNameByIndex(executor.MemPtr(callValueOffset), executor.MemPtr(tokenNameOffset), index) -} - -//export v1_5_isReservedFunctionName -func v1_5_isReservedFunctionName(context unsafe.Pointer, nameHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.IsReservedFunctionName(nameHandle) -} - -//export v1_5_writeLog -func v1_5_writeLog(context unsafe.Pointer, dataPointer int32, dataLength int32, topicPtr int32, numTopics int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.WriteLog(executor.MemPtr(dataPointer), dataLength, executor.MemPtr(topicPtr), numTopics) -} - -//export v1_5_writeEventLog -func v1_5_writeEventLog(context unsafe.Pointer, numTopics int32, topicLengthsOffset int32, topicOffset int32, dataOffset int32, dataLength int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.WriteEventLog(numTopics, executor.MemPtr(topicLengthsOffset), executor.MemPtr(topicOffset), executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_getBlockTimestamp -func v1_5_getBlockTimestamp(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetBlockTimestamp() -} - -//export v1_5_getBlockNonce -func v1_5_getBlockNonce(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetBlockNonce() -} - -//export v1_5_getBlockRound -func v1_5_getBlockRound(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetBlockRound() -} - -//export v1_5_getBlockEpoch -func v1_5_getBlockEpoch(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetBlockEpoch() -} - -//export v1_5_getBlockRandomSeed -func v1_5_getBlockRandomSeed(context unsafe.Pointer, pointer int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetBlockRandomSeed(executor.MemPtr(pointer)) -} - -//export v1_5_getStateRootHash -func v1_5_getStateRootHash(context unsafe.Pointer, pointer int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetStateRootHash(executor.MemPtr(pointer)) -} - -//export v1_5_getPrevBlockTimestamp -func v1_5_getPrevBlockTimestamp(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetPrevBlockTimestamp() -} - -//export v1_5_getPrevBlockNonce -func v1_5_getPrevBlockNonce(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetPrevBlockNonce() -} - -//export v1_5_getPrevBlockRound -func v1_5_getPrevBlockRound(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetPrevBlockRound() -} - -//export v1_5_getPrevBlockEpoch -func v1_5_getPrevBlockEpoch(context unsafe.Pointer) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetPrevBlockEpoch() -} - -//export v1_5_getPrevBlockRandomSeed -func v1_5_getPrevBlockRandomSeed(context unsafe.Pointer, pointer int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetPrevBlockRandomSeed(executor.MemPtr(pointer)) -} - -//export v1_5_finish -func v1_5_finish(context unsafe.Pointer, pointer int32, length int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.Finish(executor.MemPtr(pointer), length) -} - -//export v1_5_executeOnSameContext -func v1_5_executeOnSameContext(context unsafe.Pointer, gasLimit int64, addressOffset int32, valueOffset int32, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ExecuteOnSameContext(gasLimit, executor.MemPtr(addressOffset), executor.MemPtr(valueOffset), executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_executeOnDestContext -func v1_5_executeOnDestContext(context unsafe.Pointer, gasLimit int64, addressOffset int32, valueOffset int32, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ExecuteOnDestContext(gasLimit, executor.MemPtr(addressOffset), executor.MemPtr(valueOffset), executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_executeReadOnly -func v1_5_executeReadOnly(context unsafe.Pointer, gasLimit int64, addressOffset int32, functionOffset int32, functionLength int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ExecuteReadOnly(gasLimit, executor.MemPtr(addressOffset), executor.MemPtr(functionOffset), functionLength, numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_createContract -func v1_5_createContract(context unsafe.Pointer, gasLimit int64, valueOffset int32, codeOffset int32, codeMetadataOffset int32, length int32, resultOffset int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.CreateContract(gasLimit, executor.MemPtr(valueOffset), executor.MemPtr(codeOffset), executor.MemPtr(codeMetadataOffset), length, executor.MemPtr(resultOffset), numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_deployFromSourceContract -func v1_5_deployFromSourceContract(context unsafe.Pointer, gasLimit int64, valueOffset int32, sourceContractAddressOffset int32, codeMetadataOffset int32, resultAddressOffset int32, numArguments int32, argumentsLengthOffset int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.DeployFromSourceContract(gasLimit, executor.MemPtr(valueOffset), executor.MemPtr(sourceContractAddressOffset), executor.MemPtr(codeMetadataOffset), executor.MemPtr(resultAddressOffset), numArguments, executor.MemPtr(argumentsLengthOffset), executor.MemPtr(dataOffset)) -} - -//export v1_5_getNumReturnData -func v1_5_getNumReturnData(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetNumReturnData() -} - -//export v1_5_getReturnDataSize -func v1_5_getReturnDataSize(context unsafe.Pointer, resultID int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetReturnDataSize(resultID) -} - -//export v1_5_getReturnData -func v1_5_getReturnData(context unsafe.Pointer, resultID int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetReturnData(resultID, executor.MemPtr(dataOffset)) -} - -//export v1_5_cleanReturnData -func v1_5_cleanReturnData(context unsafe.Pointer) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.CleanReturnData() -} - -//export v1_5_deleteFromReturnData -func v1_5_deleteFromReturnData(context unsafe.Pointer, resultID int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.DeleteFromReturnData(resultID) -} - -//export v1_5_getOriginalTxHash -func v1_5_getOriginalTxHash(context unsafe.Pointer, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetOriginalTxHash(executor.MemPtr(dataOffset)) -} - -//export v1_5_getCurrentTxHash -func v1_5_getCurrentTxHash(context unsafe.Pointer, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetCurrentTxHash(executor.MemPtr(dataOffset)) -} - -//export v1_5_getPrevTxHash -func v1_5_getPrevTxHash(context unsafe.Pointer, dataOffset int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.GetPrevTxHash(executor.MemPtr(dataOffset)) -} - -//export v1_5_managedSCAddress -func v1_5_managedSCAddress(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedSCAddress(destinationHandle) -} - -//export v1_5_managedOwnerAddress -func v1_5_managedOwnerAddress(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedOwnerAddress(destinationHandle) -} - -//export v1_5_managedCaller -func v1_5_managedCaller(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedCaller(destinationHandle) -} - -//export v1_5_managedGetOriginalCallerAddr -func v1_5_managedGetOriginalCallerAddr(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetOriginalCallerAddr(destinationHandle) -} - -//export v1_5_managedGetRelayerAddr -func v1_5_managedGetRelayerAddr(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetRelayerAddr(destinationHandle) -} - -//export v1_5_managedSignalError -func v1_5_managedSignalError(context unsafe.Pointer, errHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedSignalError(errHandle) -} - -//export v1_5_managedWriteLog -func v1_5_managedWriteLog(context unsafe.Pointer, topicsHandle int32, dataHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedWriteLog(topicsHandle, dataHandle) -} - -//export v1_5_managedGetOriginalTxHash -func v1_5_managedGetOriginalTxHash(context unsafe.Pointer, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetOriginalTxHash(resultHandle) -} - -//export v1_5_managedGetStateRootHash -func v1_5_managedGetStateRootHash(context unsafe.Pointer, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetStateRootHash(resultHandle) -} - -//export v1_5_managedGetBlockRandomSeed -func v1_5_managedGetBlockRandomSeed(context unsafe.Pointer, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetBlockRandomSeed(resultHandle) -} - -//export v1_5_managedGetPrevBlockRandomSeed -func v1_5_managedGetPrevBlockRandomSeed(context unsafe.Pointer, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetPrevBlockRandomSeed(resultHandle) -} - -//export v1_5_managedGetReturnData -func v1_5_managedGetReturnData(context unsafe.Pointer, resultID int32, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetReturnData(resultID, resultHandle) -} - -//export v1_5_managedGetMultiESDTCallValue -func v1_5_managedGetMultiESDTCallValue(context unsafe.Pointer, multiCallValueHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetMultiESDTCallValue(multiCallValueHandle) -} - -//export v1_5_managedGetBackTransfers -func v1_5_managedGetBackTransfers(context unsafe.Pointer, esdtTransfersValueHandle int32, egldValueHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetBackTransfers(esdtTransfersValueHandle, egldValueHandle) -} - -//export v1_5_managedGetESDTBalance -func v1_5_managedGetESDTBalance(context unsafe.Pointer, addressHandle int32, tokenIDHandle int32, nonce int64, valueHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetESDTBalance(addressHandle, tokenIDHandle, nonce, valueHandle) -} - -//export v1_5_managedGetESDTTokenData -func v1_5_managedGetESDTTokenData(context unsafe.Pointer, addressHandle int32, tokenIDHandle int32, nonce int64, valueHandle int32, propertiesHandle int32, hashHandle int32, nameHandle int32, attributesHandle int32, creatorHandle int32, royaltiesHandle int32, urisHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetESDTTokenData(addressHandle, tokenIDHandle, nonce, valueHandle, propertiesHandle, hashHandle, nameHandle, attributesHandle, creatorHandle, royaltiesHandle, urisHandle) -} - -//export v1_5_managedAsyncCall -func v1_5_managedAsyncCall(context unsafe.Pointer, destHandle int32, valueHandle int32, functionHandle int32, argumentsHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedAsyncCall(destHandle, valueHandle, functionHandle, argumentsHandle) -} - -//export v1_5_managedCreateAsyncCall -func v1_5_managedCreateAsyncCall(context unsafe.Pointer, destHandle int32, valueHandle int32, functionHandle int32, argumentsHandle int32, successOffset int32, successLength int32, errorOffset int32, errorLength int32, gas int64, extraGasForCallback int64, callbackClosureHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedCreateAsyncCall(destHandle, valueHandle, functionHandle, argumentsHandle, executor.MemPtr(successOffset), successLength, executor.MemPtr(errorOffset), errorLength, gas, extraGasForCallback, callbackClosureHandle) -} - -//export v1_5_managedGetCallbackClosure -func v1_5_managedGetCallbackClosure(context unsafe.Pointer, callbackClosureHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetCallbackClosure(callbackClosureHandle) -} - -//export v1_5_managedUpgradeFromSourceContract -func v1_5_managedUpgradeFromSourceContract(context unsafe.Pointer, destHandle int32, gas int64, valueHandle int32, addressHandle int32, codeMetadataHandle int32, argumentsHandle int32, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedUpgradeFromSourceContract(destHandle, gas, valueHandle, addressHandle, codeMetadataHandle, argumentsHandle, resultHandle) -} - -//export v1_5_managedUpgradeContract -func v1_5_managedUpgradeContract(context unsafe.Pointer, destHandle int32, gas int64, valueHandle int32, codeHandle int32, codeMetadataHandle int32, argumentsHandle int32, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedUpgradeContract(destHandle, gas, valueHandle, codeHandle, codeMetadataHandle, argumentsHandle, resultHandle) -} - -//export v1_5_managedDeleteContract -func v1_5_managedDeleteContract(context unsafe.Pointer, destHandle int32, gasLimit int64, argumentsHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedDeleteContract(destHandle, gasLimit, argumentsHandle) -} - -//export v1_5_managedDeployFromSourceContract -func v1_5_managedDeployFromSourceContract(context unsafe.Pointer, gas int64, valueHandle int32, addressHandle int32, codeMetadataHandle int32, argumentsHandle int32, resultAddressHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedDeployFromSourceContract(gas, valueHandle, addressHandle, codeMetadataHandle, argumentsHandle, resultAddressHandle, resultHandle) -} - -//export v1_5_managedCreateContract -func v1_5_managedCreateContract(context unsafe.Pointer, gas int64, valueHandle int32, codeHandle int32, codeMetadataHandle int32, argumentsHandle int32, resultAddressHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedCreateContract(gas, valueHandle, codeHandle, codeMetadataHandle, argumentsHandle, resultAddressHandle, resultHandle) -} - -//export v1_5_managedExecuteReadOnly -func v1_5_managedExecuteReadOnly(context unsafe.Pointer, gas int64, addressHandle int32, functionHandle int32, argumentsHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedExecuteReadOnly(gas, addressHandle, functionHandle, argumentsHandle, resultHandle) -} - -//export v1_5_managedExecuteOnSameContext -func v1_5_managedExecuteOnSameContext(context unsafe.Pointer, gas int64, addressHandle int32, valueHandle int32, functionHandle int32, argumentsHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedExecuteOnSameContext(gas, addressHandle, valueHandle, functionHandle, argumentsHandle, resultHandle) -} - -//export v1_5_managedExecuteOnDestContext -func v1_5_managedExecuteOnDestContext(context unsafe.Pointer, gas int64, addressHandle int32, valueHandle int32, functionHandle int32, argumentsHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedExecuteOnDestContext(gas, addressHandle, valueHandle, functionHandle, argumentsHandle, resultHandle) -} - -//export v1_5_managedMultiTransferESDTNFTExecute -func v1_5_managedMultiTransferESDTNFTExecute(context unsafe.Pointer, dstHandle int32, tokenTransfersHandle int32, gasLimit int64, functionHandle int32, argumentsHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMultiTransferESDTNFTExecute(dstHandle, tokenTransfersHandle, gasLimit, functionHandle, argumentsHandle) -} - -//export v1_5_managedMultiTransferESDTNFTExecuteByUser -func v1_5_managedMultiTransferESDTNFTExecuteByUser(context unsafe.Pointer, userHandle int32, dstHandle int32, tokenTransfersHandle int32, gasLimit int64, functionHandle int32, argumentsHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMultiTransferESDTNFTExecuteByUser(userHandle, dstHandle, tokenTransfersHandle, gasLimit, functionHandle, argumentsHandle) -} - -//export v1_5_managedTransferValueExecute -func v1_5_managedTransferValueExecute(context unsafe.Pointer, dstHandle int32, valueHandle int32, gasLimit int64, functionHandle int32, argumentsHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedTransferValueExecute(dstHandle, valueHandle, gasLimit, functionHandle, argumentsHandle) -} - -//export v1_5_managedIsESDTFrozen -func v1_5_managedIsESDTFrozen(context unsafe.Pointer, addressHandle int32, tokenIDHandle int32, nonce int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedIsESDTFrozen(addressHandle, tokenIDHandle, nonce) -} - -//export v1_5_managedIsESDTLimitedTransfer -func v1_5_managedIsESDTLimitedTransfer(context unsafe.Pointer, tokenIDHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedIsESDTLimitedTransfer(tokenIDHandle) -} - -//export v1_5_managedIsESDTPaused -func v1_5_managedIsESDTPaused(context unsafe.Pointer, tokenIDHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedIsESDTPaused(tokenIDHandle) -} - -//export v1_5_managedBufferToHex -func v1_5_managedBufferToHex(context unsafe.Pointer, sourceHandle int32, destHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedBufferToHex(sourceHandle, destHandle) -} - -//export v1_5_managedGetCodeMetadata -func v1_5_managedGetCodeMetadata(context unsafe.Pointer, addressHandle int32, responseHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.ManagedGetCodeMetadata(addressHandle, responseHandle) -} - -//export v1_5_managedIsBuiltinFunction -func v1_5_managedIsBuiltinFunction(context unsafe.Pointer, functionNameHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedIsBuiltinFunction(functionNameHandle) -} - -//export v1_5_bigFloatNewFromParts -func v1_5_bigFloatNewFromParts(context unsafe.Pointer, integralPart int32, fractionalPart int32, exponent int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatNewFromParts(integralPart, fractionalPart, exponent) -} - -//export v1_5_bigFloatNewFromFrac -func v1_5_bigFloatNewFromFrac(context unsafe.Pointer, numerator int64, denominator int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatNewFromFrac(numerator, denominator) -} - -//export v1_5_bigFloatNewFromSci -func v1_5_bigFloatNewFromSci(context unsafe.Pointer, significand int64, exponent int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatNewFromSci(significand, exponent) -} - -//export v1_5_bigFloatAdd -func v1_5_bigFloatAdd(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatAdd(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigFloatSub -func v1_5_bigFloatSub(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatSub(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigFloatMul -func v1_5_bigFloatMul(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatMul(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigFloatDiv -func v1_5_bigFloatDiv(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatDiv(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigFloatNeg -func v1_5_bigFloatNeg(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatNeg(destinationHandle, opHandle) -} - -//export v1_5_bigFloatClone -func v1_5_bigFloatClone(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatClone(destinationHandle, opHandle) -} - -//export v1_5_bigFloatCmp -func v1_5_bigFloatCmp(context unsafe.Pointer, op1Handle int32, op2Handle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatCmp(op1Handle, op2Handle) -} - -//export v1_5_bigFloatAbs -func v1_5_bigFloatAbs(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatAbs(destinationHandle, opHandle) -} - -//export v1_5_bigFloatSign -func v1_5_bigFloatSign(context unsafe.Pointer, opHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatSign(opHandle) -} - -//export v1_5_bigFloatSqrt -func v1_5_bigFloatSqrt(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatSqrt(destinationHandle, opHandle) -} - -//export v1_5_bigFloatPow -func v1_5_bigFloatPow(context unsafe.Pointer, destinationHandle int32, opHandle int32, exponent int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatPow(destinationHandle, opHandle, exponent) -} - -//export v1_5_bigFloatFloor -func v1_5_bigFloatFloor(context unsafe.Pointer, destBigIntHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatFloor(destBigIntHandle, opHandle) -} - -//export v1_5_bigFloatCeil -func v1_5_bigFloatCeil(context unsafe.Pointer, destBigIntHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatCeil(destBigIntHandle, opHandle) -} - -//export v1_5_bigFloatTruncate -func v1_5_bigFloatTruncate(context unsafe.Pointer, destBigIntHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatTruncate(destBigIntHandle, opHandle) -} - -//export v1_5_bigFloatSetInt64 -func v1_5_bigFloatSetInt64(context unsafe.Pointer, destinationHandle int32, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatSetInt64(destinationHandle, value) -} - -//export v1_5_bigFloatIsInt -func v1_5_bigFloatIsInt(context unsafe.Pointer, opHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigFloatIsInt(opHandle) -} - -//export v1_5_bigFloatSetBigInt -func v1_5_bigFloatSetBigInt(context unsafe.Pointer, destinationHandle int32, bigIntHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatSetBigInt(destinationHandle, bigIntHandle) -} - -//export v1_5_bigFloatGetConstPi -func v1_5_bigFloatGetConstPi(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatGetConstPi(destinationHandle) -} - -//export v1_5_bigFloatGetConstE -func v1_5_bigFloatGetConstE(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigFloatGetConstE(destinationHandle) -} - -//export v1_5_bigIntGetUnsignedArgument -func v1_5_bigIntGetUnsignedArgument(context unsafe.Pointer, id int32, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetUnsignedArgument(id, destinationHandle) -} - -//export v1_5_bigIntGetSignedArgument -func v1_5_bigIntGetSignedArgument(context unsafe.Pointer, id int32, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetSignedArgument(id, destinationHandle) -} - -//export v1_5_bigIntStorageStoreUnsigned -func v1_5_bigIntStorageStoreUnsigned(context unsafe.Pointer, keyOffset int32, keyLength int32, sourceHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntStorageStoreUnsigned(executor.MemPtr(keyOffset), keyLength, sourceHandle) -} - -//export v1_5_bigIntStorageLoadUnsigned -func v1_5_bigIntStorageLoadUnsigned(context unsafe.Pointer, keyOffset int32, keyLength int32, destinationHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntStorageLoadUnsigned(executor.MemPtr(keyOffset), keyLength, destinationHandle) -} - -//export v1_5_bigIntGetCallValue -func v1_5_bigIntGetCallValue(context unsafe.Pointer, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetCallValue(destinationHandle) -} - -//export v1_5_bigIntGetESDTCallValue -func v1_5_bigIntGetESDTCallValue(context unsafe.Pointer, destination int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetESDTCallValue(destination) -} - -//export v1_5_bigIntGetESDTCallValueByIndex -func v1_5_bigIntGetESDTCallValueByIndex(context unsafe.Pointer, destinationHandle int32, index int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetESDTCallValueByIndex(destinationHandle, index) -} - -//export v1_5_bigIntGetExternalBalance -func v1_5_bigIntGetExternalBalance(context unsafe.Pointer, addressOffset int32, result int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetExternalBalance(executor.MemPtr(addressOffset), result) -} - -//export v1_5_bigIntGetESDTExternalBalance -func v1_5_bigIntGetESDTExternalBalance(context unsafe.Pointer, addressOffset int32, tokenIDOffset int32, tokenIDLen int32, nonce int64, resultHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntGetESDTExternalBalance(executor.MemPtr(addressOffset), executor.MemPtr(tokenIDOffset), tokenIDLen, nonce, resultHandle) -} - -//export v1_5_bigIntNew -func v1_5_bigIntNew(context unsafe.Pointer, smallValue int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntNew(smallValue) -} - -//export v1_5_bigIntUnsignedByteLength -func v1_5_bigIntUnsignedByteLength(context unsafe.Pointer, referenceHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntUnsignedByteLength(referenceHandle) -} - -//export v1_5_bigIntSignedByteLength -func v1_5_bigIntSignedByteLength(context unsafe.Pointer, referenceHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntSignedByteLength(referenceHandle) -} - -//export v1_5_bigIntGetUnsignedBytes -func v1_5_bigIntGetUnsignedBytes(context unsafe.Pointer, referenceHandle int32, byteOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntGetUnsignedBytes(referenceHandle, executor.MemPtr(byteOffset)) -} - -//export v1_5_bigIntGetSignedBytes -func v1_5_bigIntGetSignedBytes(context unsafe.Pointer, referenceHandle int32, byteOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntGetSignedBytes(referenceHandle, executor.MemPtr(byteOffset)) -} - -//export v1_5_bigIntSetUnsignedBytes -func v1_5_bigIntSetUnsignedBytes(context unsafe.Pointer, destinationHandle int32, byteOffset int32, byteLength int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntSetUnsignedBytes(destinationHandle, executor.MemPtr(byteOffset), byteLength) -} - -//export v1_5_bigIntSetSignedBytes -func v1_5_bigIntSetSignedBytes(context unsafe.Pointer, destinationHandle int32, byteOffset int32, byteLength int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntSetSignedBytes(destinationHandle, executor.MemPtr(byteOffset), byteLength) -} - -//export v1_5_bigIntIsInt64 -func v1_5_bigIntIsInt64(context unsafe.Pointer, destinationHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntIsInt64(destinationHandle) -} - -//export v1_5_bigIntGetInt64 -func v1_5_bigIntGetInt64(context unsafe.Pointer, destinationHandle int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntGetInt64(destinationHandle) -} - -//export v1_5_bigIntSetInt64 -func v1_5_bigIntSetInt64(context unsafe.Pointer, destinationHandle int32, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntSetInt64(destinationHandle, value) -} - -//export v1_5_bigIntAdd -func v1_5_bigIntAdd(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntAdd(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntSub -func v1_5_bigIntSub(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntSub(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntMul -func v1_5_bigIntMul(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntMul(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntTDiv -func v1_5_bigIntTDiv(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntTDiv(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntTMod -func v1_5_bigIntTMod(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntTMod(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntEDiv -func v1_5_bigIntEDiv(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntEDiv(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntEMod -func v1_5_bigIntEMod(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntEMod(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntSqrt -func v1_5_bigIntSqrt(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntSqrt(destinationHandle, opHandle) -} - -//export v1_5_bigIntPow -func v1_5_bigIntPow(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntPow(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntLog2 -func v1_5_bigIntLog2(context unsafe.Pointer, op1Handle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntLog2(op1Handle) -} - -//export v1_5_bigIntAbs -func v1_5_bigIntAbs(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntAbs(destinationHandle, opHandle) -} - -//export v1_5_bigIntNeg -func v1_5_bigIntNeg(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntNeg(destinationHandle, opHandle) -} - -//export v1_5_bigIntSign -func v1_5_bigIntSign(context unsafe.Pointer, opHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntSign(opHandle) -} - -//export v1_5_bigIntCmp -func v1_5_bigIntCmp(context unsafe.Pointer, op1Handle int32, op2Handle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.BigIntCmp(op1Handle, op2Handle) -} - -//export v1_5_bigIntNot -func v1_5_bigIntNot(context unsafe.Pointer, destinationHandle int32, opHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntNot(destinationHandle, opHandle) -} - -//export v1_5_bigIntAnd -func v1_5_bigIntAnd(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntAnd(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntOr -func v1_5_bigIntOr(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntOr(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntXor -func v1_5_bigIntXor(context unsafe.Pointer, destinationHandle int32, op1Handle int32, op2Handle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntXor(destinationHandle, op1Handle, op2Handle) -} - -//export v1_5_bigIntShr -func v1_5_bigIntShr(context unsafe.Pointer, destinationHandle int32, opHandle int32, bits int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntShr(destinationHandle, opHandle, bits) -} - -//export v1_5_bigIntShl -func v1_5_bigIntShl(context unsafe.Pointer, destinationHandle int32, opHandle int32, bits int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntShl(destinationHandle, opHandle, bits) -} - -//export v1_5_bigIntFinishUnsigned -func v1_5_bigIntFinishUnsigned(context unsafe.Pointer, referenceHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntFinishUnsigned(referenceHandle) -} - -//export v1_5_bigIntFinishSigned -func v1_5_bigIntFinishSigned(context unsafe.Pointer, referenceHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntFinishSigned(referenceHandle) -} - -//export v1_5_bigIntToString -func v1_5_bigIntToString(context unsafe.Pointer, bigIntHandle int32, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.BigIntToString(bigIntHandle, destinationHandle) -} - -//export v1_5_mBufferNew -func v1_5_mBufferNew(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferNew() -} - -//export v1_5_mBufferNewFromBytes -func v1_5_mBufferNewFromBytes(context unsafe.Pointer, dataOffset int32, dataLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferNewFromBytes(executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_mBufferGetLength -func v1_5_mBufferGetLength(context unsafe.Pointer, mBufferHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferGetLength(mBufferHandle) -} - -//export v1_5_mBufferGetBytes -func v1_5_mBufferGetBytes(context unsafe.Pointer, mBufferHandle int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferGetBytes(mBufferHandle, executor.MemPtr(resultOffset)) -} - -//export v1_5_mBufferGetByteSlice -func v1_5_mBufferGetByteSlice(context unsafe.Pointer, sourceHandle int32, startingPosition int32, sliceLength int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferGetByteSlice(sourceHandle, startingPosition, sliceLength, executor.MemPtr(resultOffset)) -} - -//export v1_5_mBufferCopyByteSlice -func v1_5_mBufferCopyByteSlice(context unsafe.Pointer, sourceHandle int32, startingPosition int32, sliceLength int32, destinationHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferCopyByteSlice(sourceHandle, startingPosition, sliceLength, destinationHandle) -} - -//export v1_5_mBufferEq -func v1_5_mBufferEq(context unsafe.Pointer, mBufferHandle1 int32, mBufferHandle2 int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferEq(mBufferHandle1, mBufferHandle2) -} - -//export v1_5_mBufferSetBytes -func v1_5_mBufferSetBytes(context unsafe.Pointer, mBufferHandle int32, dataOffset int32, dataLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferSetBytes(mBufferHandle, executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_mBufferSetByteSlice -func v1_5_mBufferSetByteSlice(context unsafe.Pointer, mBufferHandle int32, startingPosition int32, dataLength int32, dataOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferSetByteSlice(mBufferHandle, startingPosition, dataLength, executor.MemPtr(dataOffset)) -} - -//export v1_5_mBufferAppend -func v1_5_mBufferAppend(context unsafe.Pointer, accumulatorHandle int32, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferAppend(accumulatorHandle, dataHandle) -} - -//export v1_5_mBufferAppendBytes -func v1_5_mBufferAppendBytes(context unsafe.Pointer, accumulatorHandle int32, dataOffset int32, dataLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferAppendBytes(accumulatorHandle, executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_mBufferToBigIntUnsigned -func v1_5_mBufferToBigIntUnsigned(context unsafe.Pointer, mBufferHandle int32, bigIntHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferToBigIntUnsigned(mBufferHandle, bigIntHandle) -} - -//export v1_5_mBufferToBigIntSigned -func v1_5_mBufferToBigIntSigned(context unsafe.Pointer, mBufferHandle int32, bigIntHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferToBigIntSigned(mBufferHandle, bigIntHandle) -} - -//export v1_5_mBufferFromBigIntUnsigned -func v1_5_mBufferFromBigIntUnsigned(context unsafe.Pointer, mBufferHandle int32, bigIntHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferFromBigIntUnsigned(mBufferHandle, bigIntHandle) -} - -//export v1_5_mBufferFromBigIntSigned -func v1_5_mBufferFromBigIntSigned(context unsafe.Pointer, mBufferHandle int32, bigIntHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferFromBigIntSigned(mBufferHandle, bigIntHandle) -} - -//export v1_5_mBufferToSmallIntUnsigned -func v1_5_mBufferToSmallIntUnsigned(context unsafe.Pointer, mBufferHandle int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferToSmallIntUnsigned(mBufferHandle) -} - -//export v1_5_mBufferToSmallIntSigned -func v1_5_mBufferToSmallIntSigned(context unsafe.Pointer, mBufferHandle int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferToSmallIntSigned(mBufferHandle) -} - -//export v1_5_mBufferFromSmallIntUnsigned -func v1_5_mBufferFromSmallIntUnsigned(context unsafe.Pointer, mBufferHandle int32, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.MBufferFromSmallIntUnsigned(mBufferHandle, value) -} - -//export v1_5_mBufferFromSmallIntSigned -func v1_5_mBufferFromSmallIntSigned(context unsafe.Pointer, mBufferHandle int32, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.MBufferFromSmallIntSigned(mBufferHandle, value) -} - -//export v1_5_mBufferToBigFloat -func v1_5_mBufferToBigFloat(context unsafe.Pointer, mBufferHandle int32, bigFloatHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferToBigFloat(mBufferHandle, bigFloatHandle) -} - -//export v1_5_mBufferFromBigFloat -func v1_5_mBufferFromBigFloat(context unsafe.Pointer, mBufferHandle int32, bigFloatHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferFromBigFloat(mBufferHandle, bigFloatHandle) -} - -//export v1_5_mBufferStorageStore -func v1_5_mBufferStorageStore(context unsafe.Pointer, keyHandle int32, sourceHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferStorageStore(keyHandle, sourceHandle) -} - -//export v1_5_mBufferStorageLoad -func v1_5_mBufferStorageLoad(context unsafe.Pointer, keyHandle int32, destinationHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferStorageLoad(keyHandle, destinationHandle) -} - -//export v1_5_mBufferStorageLoadFromAddress -func v1_5_mBufferStorageLoadFromAddress(context unsafe.Pointer, addressHandle int32, keyHandle int32, destinationHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.MBufferStorageLoadFromAddress(addressHandle, keyHandle, destinationHandle) -} - -//export v1_5_mBufferGetArgument -func v1_5_mBufferGetArgument(context unsafe.Pointer, id int32, destinationHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferGetArgument(id, destinationHandle) -} - -//export v1_5_mBufferFinish -func v1_5_mBufferFinish(context unsafe.Pointer, sourceHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferFinish(sourceHandle) -} - -//export v1_5_mBufferSetRandom -func v1_5_mBufferSetRandom(context unsafe.Pointer, destinationHandle int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MBufferSetRandom(destinationHandle, length) -} - -//export v1_5_managedMapNew -func v1_5_managedMapNew(context unsafe.Pointer) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMapNew() -} - -//export v1_5_managedMapPut -func v1_5_managedMapPut(context unsafe.Pointer, mMapHandle int32, keyHandle int32, valueHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMapPut(mMapHandle, keyHandle, valueHandle) -} - -//export v1_5_managedMapGet -func v1_5_managedMapGet(context unsafe.Pointer, mMapHandle int32, keyHandle int32, outValueHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMapGet(mMapHandle, keyHandle, outValueHandle) -} - -//export v1_5_managedMapRemove -func v1_5_managedMapRemove(context unsafe.Pointer, mMapHandle int32, keyHandle int32, outValueHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMapRemove(mMapHandle, keyHandle, outValueHandle) -} - -//export v1_5_managedMapContains -func v1_5_managedMapContains(context unsafe.Pointer, mMapHandle int32, keyHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMapContains(mMapHandle, keyHandle) -} - -//export v1_5_smallIntGetUnsignedArgument -func v1_5_smallIntGetUnsignedArgument(context unsafe.Pointer, id int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntGetUnsignedArgument(id) -} - -//export v1_5_smallIntGetSignedArgument -func v1_5_smallIntGetSignedArgument(context unsafe.Pointer, id int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntGetSignedArgument(id) -} - -//export v1_5_smallIntFinishUnsigned -func v1_5_smallIntFinishUnsigned(context unsafe.Pointer, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.SmallIntFinishUnsigned(value) -} - -//export v1_5_smallIntFinishSigned -func v1_5_smallIntFinishSigned(context unsafe.Pointer, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.SmallIntFinishSigned(value) -} - -//export v1_5_smallIntStorageStoreUnsigned -func v1_5_smallIntStorageStoreUnsigned(context unsafe.Pointer, keyOffset int32, keyLength int32, value int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntStorageStoreUnsigned(executor.MemPtr(keyOffset), keyLength, value) -} - -//export v1_5_smallIntStorageStoreSigned -func v1_5_smallIntStorageStoreSigned(context unsafe.Pointer, keyOffset int32, keyLength int32, value int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntStorageStoreSigned(executor.MemPtr(keyOffset), keyLength, value) -} - -//export v1_5_smallIntStorageLoadUnsigned -func v1_5_smallIntStorageLoadUnsigned(context unsafe.Pointer, keyOffset int32, keyLength int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntStorageLoadUnsigned(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_smallIntStorageLoadSigned -func v1_5_smallIntStorageLoadSigned(context unsafe.Pointer, keyOffset int32, keyLength int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.SmallIntStorageLoadSigned(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_int64getArgument -func v1_5_int64getArgument(context unsafe.Pointer, id int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Int64getArgument(id) -} - -//export v1_5_int64finish -func v1_5_int64finish(context unsafe.Pointer, value int64) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.Int64finish(value) -} - -//export v1_5_int64storageStore -func v1_5_int64storageStore(context unsafe.Pointer, keyOffset int32, keyLength int32, value int64) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Int64storageStore(executor.MemPtr(keyOffset), keyLength, value) -} - -//export v1_5_int64storageLoad -func v1_5_int64storageLoad(context unsafe.Pointer, keyOffset int32, keyLength int32) int64 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Int64storageLoad(executor.MemPtr(keyOffset), keyLength) -} - -//export v1_5_sha256 -func v1_5_sha256(context unsafe.Pointer, dataOffset int32, length int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Sha256(executor.MemPtr(dataOffset), length, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedSha256 -func v1_5_managedSha256(context unsafe.Pointer, inputHandle int32, outputHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedSha256(inputHandle, outputHandle) -} - -//export v1_5_keccak256 -func v1_5_keccak256(context unsafe.Pointer, dataOffset int32, length int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Keccak256(executor.MemPtr(dataOffset), length, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedKeccak256 -func v1_5_managedKeccak256(context unsafe.Pointer, inputHandle int32, outputHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedKeccak256(inputHandle, outputHandle) -} - -//export v1_5_ripemd160 -func v1_5_ripemd160(context unsafe.Pointer, dataOffset int32, length int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.Ripemd160(executor.MemPtr(dataOffset), length, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedRipemd160 -func v1_5_managedRipemd160(context unsafe.Pointer, inputHandle int32, outputHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedRipemd160(inputHandle, outputHandle) -} - -//export v1_5_verifyBLS -func v1_5_verifyBLS(context unsafe.Pointer, keyOffset int32, messageOffset int32, messageLength int32, sigOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.VerifyBLS(executor.MemPtr(keyOffset), executor.MemPtr(messageOffset), messageLength, executor.MemPtr(sigOffset)) -} - -//export v1_5_managedVerifyBLS -func v1_5_managedVerifyBLS(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifyBLS(keyHandle, messageHandle, sigHandle) -} - -//export v1_5_verifyEd25519 -func v1_5_verifyEd25519(context unsafe.Pointer, keyOffset int32, messageOffset int32, messageLength int32, sigOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.VerifyEd25519(executor.MemPtr(keyOffset), executor.MemPtr(messageOffset), messageLength, executor.MemPtr(sigOffset)) -} - -//export v1_5_managedVerifyEd25519 -func v1_5_managedVerifyEd25519(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifyEd25519(keyHandle, messageHandle, sigHandle) -} - -//export v1_5_verifyCustomSecp256k1 -func v1_5_verifyCustomSecp256k1(context unsafe.Pointer, keyOffset int32, keyLength int32, messageOffset int32, messageLength int32, sigOffset int32, hashType int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.VerifyCustomSecp256k1(executor.MemPtr(keyOffset), keyLength, executor.MemPtr(messageOffset), messageLength, executor.MemPtr(sigOffset), hashType) -} - -//export v1_5_managedVerifyCustomSecp256k1 -func v1_5_managedVerifyCustomSecp256k1(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32, hashType int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifyCustomSecp256k1(keyHandle, messageHandle, sigHandle, hashType) -} - -//export v1_5_verifySecp256k1 -func v1_5_verifySecp256k1(context unsafe.Pointer, keyOffset int32, keyLength int32, messageOffset int32, messageLength int32, sigOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.VerifySecp256k1(executor.MemPtr(keyOffset), keyLength, executor.MemPtr(messageOffset), messageLength, executor.MemPtr(sigOffset)) -} - -//export v1_5_managedVerifySecp256k1 -func v1_5_managedVerifySecp256k1(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifySecp256k1(keyHandle, messageHandle, sigHandle) -} - -//export v1_5_encodeSecp256k1DerSignature -func v1_5_encodeSecp256k1DerSignature(context unsafe.Pointer, rOffset int32, rLength int32, sOffset int32, sLength int32, sigOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.EncodeSecp256k1DerSignature(executor.MemPtr(rOffset), rLength, executor.MemPtr(sOffset), sLength, executor.MemPtr(sigOffset)) -} - -//export v1_5_managedEncodeSecp256k1DerSignature -func v1_5_managedEncodeSecp256k1DerSignature(context unsafe.Pointer, rHandle int32, sHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedEncodeSecp256k1DerSignature(rHandle, sHandle, sigHandle) -} - -//export v1_5_addEC -func v1_5_addEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, fstPointXHandle int32, fstPointYHandle int32, sndPointXHandle int32, sndPointYHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.AddEC(xResultHandle, yResultHandle, ecHandle, fstPointXHandle, fstPointYHandle, sndPointXHandle, sndPointYHandle) -} - -//export v1_5_doubleEC -func v1_5_doubleEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, pointXHandle int32, pointYHandle int32) { - vmHooks := getVMHooksFromContextRawPtr(context) - vmHooks.DoubleEC(xResultHandle, yResultHandle, ecHandle, pointXHandle, pointYHandle) -} - -//export v1_5_isOnCurveEC -func v1_5_isOnCurveEC(context unsafe.Pointer, ecHandle int32, pointXHandle int32, pointYHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.IsOnCurveEC(ecHandle, pointXHandle, pointYHandle) -} - -//export v1_5_scalarBaseMultEC -func v1_5_scalarBaseMultEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataOffset int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ScalarBaseMultEC(xResultHandle, yResultHandle, ecHandle, executor.MemPtr(dataOffset), length) -} - -//export v1_5_managedScalarBaseMultEC -func v1_5_managedScalarBaseMultEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedScalarBaseMultEC(xResultHandle, yResultHandle, ecHandle, dataHandle) -} - -//export v1_5_scalarMultEC -func v1_5_scalarMultEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, pointXHandle int32, pointYHandle int32, dataOffset int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ScalarMultEC(xResultHandle, yResultHandle, ecHandle, pointXHandle, pointYHandle, executor.MemPtr(dataOffset), length) -} - -//export v1_5_managedScalarMultEC -func v1_5_managedScalarMultEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, pointXHandle int32, pointYHandle int32, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedScalarMultEC(xResultHandle, yResultHandle, ecHandle, pointXHandle, pointYHandle, dataHandle) -} - -//export v1_5_marshalEC -func v1_5_marshalEC(context unsafe.Pointer, xPairHandle int32, yPairHandle int32, ecHandle int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MarshalEC(xPairHandle, yPairHandle, ecHandle, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedMarshalEC -func v1_5_managedMarshalEC(context unsafe.Pointer, xPairHandle int32, yPairHandle int32, ecHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMarshalEC(xPairHandle, yPairHandle, ecHandle, resultHandle) -} - -//export v1_5_marshalCompressedEC -func v1_5_marshalCompressedEC(context unsafe.Pointer, xPairHandle int32, yPairHandle int32, ecHandle int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.MarshalCompressedEC(xPairHandle, yPairHandle, ecHandle, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedMarshalCompressedEC -func v1_5_managedMarshalCompressedEC(context unsafe.Pointer, xPairHandle int32, yPairHandle int32, ecHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedMarshalCompressedEC(xPairHandle, yPairHandle, ecHandle, resultHandle) -} - -//export v1_5_unmarshalEC -func v1_5_unmarshalEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataOffset int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.UnmarshalEC(xResultHandle, yResultHandle, ecHandle, executor.MemPtr(dataOffset), length) -} - -//export v1_5_managedUnmarshalEC -func v1_5_managedUnmarshalEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedUnmarshalEC(xResultHandle, yResultHandle, ecHandle, dataHandle) -} - -//export v1_5_unmarshalCompressedEC -func v1_5_unmarshalCompressedEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataOffset int32, length int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.UnmarshalCompressedEC(xResultHandle, yResultHandle, ecHandle, executor.MemPtr(dataOffset), length) -} - -//export v1_5_managedUnmarshalCompressedEC -func v1_5_managedUnmarshalCompressedEC(context unsafe.Pointer, xResultHandle int32, yResultHandle int32, ecHandle int32, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedUnmarshalCompressedEC(xResultHandle, yResultHandle, ecHandle, dataHandle) -} - -//export v1_5_generateKeyEC -func v1_5_generateKeyEC(context unsafe.Pointer, xPubKeyHandle int32, yPubKeyHandle int32, ecHandle int32, resultOffset int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GenerateKeyEC(xPubKeyHandle, yPubKeyHandle, ecHandle, executor.MemPtr(resultOffset)) -} - -//export v1_5_managedGenerateKeyEC -func v1_5_managedGenerateKeyEC(context unsafe.Pointer, xPubKeyHandle int32, yPubKeyHandle int32, ecHandle int32, resultHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedGenerateKeyEC(xPubKeyHandle, yPubKeyHandle, ecHandle, resultHandle) -} - -//export v1_5_createEC -func v1_5_createEC(context unsafe.Pointer, dataOffset int32, dataLength int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.CreateEC(executor.MemPtr(dataOffset), dataLength) -} - -//export v1_5_managedCreateEC -func v1_5_managedCreateEC(context unsafe.Pointer, dataHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedCreateEC(dataHandle) -} - -//export v1_5_getCurveLengthEC -func v1_5_getCurveLengthEC(context unsafe.Pointer, ecHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetCurveLengthEC(ecHandle) -} - -//export v1_5_getPrivKeyByteLengthEC -func v1_5_getPrivKeyByteLengthEC(context unsafe.Pointer, ecHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.GetPrivKeyByteLengthEC(ecHandle) -} - -//export v1_5_ellipticCurveGetValues -func v1_5_ellipticCurveGetValues(context unsafe.Pointer, ecHandle int32, fieldOrderHandle int32, basePointOrderHandle int32, eqConstantHandle int32, xBasePointHandle int32, yBasePointHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.EllipticCurveGetValues(ecHandle, fieldOrderHandle, basePointOrderHandle, eqConstantHandle, xBasePointHandle, yBasePointHandle) -} - -//export v1_5_managedVerifySecp256r1 -func v1_5_managedVerifySecp256r1(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifySecp256r1(keyHandle, messageHandle, sigHandle) -} - -//export v1_5_managedVerifyBLSSignatureShare -func v1_5_managedVerifyBLSSignatureShare(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifyBLSSignatureShare(keyHandle, messageHandle, sigHandle) -} - -//export v1_5_managedVerifyBLSAggregatedSignature -func v1_5_managedVerifyBLSAggregatedSignature(context unsafe.Pointer, keyHandle int32, messageHandle int32, sigHandle int32) int32 { - vmHooks := getVMHooksFromContextRawPtr(context) - return vmHooks.ManagedVerifyBLSAggregatedSignature(keyHandle, messageHandle, sigHandle) -} diff --git a/wasmer/wasmerImportsCgoHelper.go b/wasmer/wasmerImportsCgoHelper.go deleted file mode 100644 index 74efeceef..000000000 --- a/wasmer/wasmerImportsCgoHelper.go +++ /dev/null @@ -1,98 +0,0 @@ -package wasmer - -import ( - "unsafe" - - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-go/executor" -) - -//nolint:all -func getVMHooksFromContextRawPtr(contextPtr unsafe.Pointer) executor.VMHooks { - instCtx := IntoInstanceContext(contextPtr) - vmHooksPtr := *(*uintptr)(instCtx.Data()) - return *(*executor.VMHooks)(unsafe.Pointer(vmHooksPtr)) -} - -func injectCgoFunctionPointers() (vmcommon.FunctionNames, error) { - importsInfo := newWasmerImports() - defer importsInfo.Close() - - err := populateWasmerImports(importsInfo) - if err != nil { - return nil, err - } - - wasmImportsCPointer, numberOfImports := generateWasmerImports(importsInfo) - - var result = cWasmerCacheImportObjectFromImports( - wasmImportsCPointer, - cInt(numberOfImports), - ) - - if result != cWasmerOk { - return nil, newWrappedError(ErrFailedCacheImports) - } - - return extractImportNames(importsInfo), nil -} - -func extractImportNames(imports *wasmerImports) vmcommon.FunctionNames { - names := make(vmcommon.FunctionNames) - var empty struct{} - for _, env := range imports.imports { - for name := range env { - names[name] = empty - } - } - return names -} - -func generateWasmerImports(imports *wasmerImports) (*cWasmerImportT, int) { - var numberOfImports = imports.Count() - var wasmImports = make([]cWasmerImportT, numberOfImports) - var importFunctionNth = 0 - - for _, namespacedImports := range imports.imports { - for importName, importFunction := range namespacedImports { - var wasmInputsArity = len(importFunction.wasmInputs) - var wasmOutputsArity = len(importFunction.wasmOutputs) - - var importFunctionInputsCPointer *cWasmerValueTag - var importFunctionOutputsCPointer *cWasmerValueTag - - if wasmInputsArity > 0 { - importFunctionInputsCPointer = (*cWasmerValueTag)(unsafe.Pointer(&importFunction.wasmInputs[0])) - } - - if wasmOutputsArity > 0 { - importFunctionOutputsCPointer = (*cWasmerValueTag)(unsafe.Pointer(&importFunction.wasmOutputs[0])) - } - - importFunction.importedFunctionPointer = cWasmerImportFuncNew( - importFunction.cgoPointer, - importFunctionInputsCPointer, - cUint(wasmInputsArity), - importFunctionOutputsCPointer, - cUint(wasmOutputsArity), - ) - - var importedFunction = cNewWasmerImportT( - importFunction.namespace, - importName, - importFunction.importedFunctionPointer, - ) - - wasmImports[importFunctionNth] = importedFunction - importFunctionNth++ - } - } - - var wasmImportsCPointer *cWasmerImportT - - if numberOfImports > 0 { - wasmImportsCPointer = (*cWasmerImportT)(unsafe.Pointer(&wasmImports[0])) - } - - return wasmImportsCPointer, numberOfImports -} diff --git a/wasmer/wasmerInstance.go b/wasmer/wasmerInstance.go deleted file mode 100644 index cd147ea14..000000000 --- a/wasmer/wasmerInstance.go +++ /dev/null @@ -1,395 +0,0 @@ -package wasmer - -// #include -import "C" -import ( - "fmt" - "unsafe" - - "github.com/multiversx/mx-chain-vm-go/executor" -) - -// InstanceError represents any kind of errors related to a WebAssembly instance. It -// is returned by `Instance` functions only. -type InstanceError struct { - // Error message. - message string -} - -// NewInstanceError constructs a new `InstanceError`. -func NewInstanceError(message string) *InstanceError { - return &InstanceError{message} -} - -// `InstanceError` is an actual error. The `Error` function returns -// the error message. -func (error *InstanceError) Error() string { - return error.message -} - -// ExportedFunctionError represents any kind of errors related to a -// WebAssembly exported function. It is returned by `Instance` -// functions only. -type ExportedFunctionError struct { - functionName string - message string -} - -// ExportedFunctionSignature holds information about the input/output arities -// of an exported function -type ExportedFunctionSignature struct { - InputArity int - OutputArity int -} - -// NewExportedFunctionError constructs a new `ExportedFunctionError`, -// where `functionName` is the name of the exported function, and -// `message` is the error message. If the error message contains `%s`, -// then this parameter will be replaced by `functionName`. -func NewExportedFunctionError(functionName string, message string) *ExportedFunctionError { - return &ExportedFunctionError{functionName, message} -} - -// ExportedFunctionError is an actual error. The `Error` function -// returns the error message. -func (error *ExportedFunctionError) Error() string { - return error.message -} - -// ExportsMap is a map of names to ExportedFunctionCallInfo values -type ExportsMap map[string]*ExportedFunctionCallInfo - -// ExportSignaturesMap is a map of names to ExportedFunctionSignatures -type ExportSignaturesMap map[string]*ExportedFunctionSignature - -// ExportedFunctionCallInfo contains information required to call an exported WASM function -type ExportedFunctionCallInfo struct { - FuncName string - InputArity cUint32T - InputSignature []cWasmerValueTag - OutputArity cUint32T -} - -// WasmerInstance represents a WebAssembly instance. -type WasmerInstance struct { - // The underlying WebAssembly instance. - instance *cWasmerInstanceT - - AlreadyClean bool - - // All functions exported by the WebAssembly instance, indexed - // by their name as a string. An exported function is a - // regular variadic Go closure. Arguments are untyped. Since - // WebAssembly only supports: `i32`, `i64`, `f32` and `f64` - // types, the accepted Go types are: `int8`, `uint8`, `int16`, - // `uint16`, `int32`, `uint32`, `int64`, `int`, `uint`, `float32` - // and `float64`. In addition to those types, the `Value` type - // (from this project) is accepted. The conversion from a Go - // value to a WebAssembly value is done automatically except for - // the `Value` type (where type is coerced, that's the intent - // here). The WebAssembly type is automatically inferred. Note - // that the returned value is of kind `Value`, and not a - // standard Go type. - exports ExportsMap - - signatures ExportSignaturesMap - - // The exported memory of a WebAssembly instance. - Memory executor.Memory - - // The instance context. - InstanceCtx InstanceContext - - vmHooksPtr unsafe.Pointer -} - -func newWrappedError(target error) error { - var lastError string - var err error - lastError, err = GetLastError() - - if err != nil { - lastError = "unknown details" - } - - return fmt.Errorf("%w: %s", target, lastError) -} - -// NewInstanceWithOptions creates a new instance from provided bytes & options -func NewInstanceWithOptions( - bytes []byte, - options executor.CompilationOptions, -) (*WasmerInstance, error) { - var cInstance *cWasmerInstanceT - - if len(bytes) == 0 { - var emptyInstance = &WasmerInstance{instance: nil, exports: nil, Memory: nil} - return emptyInstance, newWrappedError(ErrInvalidBytecode) - } - - cOptions := unsafe.Pointer(&options) - var compileResult = cWasmerInstantiateWithOptions( - &cInstance, - (*cUchar)(unsafe.Pointer(&bytes[0])), - cUint(len(bytes)), - (*cWasmerCompilationOptions)(cOptions), - ) - - if compileResult != cWasmerOk { - var emptyInstance = &WasmerInstance{instance: nil, exports: nil, Memory: nil} - return emptyInstance, newWrappedError(ErrFailedInstantiation) - } - - instance, err := newInstance(cInstance) - if instance != nil && instance.Memory != nil { - cInstanceContext := cWasmerInstanceContextGet(cInstance) - instance.InstanceCtx = IntoInstanceContextDirect(cInstanceContext) - } - - logWasmer.Trace("new instance created", "id", instance.ID()) - return instance, err -} - -func newInstance(cInstance *cWasmerInstanceT) (*WasmerInstance, error) { - var emptyInstance = &WasmerInstance{instance: nil, exports: nil, signatures: nil, Memory: nil} - - var wasmExports *cWasmerExportsT - var hasMemory bool - - cWasmerInstanceExports(cInstance, &wasmExports) - defer cWasmerExportsDestroy(wasmExports) - - exports, signatures, err := retrieveExportedFunctions(cInstance, wasmExports) - if err != nil { - return emptyInstance, err - } - - memory, hasMemory, err := retrieveExportedMemory(wasmExports) - if err != nil { - return emptyInstance, err - } - - if !hasMemory { - return &WasmerInstance{instance: cInstance, exports: exports, signatures: signatures, Memory: nil}, nil - } - - return &WasmerInstance{instance: cInstance, exports: exports, signatures: signatures, Memory: &memory}, nil -} - -// NewInstanceFromCompiledCodeWithOptions creates a new instance from compiled code -func NewInstanceFromCompiledCodeWithOptions( - compiledCode []byte, - options executor.CompilationOptions, -) (*WasmerInstance, error) { - var cInstance *cWasmerInstanceT - - if len(compiledCode) == 0 { - var emptyInstance = &WasmerInstance{instance: nil, exports: nil, Memory: nil} - return emptyInstance, newWrappedError(ErrInvalidBytecode) - } - - cOptions := unsafe.Pointer(&options) - var instantiateResult = cWasmerInstanceFromCache( - &cInstance, - (*cUchar)(unsafe.Pointer(&compiledCode[0])), - cUint32T(len(compiledCode)), - (*cWasmerCompilationOptions)(cOptions), - ) - - if instantiateResult != cWasmerOk { - var emptyInstance = &WasmerInstance{instance: nil, exports: nil, Memory: nil} - return emptyInstance, newWrappedError(ErrFailedInstantiation) - } - - instance, err := newInstance(cInstance) - if instance != nil && instance.Memory != nil { - cInstanceContext := cWasmerInstanceContextGet(cInstance) - instance.InstanceCtx = IntoInstanceContextDirect(cInstanceContext) - } - - return instance, err -} - -// Clean cleans instance -func (instance *WasmerInstance) Clean() bool { - logWasmer.Trace("cleaning instance", "id", instance.ID()) - if instance.AlreadyClean { - logWasmer.Trace("clean: already cleaned instance", "id", instance.ID()) - return false - } - - if instance.instance != nil { - cWasmerInstanceDestroy(instance.instance) - - if instance.Memory != nil { - instance.Memory.Destroy() - } - - instance.AlreadyClean = true - logWasmer.Trace("cleaned instance", "id", instance.ID()) - - return true - } - - return false -} - -// IsAlreadyCleaned returns the internal field AlreadyClean -func (instance *WasmerInstance) IsAlreadyCleaned() bool { - return instance.AlreadyClean -} - -// GetPointsUsed returns the internal instance gas counter -func (instance *WasmerInstance) GetPointsUsed() uint64 { - return cWasmerInstanceGetPointsUsed(instance.instance) -} - -// SetPointsUsed sets the internal instance gas counter -func (instance *WasmerInstance) SetPointsUsed(points uint64) { - cWasmerInstanceSetPointsUsed(instance.instance, points) -} - -// SetGasLimit sets the gas limit for the instance -func (instance *WasmerInstance) SetGasLimit(gasLimit uint64) { - cWasmerInstanceSetGasLimit(instance.instance, gasLimit) -} - -// SetBreakpointValue sets the breakpoint value for the instance -func (instance *WasmerInstance) SetBreakpointValue(value uint64) { - cWasmerInstanceSetBreakpointValue(instance.instance, value) -} - -// GetBreakpointValue returns the breakpoint value -func (instance *WasmerInstance) GetBreakpointValue() uint64 { - return cWasmerInstanceGetBreakpointValue(instance.instance) -} - -// Cache caches the instance -func (instance *WasmerInstance) Cache() ([]byte, error) { - var cacheBytes *cUchar - var cacheLen cUint32T - - var cacheResult = cWasmerInstanceCache( - instance.instance, - &cacheBytes, - &cacheLen, - ) - - if cacheResult != cWasmerOk { - return nil, ErrCachingFailed - } - - goBytes := C.GoBytes(unsafe.Pointer(cacheBytes), C.int(cacheLen)) - - C.free(unsafe.Pointer(cacheBytes)) - cacheBytes = nil - return goBytes, nil -} - -// IsFunctionImported returns true if the instance imports the specified function -func (instance *WasmerInstance) IsFunctionImported(name string) bool { - return cWasmerInstanceIsFunctionImported(instance.instance, name) -} - -// CallFunction executes given function from loaded contract. -func (instance *WasmerInstance) CallFunction(functionName string) error { - callInfo, found := instance.exports[functionName] - if !found { - return executor.ErrFuncNotFound - } - - return callExportedFunction(instance.instance, callInfo) -} - -// HasFunction checks if loaded contract has a function (endpoint) with given name. -func (instance *WasmerInstance) HasFunction(functionName string) bool { - _, ok := instance.exports[functionName] - return ok -} - -// GetFunctionNames loads a list of contract function (endpoint) names. Required for validating reserved names. -func (instance *WasmerInstance) GetFunctionNames() []string { - var functionNames []string - for functionName := range instance.exports { - functionNames = append(functionNames, functionName) - } - return functionNames -} - -// ValidateFunctionArities checks that no function (endpoint) of the given contract has any parameters or returns any result. -// All arguments and results should be transferred via the import functions. -func (instance *WasmerInstance) ValidateFunctionArities() error { - for functionName := range instance.exports { - err := instance.verifyVoidFunction(functionName) - if err != nil { - return err - } - } - return nil -} - -// HasMemory checks whether the instance has at least one exported memory. -func (instance *WasmerInstance) HasMemory() bool { - return nil != instance.Memory -} - -// MemLoad returns the contents from the given offset of the WASM memory. -func (instance *WasmerInstance) MemLoad(memPtr executor.MemPtr, length executor.MemLength) ([]byte, error) { - return executor.MemLoadFromMemory(instance.Memory, memPtr, length) -} - -// MemStore stores the given data in the WASM memory at the given offset. -func (instance *WasmerInstance) MemStore(memPtr executor.MemPtr, data []byte) error { - return executor.MemStoreToMemory(instance.Memory, memPtr, data) -} - -// MemLength returns the length of the allocated memory. Only called directly in tests. -func (instance *WasmerInstance) MemLength() uint32 { - return instance.Memory.Length() -} - -// MemGrow allocates more pages to the current memory. Only called directly in tests. -func (instance *WasmerInstance) MemGrow(pages uint32) error { - return instance.Memory.Grow(pages) -} - -// MemDump yields the entire contents of the memory. Only used in tests. -func (instance *WasmerInstance) MemDump() []byte { - return instance.Memory.Data() -} - -// Reset resets the instance memories and globals -func (instance *WasmerInstance) Reset() bool { - if instance.AlreadyClean { - logWasmer.Trace("reset: already cleaned instance", "id", instance.ID()) - return false - } - - result := cWasmerInstanceReset(instance.instance) - ok := result == cWasmerOk - - logWasmer.Trace("reset: warm instance", "id", instance.ID(), "ok", ok) - return ok -} - -// IsInterfaceNil returns true if underlying object is nil -func (instance *WasmerInstance) IsInterfaceNil() bool { - return instance == nil -} - -// SetVMHooksPtr sets the VM hooks pointer -func (instance *WasmerInstance) SetVMHooksPtr(vmHooksPtr uintptr) { - localVMHooksPointer := unsafe.Pointer(&vmHooksPtr) - instance.vmHooksPtr = localVMHooksPointer - cWasmerInstanceContextDataSet(instance.instance, localVMHooksPointer) -} - -// GetVMHooksPtr returns the VM hooks pointer -func (instance *WasmerInstance) GetVMHooksPtr() uintptr { - return *(*uintptr)(instance.vmHooksPtr) -} - -// ID returns an identifier for the instance, unique at runtime -func (instance *WasmerInstance) ID() string { - return fmt.Sprintf("%p", instance.instance) -} diff --git a/wasmer/wasmerInstanceHelpers.go b/wasmer/wasmerInstanceHelpers.go deleted file mode 100644 index d7edbb39a..000000000 --- a/wasmer/wasmerInstanceHelpers.go +++ /dev/null @@ -1,131 +0,0 @@ -package wasmer - -import ( - "fmt" - "unsafe" -) - -func retrieveExportedMemory(wasmExports *cWasmerExportsT) (Memory, bool, error) { - var numberOfExports = int(cWasmerExportsLen(wasmExports)) - - var memory Memory - var hasMemory = false - - for nth := 0; nth < numberOfExports; nth++ { - var wasmExport = cWasmerExportsGet(wasmExports, cInt(nth)) - var wasmExportKind = cWasmerExportKind(wasmExport) - - if wasmExportKind == cWasmMemory { - var wasmMemory *cWasmerMemoryT - - if cWasmerExportToMemory(wasmExport, &wasmMemory) != cWasmerOk { - var emptyMemory Memory - return emptyMemory, false, NewInstanceError("Failed to extract the exported memory.") - } - - memory = newMemory(wasmMemory) - hasMemory = true - } - } - - return memory, hasMemory, nil -} - -func retrieveExportedFunctions( - cInstance *cWasmerInstanceT, - wasmExports *cWasmerExportsT, -) (ExportsMap, ExportSignaturesMap, error) { - var exports = make(ExportsMap) - var signatures = make(ExportSignaturesMap) - - var numberOfExports = int(cWasmerExportsLen(wasmExports)) - - for nth := 0; nth < numberOfExports; nth++ { - var wasmExport = cWasmerExportsGet(wasmExports, cInt(nth)) - var wasmExportKind = cWasmerExportKind(wasmExport) - - if wasmExportKind != cWasmFunction { - continue - } - - var wasmExportName = cWasmerExportName(wasmExport) - var wasmFunction = cWasmerExportToFunc(wasmExport) - var exportedFunctionName = cGoStringN((*cChar)(unsafe.Pointer(wasmExportName.bytes)), (cInt)(wasmExportName.bytes_len)) - - callInfo, err := createExportedFunctionCallInfo(wasmFunction, exportedFunctionName) - if err != nil { - return nil, nil, err - } - - signature := &ExportedFunctionSignature{ - InputArity: int(callInfo.InputArity), - OutputArity: int(callInfo.OutputArity), - } - - exports[exportedFunctionName] = callInfo - signatures[exportedFunctionName] = signature - } - - return exports, signatures, nil -} - -func createExportedFunctionCallInfo( - wasmFunction *cWasmerExportFuncT, - exportedFunctionName string, -) (*ExportedFunctionCallInfo, error) { - - wasmFunctionInputSignatures, wasmFunctionInputsArity, err := getExportedFunctionSignature(wasmFunction, exportedFunctionName) - if err != nil { - return nil, err - } - - wasmFunctionOutputsArity, err := getExportedFunctionOutputArity(wasmFunction, exportedFunctionName) - if err != nil { - return nil, err - } - - callInfo := &ExportedFunctionCallInfo{ - FuncName: exportedFunctionName, - InputArity: wasmFunctionInputsArity, - InputSignature: wasmFunctionInputSignatures, - OutputArity: wasmFunctionOutputsArity, - } - - return callInfo, nil -} - -func callExportedFunction( - cInstance *cWasmerInstanceT, - callInfo *ExportedFunctionCallInfo, - arguments ...interface{}, -) error { - err := validateGivenArguments(callInfo.FuncName, arguments, callInfo.InputArity) - if err != nil { - return err - } - - var wasmInputs []cWasmerValueT - wasmInputs, err = createWasmInputsFromArguments( - arguments, - callInfo.InputArity, - callInfo.InputSignature, - callInfo.FuncName) - if err != nil { - return err - } - - _, callResult := callWasmFunction( - cInstance, - callInfo.FuncName, - callInfo.InputArity, - callInfo.OutputArity, - wasmInputs, - ) - - if callResult != cWasmerOk { - err = fmt.Errorf("failed to call the `%s` exported function", callInfo.FuncName) - return newWrappedError(err) - } - - return nil -} diff --git a/wasmer/wasmerInstanceValidate.go b/wasmer/wasmerInstanceValidate.go deleted file mode 100644 index a7d5870f4..000000000 --- a/wasmer/wasmerInstanceValidate.go +++ /dev/null @@ -1,49 +0,0 @@ -package wasmer - -import ( - "fmt" - - "github.com/multiversx/mx-chain-vm-go/executor" -) - -const noArity = -1 - -// getSignature returns the signature for the given functionName -func (instance *WasmerInstance) getSignature(functionName string) (*ExportedFunctionSignature, bool) { - signature, ok := instance.signatures[functionName] - return signature, ok -} - -func (instance *WasmerInstance) verifyVoidFunction(functionName string) error { - inArity, err := instance.getInputArity(functionName) - if err != nil { - return err - } - - outArity, err := instance.getOutputArity(functionName) - if err != nil { - return err - } - - isVoid := inArity == 0 && outArity == 0 - if !isVoid { - return fmt.Errorf("%w: %s", executor.ErrFunctionNonvoidSignature, functionName) - } - return nil -} - -func (instance *WasmerInstance) getInputArity(functionName string) (int, error) { - signature, ok := instance.getSignature(functionName) - if !ok { - return noArity, fmt.Errorf("%w: %s", executor.ErrFuncNotFound, functionName) - } - return signature.InputArity, nil -} - -func (instance *WasmerInstance) getOutputArity(functionName string) (int, error) { - signature, ok := instance.getSignature(functionName) - if !ok { - return noArity, fmt.Errorf("%w: %s", executor.ErrFuncNotFound, functionName) - } - return signature.OutputArity, nil -} diff --git a/wasmer/wasmerInstanceValidate_test.go b/wasmer/wasmerInstanceValidate_test.go deleted file mode 100644 index b8abaa987..000000000 --- a/wasmer/wasmerInstanceValidate_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package wasmer - -import ( - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/multiversx/mx-chain-vm-go/executor" - "github.com/stretchr/testify/require" -) - -// GetSCCode retrieves the bytecode of a WASM module from a file. -func getSCCode(fileName string) []byte { - code, err := os.ReadFile(filepath.Clean(fileName)) - if err != nil { - panic(fmt.Sprintf("GetSCCode(): %s", fileName)) - } - return code -} - -func TestFunctionsGuard_Arity(t *testing.T) { - if os.Getenv("VMEXECUTOR") != "wasmer1" { - t.Skip("run exclusively with wasmer1") - } - - // Empty imports on purpose. - // We have currently no access to the vmhooks package here, due to cyclic imports. - // Fortunately, imports are not necessary for this test. - _, err := injectCgoFunctionPointers() - require.Nil(t, err) - - gasLimit := uint64(100000000) - path := "./../test/contracts/signatures/output/signatures.wasm" - contractCode := getSCCode(path) - options := executor.CompilationOptions{ - GasLimit: gasLimit, - OpcodeTrace: false, - Metering: true, - RuntimeBreakpoints: true, - } - instance, err := NewInstanceWithOptions(contractCode, options) - require.Nil(t, err) - - inArity, _ := instance.getInputArity("goodFunction") - require.Equal(t, 0, inArity) - - outArity, _ := instance.getOutputArity("goodFunction") - require.Equal(t, 0, outArity) - - inArity, _ = instance.getInputArity("wrongReturn") - require.Equal(t, 0, inArity) - - outArity, _ = instance.getOutputArity("wrongReturn") - require.Equal(t, 1, outArity) - - inArity, _ = instance.getInputArity("wrongParams") - require.Equal(t, 1, inArity) - - outArity, _ = instance.getOutputArity("wrongParams") - require.Equal(t, 0, outArity) - - inArity, _ = instance.getInputArity("wrongParamsAndReturn") - require.Equal(t, 2, inArity) - - outArity, _ = instance.getOutputArity("wrongParamsAndReturn") - require.Equal(t, 1, outArity) - - err = instance.verifyVoidFunction("goodFunction") - require.Nil(t, err) - - err = instance.verifyVoidFunction("wrongReturn") - require.NotNil(t, err) - - err = instance.verifyVoidFunction("wrongParams") - require.NotNil(t, err) - - err = instance.verifyVoidFunction("wrongParamsAndReturn") - require.NotNil(t, err) -} diff --git a/wasmer/wasmerOpcodeCostsArray.go b/wasmer/wasmerOpcodeCostsArray.go deleted file mode 100644 index ec17bc5be..000000000 --- a/wasmer/wasmerOpcodeCostsArray.go +++ /dev/null @@ -1,918 +0,0 @@ -package wasmer - -import ( - "github.com/multiversx/mx-chain-vm-go/executor" -) - -// OpcodeCount is the number of opcodes that we account for when setting gas costs. -const opcodeCount = 448 - -// opcodes list -const ( - OpcodeUnreachable = iota - OpcodeNop - OpcodeBlock - OpcodeLoop - OpcodeIf - OpcodeElse - OpcodeEnd - OpcodeBr - OpcodeBrIf - OpcodeBrTable - OpcodeReturn - OpcodeCall - OpcodeCallIndirect - OpcodeDrop - OpcodeSelect - OpcodeTypedSelect - OpcodeLocalGet - OpcodeLocalSet - OpcodeLocalTee - OpcodeGlobalGet - OpcodeGlobalSet - OpcodeI32Load - OpcodeI64Load - OpcodeF32Load - OpcodeF64Load - OpcodeI32Load8S - OpcodeI32Load8U - OpcodeI32Load16S - OpcodeI32Load16U - OpcodeI64Load8S - OpcodeI64Load8U - OpcodeI64Load16S - OpcodeI64Load16U - OpcodeI64Load32S - OpcodeI64Load32U - OpcodeI32Store - OpcodeI64Store - OpcodeF32Store - OpcodeF64Store - OpcodeI32Store8 - OpcodeI32Store16 - OpcodeI64Store8 - OpcodeI64Store16 - OpcodeI64Store32 - OpcodeMemorySize - OpcodeMemoryGrow - OpcodeI32Const - OpcodeI64Const - OpcodeF32Const - OpcodeF64Const - OpcodeRefNull - OpcodeRefIsNull - OpcodeRefFunc - OpcodeI32Eqz - OpcodeI32Eq - OpcodeI32Ne - OpcodeI32LtS - OpcodeI32LtU - OpcodeI32GtS - OpcodeI32GtU - OpcodeI32LeS - OpcodeI32LeU - OpcodeI32GeS - OpcodeI32GeU - OpcodeI64Eqz - OpcodeI64Eq - OpcodeI64Ne - OpcodeI64LtS - OpcodeI64LtU - OpcodeI64GtS - OpcodeI64GtU - OpcodeI64LeS - OpcodeI64LeU - OpcodeI64GeS - OpcodeI64GeU - OpcodeF32Eq - OpcodeF32Ne - OpcodeF32Lt - OpcodeF32Gt - OpcodeF32Le - OpcodeF32Ge - OpcodeF64Eq - OpcodeF64Ne - OpcodeF64Lt - OpcodeF64Gt - OpcodeF64Le - OpcodeF64Ge - OpcodeI32Clz - OpcodeI32Ctz - OpcodeI32Popcnt - OpcodeI32Add - OpcodeI32Sub - OpcodeI32Mul - OpcodeI32DivS - OpcodeI32DivU - OpcodeI32RemS - OpcodeI32RemU - OpcodeI32And - OpcodeI32Or - OpcodeI32Xor - OpcodeI32Shl - OpcodeI32ShrS - OpcodeI32ShrU - OpcodeI32Rotl - OpcodeI32Rotr - OpcodeI64Clz - OpcodeI64Ctz - OpcodeI64Popcnt - OpcodeI64Add - OpcodeI64Sub - OpcodeI64Mul - OpcodeI64DivS - OpcodeI64DivU - OpcodeI64RemS - OpcodeI64RemU - OpcodeI64And - OpcodeI64Or - OpcodeI64Xor - OpcodeI64Shl - OpcodeI64ShrS - OpcodeI64ShrU - OpcodeI64Rotl - OpcodeI64Rotr - OpcodeF32Abs - OpcodeF32Neg - OpcodeF32Ceil - OpcodeF32Floor - OpcodeF32Trunc - OpcodeF32Nearest - OpcodeF32Sqrt - OpcodeF32Add - OpcodeF32Sub - OpcodeF32Mul - OpcodeF32Div - OpcodeF32Min - OpcodeF32Max - OpcodeF32Copysign - OpcodeF64Abs - OpcodeF64Neg - OpcodeF64Ceil - OpcodeF64Floor - OpcodeF64Trunc - OpcodeF64Nearest - OpcodeF64Sqrt - OpcodeF64Add - OpcodeF64Sub - OpcodeF64Mul - OpcodeF64Div - OpcodeF64Min - OpcodeF64Max - OpcodeF64Copysign - OpcodeI32WrapI64 - OpcodeI32TruncF32S - OpcodeI32TruncF32U - OpcodeI32TruncF64S - OpcodeI32TruncF64U - OpcodeI64ExtendI32S - OpcodeI64ExtendI32U - OpcodeI64TruncF32S - OpcodeI64TruncF32U - OpcodeI64TruncF64S - OpcodeI64TruncF64U - OpcodeF32ConvertI32S - OpcodeF32ConvertI32U - OpcodeF32ConvertI64S - OpcodeF32ConvertI64U - OpcodeF32DemoteF64 - OpcodeF64ConvertI32S - OpcodeF64ConvertI32U - OpcodeF64ConvertI64S - OpcodeF64ConvertI64U - OpcodeF64PromoteF32 - OpcodeI32ReinterpretF32 - OpcodeI64ReinterpretF64 - OpcodeF32ReinterpretI32 - OpcodeF64ReinterpretI64 - OpcodeI32Extend8S - OpcodeI32Extend16S - OpcodeI64Extend8S - OpcodeI64Extend16S - OpcodeI64Extend32S - OpcodeI32TruncSatF32S - OpcodeI32TruncSatF32U - OpcodeI32TruncSatF64S - OpcodeI32TruncSatF64U - OpcodeI64TruncSatF32S - OpcodeI64TruncSatF32U - OpcodeI64TruncSatF64S - OpcodeI64TruncSatF64U - OpcodeMemoryInit - OpcodeDataDrop - OpcodeMemoryCopy - OpcodeMemoryFill - OpcodeTableInit - OpcodeElemDrop - OpcodeTableCopy - OpcodeTableFill - OpcodeTableGet - OpcodeTableSet - OpcodeTableGrow - OpcodeTableSize - OpcodeAtomicNotify - OpcodeI32AtomicWait - OpcodeI64AtomicWait - OpcodeAtomicFence - OpcodeI32AtomicLoad - OpcodeI64AtomicLoad - OpcodeI32AtomicLoad8U - OpcodeI32AtomicLoad16U - OpcodeI64AtomicLoad8U - OpcodeI64AtomicLoad16U - OpcodeI64AtomicLoad32U - OpcodeI32AtomicStore - OpcodeI64AtomicStore - OpcodeI32AtomicStore8 - OpcodeI32AtomicStore16 - OpcodeI64AtomicStore8 - OpcodeI64AtomicStore16 - OpcodeI64AtomicStore32 - OpcodeI32AtomicRmwAdd - OpcodeI64AtomicRmwAdd - OpcodeI32AtomicRmw8AddU - OpcodeI32AtomicRmw16AddU - OpcodeI64AtomicRmw8AddU - OpcodeI64AtomicRmw16AddU - OpcodeI64AtomicRmw32AddU - OpcodeI32AtomicRmwSub - OpcodeI64AtomicRmwSub - OpcodeI32AtomicRmw8SubU - OpcodeI32AtomicRmw16SubU - OpcodeI64AtomicRmw8SubU - OpcodeI64AtomicRmw16SubU - OpcodeI64AtomicRmw32SubU - OpcodeI32AtomicRmwAnd - OpcodeI64AtomicRmwAnd - OpcodeI32AtomicRmw8AndU - OpcodeI32AtomicRmw16AndU - OpcodeI64AtomicRmw8AndU - OpcodeI64AtomicRmw16AndU - OpcodeI64AtomicRmw32AndU - OpcodeI32AtomicRmwOr - OpcodeI64AtomicRmwOr - OpcodeI32AtomicRmw8OrU - OpcodeI32AtomicRmw16OrU - OpcodeI64AtomicRmw8OrU - OpcodeI64AtomicRmw16OrU - OpcodeI64AtomicRmw32OrU - OpcodeI32AtomicRmwXor - OpcodeI64AtomicRmwXor - OpcodeI32AtomicRmw8XorU - OpcodeI32AtomicRmw16XorU - OpcodeI64AtomicRmw8XorU - OpcodeI64AtomicRmw16XorU - OpcodeI64AtomicRmw32XorU - OpcodeI32AtomicRmwXchg - OpcodeI64AtomicRmwXchg - OpcodeI32AtomicRmw8XchgU - OpcodeI32AtomicRmw16XchgU - OpcodeI64AtomicRmw8XchgU - OpcodeI64AtomicRmw16XchgU - OpcodeI64AtomicRmw32XchgU - OpcodeI32AtomicRmwCmpxchg - OpcodeI64AtomicRmwCmpxchg - OpcodeI32AtomicRmw8CmpxchgU - OpcodeI32AtomicRmw16CmpxchgU - OpcodeI64AtomicRmw8CmpxchgU - OpcodeI64AtomicRmw16CmpxchgU - OpcodeI64AtomicRmw32CmpxchgU - OpcodeV128Load - OpcodeV128Store - OpcodeV128Const - OpcodeI8x16Splat - OpcodeI8x16ExtractLaneS - OpcodeI8x16ExtractLaneU - OpcodeI8x16ReplaceLane - OpcodeI16x8Splat - OpcodeI16x8ExtractLaneS - OpcodeI16x8ExtractLaneU - OpcodeI16x8ReplaceLane - OpcodeI32x4Splat - OpcodeI32x4ExtractLane - OpcodeI32x4ReplaceLane - OpcodeI64x2Splat - OpcodeI64x2ExtractLane - OpcodeI64x2ReplaceLane - OpcodeF32x4Splat - OpcodeF32x4ExtractLane - OpcodeF32x4ReplaceLane - OpcodeF64x2Splat - OpcodeF64x2ExtractLane - OpcodeF64x2ReplaceLane - OpcodeI8x16Eq - OpcodeI8x16Ne - OpcodeI8x16LtS - OpcodeI8x16LtU - OpcodeI8x16GtS - OpcodeI8x16GtU - OpcodeI8x16LeS - OpcodeI8x16LeU - OpcodeI8x16GeS - OpcodeI8x16GeU - OpcodeI16x8Eq - OpcodeI16x8Ne - OpcodeI16x8LtS - OpcodeI16x8LtU - OpcodeI16x8GtS - OpcodeI16x8GtU - OpcodeI16x8LeS - OpcodeI16x8LeU - OpcodeI16x8GeS - OpcodeI16x8GeU - OpcodeI32x4Eq - OpcodeI32x4Ne - OpcodeI32x4LtS - OpcodeI32x4LtU - OpcodeI32x4GtS - OpcodeI32x4GtU - OpcodeI32x4LeS - OpcodeI32x4LeU - OpcodeI32x4GeS - OpcodeI32x4GeU - OpcodeF32x4Eq - OpcodeF32x4Ne - OpcodeF32x4Lt - OpcodeF32x4Gt - OpcodeF32x4Le - OpcodeF32x4Ge - OpcodeF64x2Eq - OpcodeF64x2Ne - OpcodeF64x2Lt - OpcodeF64x2Gt - OpcodeF64x2Le - OpcodeF64x2Ge - OpcodeV128Not - OpcodeV128And - OpcodeV128AndNot - OpcodeV128Or - OpcodeV128Xor - OpcodeV128Bitselect - OpcodeI8x16Neg - OpcodeI8x16AnyTrue - OpcodeI8x16AllTrue - OpcodeI8x16Shl - OpcodeI8x16ShrS - OpcodeI8x16ShrU - OpcodeI8x16Add - OpcodeI8x16AddSaturateS - OpcodeI8x16AddSaturateU - OpcodeI8x16Sub - OpcodeI8x16SubSaturateS - OpcodeI8x16SubSaturateU - OpcodeI8x16MinS - OpcodeI8x16MinU - OpcodeI8x16MaxS - OpcodeI8x16MaxU - OpcodeI8x16Mul - OpcodeI16x8Neg - OpcodeI16x8AnyTrue - OpcodeI16x8AllTrue - OpcodeI16x8Shl - OpcodeI16x8ShrS - OpcodeI16x8ShrU - OpcodeI16x8Add - OpcodeI16x8AddSaturateS - OpcodeI16x8AddSaturateU - OpcodeI16x8Sub - OpcodeI16x8SubSaturateS - OpcodeI16x8SubSaturateU - OpcodeI16x8Mul - OpcodeI16x8MinS - OpcodeI16x8MinU - OpcodeI16x8MaxS - OpcodeI16x8MaxU - OpcodeI32x4Neg - OpcodeI32x4AnyTrue - OpcodeI32x4AllTrue - OpcodeI32x4Shl - OpcodeI32x4ShrS - OpcodeI32x4ShrU - OpcodeI32x4Add - OpcodeI32x4Sub - OpcodeI32x4Mul - OpcodeI32x4MinS - OpcodeI32x4MinU - OpcodeI32x4MaxS - OpcodeI32x4MaxU - OpcodeI64x2Neg - OpcodeI64x2AnyTrue - OpcodeI64x2AllTrue - OpcodeI64x2Shl - OpcodeI64x2ShrS - OpcodeI64x2ShrU - OpcodeI64x2Add - OpcodeI64x2Sub - OpcodeI64x2Mul - OpcodeF32x4Abs - OpcodeF32x4Neg - OpcodeF32x4Sqrt - OpcodeF32x4Add - OpcodeF32x4Sub - OpcodeF32x4Mul - OpcodeF32x4Div - OpcodeF32x4Min - OpcodeF32x4Max - OpcodeF64x2Abs - OpcodeF64x2Neg - OpcodeF64x2Sqrt - OpcodeF64x2Add - OpcodeF64x2Sub - OpcodeF64x2Mul - OpcodeF64x2Div - OpcodeF64x2Min - OpcodeF64x2Max - OpcodeI32x4TruncSatF32x4S - OpcodeI32x4TruncSatF32x4U - OpcodeI64x2TruncSatF64x2S - OpcodeI64x2TruncSatF64x2U - OpcodeF32x4ConvertI32x4S - OpcodeF32x4ConvertI32x4U - OpcodeF64x2ConvertI64x2S - OpcodeF64x2ConvertI64x2U - OpcodeV8x16Swizzle - OpcodeV8x16Shuffle - OpcodeV8x16LoadSplat - OpcodeV16x8LoadSplat - OpcodeV32x4LoadSplat - OpcodeV64x2LoadSplat - OpcodeI8x16NarrowI16x8S - OpcodeI8x16NarrowI16x8U - OpcodeI16x8NarrowI32x4S - OpcodeI16x8NarrowI32x4U - OpcodeI16x8WidenLowI8x16S - OpcodeI16x8WidenHighI8x16S - OpcodeI16x8WidenLowI8x16U - OpcodeI16x8WidenHighI8x16U - OpcodeI32x4WidenLowI16x8S - OpcodeI32x4WidenHighI16x8S - OpcodeI32x4WidenLowI16x8U - OpcodeI32x4WidenHighI16x8U - OpcodeI16x8Load8x8S - OpcodeI16x8Load8x8U - OpcodeI32x4Load16x4S - OpcodeI32x4Load16x4U - OpcodeI64x2Load32x2S - OpcodeI64x2Load32x2U - OpcodeI8x16RoundingAverageU - OpcodeI16x8RoundingAverageU - OpcodeLocalAllocate -) - -func toOpcodeCostsArray(opcodeCostsStruct *executor.WASMOpcodeCost) [opcodeCount]uint32 { - opcodeCosts := [opcodeCount]uint32{} - - opcodeCosts[OpcodeUnreachable] = opcodeCostsStruct.Unreachable - opcodeCosts[OpcodeNop] = opcodeCostsStruct.Nop - opcodeCosts[OpcodeBlock] = opcodeCostsStruct.Block - opcodeCosts[OpcodeLoop] = opcodeCostsStruct.Loop - opcodeCosts[OpcodeIf] = opcodeCostsStruct.If - opcodeCosts[OpcodeElse] = opcodeCostsStruct.Else - opcodeCosts[OpcodeEnd] = opcodeCostsStruct.End - opcodeCosts[OpcodeBr] = opcodeCostsStruct.Br - opcodeCosts[OpcodeBrIf] = opcodeCostsStruct.BrIf - opcodeCosts[OpcodeBrTable] = opcodeCostsStruct.BrTable - opcodeCosts[OpcodeReturn] = opcodeCostsStruct.Return - opcodeCosts[OpcodeCall] = opcodeCostsStruct.Call - opcodeCosts[OpcodeCallIndirect] = opcodeCostsStruct.CallIndirect - opcodeCosts[OpcodeDrop] = opcodeCostsStruct.Drop - opcodeCosts[OpcodeSelect] = opcodeCostsStruct.Select - opcodeCosts[OpcodeTypedSelect] = opcodeCostsStruct.TypedSelect - opcodeCosts[OpcodeLocalGet] = opcodeCostsStruct.LocalGet - opcodeCosts[OpcodeLocalSet] = opcodeCostsStruct.LocalSet - opcodeCosts[OpcodeLocalTee] = opcodeCostsStruct.LocalTee - opcodeCosts[OpcodeGlobalGet] = opcodeCostsStruct.GlobalGet - opcodeCosts[OpcodeGlobalSet] = opcodeCostsStruct.GlobalSet - opcodeCosts[OpcodeI32Load] = opcodeCostsStruct.I32Load - opcodeCosts[OpcodeI64Load] = opcodeCostsStruct.I64Load - opcodeCosts[OpcodeF32Load] = opcodeCostsStruct.F32Load - opcodeCosts[OpcodeF64Load] = opcodeCostsStruct.F64Load - opcodeCosts[OpcodeI32Load8S] = opcodeCostsStruct.I32Load8S - opcodeCosts[OpcodeI32Load8U] = opcodeCostsStruct.I32Load8U - opcodeCosts[OpcodeI32Load16S] = opcodeCostsStruct.I32Load16S - opcodeCosts[OpcodeI32Load16U] = opcodeCostsStruct.I32Load16U - opcodeCosts[OpcodeI64Load8S] = opcodeCostsStruct.I64Load8S - opcodeCosts[OpcodeI64Load8U] = opcodeCostsStruct.I64Load8U - opcodeCosts[OpcodeI64Load16S] = opcodeCostsStruct.I64Load16S - opcodeCosts[OpcodeI64Load16U] = opcodeCostsStruct.I64Load16U - opcodeCosts[OpcodeI64Load32S] = opcodeCostsStruct.I64Load32S - opcodeCosts[OpcodeI64Load32U] = opcodeCostsStruct.I64Load32U - opcodeCosts[OpcodeI32Store] = opcodeCostsStruct.I32Store - opcodeCosts[OpcodeI64Store] = opcodeCostsStruct.I64Store - opcodeCosts[OpcodeF32Store] = opcodeCostsStruct.F32Store - opcodeCosts[OpcodeF64Store] = opcodeCostsStruct.F64Store - opcodeCosts[OpcodeI32Store8] = opcodeCostsStruct.I32Store8 - opcodeCosts[OpcodeI32Store16] = opcodeCostsStruct.I32Store16 - opcodeCosts[OpcodeI64Store8] = opcodeCostsStruct.I64Store8 - opcodeCosts[OpcodeI64Store16] = opcodeCostsStruct.I64Store16 - opcodeCosts[OpcodeI64Store32] = opcodeCostsStruct.I64Store32 - opcodeCosts[OpcodeMemorySize] = opcodeCostsStruct.MemorySize - opcodeCosts[OpcodeMemoryGrow] = opcodeCostsStruct.MemoryGrow - opcodeCosts[OpcodeI32Const] = opcodeCostsStruct.I32Const - opcodeCosts[OpcodeI64Const] = opcodeCostsStruct.I64Const - opcodeCosts[OpcodeF32Const] = opcodeCostsStruct.F32Const - opcodeCosts[OpcodeF64Const] = opcodeCostsStruct.F64Const - opcodeCosts[OpcodeRefNull] = opcodeCostsStruct.RefNull - opcodeCosts[OpcodeRefIsNull] = opcodeCostsStruct.RefIsNull - opcodeCosts[OpcodeRefFunc] = opcodeCostsStruct.RefFunc - opcodeCosts[OpcodeI32Eqz] = opcodeCostsStruct.I32Eqz - opcodeCosts[OpcodeI32Eq] = opcodeCostsStruct.I32Eq - opcodeCosts[OpcodeI32Ne] = opcodeCostsStruct.I32Ne - opcodeCosts[OpcodeI32LtS] = opcodeCostsStruct.I32LtS - opcodeCosts[OpcodeI32LtU] = opcodeCostsStruct.I32LtU - opcodeCosts[OpcodeI32GtS] = opcodeCostsStruct.I32GtS - opcodeCosts[OpcodeI32GtU] = opcodeCostsStruct.I32GtU - opcodeCosts[OpcodeI32LeS] = opcodeCostsStruct.I32LeS - opcodeCosts[OpcodeI32LeU] = opcodeCostsStruct.I32LeU - opcodeCosts[OpcodeI32GeS] = opcodeCostsStruct.I32GeS - opcodeCosts[OpcodeI32GeU] = opcodeCostsStruct.I32GeU - opcodeCosts[OpcodeI64Eqz] = opcodeCostsStruct.I64Eqz - opcodeCosts[OpcodeI64Eq] = opcodeCostsStruct.I64Eq - opcodeCosts[OpcodeI64Ne] = opcodeCostsStruct.I64Ne - opcodeCosts[OpcodeI64LtS] = opcodeCostsStruct.I64LtS - opcodeCosts[OpcodeI64LtU] = opcodeCostsStruct.I64LtU - opcodeCosts[OpcodeI64GtS] = opcodeCostsStruct.I64GtS - opcodeCosts[OpcodeI64GtU] = opcodeCostsStruct.I64GtU - opcodeCosts[OpcodeI64LeS] = opcodeCostsStruct.I64LeS - opcodeCosts[OpcodeI64LeU] = opcodeCostsStruct.I64LeU - opcodeCosts[OpcodeI64GeS] = opcodeCostsStruct.I64GeS - opcodeCosts[OpcodeI64GeU] = opcodeCostsStruct.I64GeU - opcodeCosts[OpcodeF32Eq] = opcodeCostsStruct.F32Eq - opcodeCosts[OpcodeF32Ne] = opcodeCostsStruct.F32Ne - opcodeCosts[OpcodeF32Lt] = opcodeCostsStruct.F32Lt - opcodeCosts[OpcodeF32Gt] = opcodeCostsStruct.F32Gt - opcodeCosts[OpcodeF32Le] = opcodeCostsStruct.F32Le - opcodeCosts[OpcodeF32Ge] = opcodeCostsStruct.F32Ge - opcodeCosts[OpcodeF64Eq] = opcodeCostsStruct.F64Eq - opcodeCosts[OpcodeF64Ne] = opcodeCostsStruct.F64Ne - opcodeCosts[OpcodeF64Lt] = opcodeCostsStruct.F64Lt - opcodeCosts[OpcodeF64Gt] = opcodeCostsStruct.F64Gt - opcodeCosts[OpcodeF64Le] = opcodeCostsStruct.F64Le - opcodeCosts[OpcodeF64Ge] = opcodeCostsStruct.F64Ge - opcodeCosts[OpcodeI32Clz] = opcodeCostsStruct.I32Clz - opcodeCosts[OpcodeI32Ctz] = opcodeCostsStruct.I32Ctz - opcodeCosts[OpcodeI32Popcnt] = opcodeCostsStruct.I32Popcnt - opcodeCosts[OpcodeI32Add] = opcodeCostsStruct.I32Add - opcodeCosts[OpcodeI32Sub] = opcodeCostsStruct.I32Sub - opcodeCosts[OpcodeI32Mul] = opcodeCostsStruct.I32Mul - opcodeCosts[OpcodeI32DivS] = opcodeCostsStruct.I32DivS - opcodeCosts[OpcodeI32DivU] = opcodeCostsStruct.I32DivU - opcodeCosts[OpcodeI32RemS] = opcodeCostsStruct.I32RemS - opcodeCosts[OpcodeI32RemU] = opcodeCostsStruct.I32RemU - opcodeCosts[OpcodeI32And] = opcodeCostsStruct.I32And - opcodeCosts[OpcodeI32Or] = opcodeCostsStruct.I32Or - opcodeCosts[OpcodeI32Xor] = opcodeCostsStruct.I32Xor - opcodeCosts[OpcodeI32Shl] = opcodeCostsStruct.I32Shl - opcodeCosts[OpcodeI32ShrS] = opcodeCostsStruct.I32ShrS - opcodeCosts[OpcodeI32ShrU] = opcodeCostsStruct.I32ShrU - opcodeCosts[OpcodeI32Rotl] = opcodeCostsStruct.I32Rotl - opcodeCosts[OpcodeI32Rotr] = opcodeCostsStruct.I32Rotr - opcodeCosts[OpcodeI64Clz] = opcodeCostsStruct.I64Clz - opcodeCosts[OpcodeI64Ctz] = opcodeCostsStruct.I64Ctz - opcodeCosts[OpcodeI64Popcnt] = opcodeCostsStruct.I64Popcnt - opcodeCosts[OpcodeI64Add] = opcodeCostsStruct.I64Add - opcodeCosts[OpcodeI64Sub] = opcodeCostsStruct.I64Sub - opcodeCosts[OpcodeI64Mul] = opcodeCostsStruct.I64Mul - opcodeCosts[OpcodeI64DivS] = opcodeCostsStruct.I64DivS - opcodeCosts[OpcodeI64DivU] = opcodeCostsStruct.I64DivU - opcodeCosts[OpcodeI64RemS] = opcodeCostsStruct.I64RemS - opcodeCosts[OpcodeI64RemU] = opcodeCostsStruct.I64RemU - opcodeCosts[OpcodeI64And] = opcodeCostsStruct.I64And - opcodeCosts[OpcodeI64Or] = opcodeCostsStruct.I64Or - opcodeCosts[OpcodeI64Xor] = opcodeCostsStruct.I64Xor - opcodeCosts[OpcodeI64Shl] = opcodeCostsStruct.I64Shl - opcodeCosts[OpcodeI64ShrS] = opcodeCostsStruct.I64ShrS - opcodeCosts[OpcodeI64ShrU] = opcodeCostsStruct.I64ShrU - opcodeCosts[OpcodeI64Rotl] = opcodeCostsStruct.I64Rotl - opcodeCosts[OpcodeI64Rotr] = opcodeCostsStruct.I64Rotr - opcodeCosts[OpcodeF32Abs] = opcodeCostsStruct.F32Abs - opcodeCosts[OpcodeF32Neg] = opcodeCostsStruct.F32Neg - opcodeCosts[OpcodeF32Ceil] = opcodeCostsStruct.F32Ceil - opcodeCosts[OpcodeF32Floor] = opcodeCostsStruct.F32Floor - opcodeCosts[OpcodeF32Trunc] = opcodeCostsStruct.F32Trunc - opcodeCosts[OpcodeF32Nearest] = opcodeCostsStruct.F32Nearest - opcodeCosts[OpcodeF32Sqrt] = opcodeCostsStruct.F32Sqrt - opcodeCosts[OpcodeF32Add] = opcodeCostsStruct.F32Add - opcodeCosts[OpcodeF32Sub] = opcodeCostsStruct.F32Sub - opcodeCosts[OpcodeF32Mul] = opcodeCostsStruct.F32Mul - opcodeCosts[OpcodeF32Div] = opcodeCostsStruct.F32Div - opcodeCosts[OpcodeF32Min] = opcodeCostsStruct.F32Min - opcodeCosts[OpcodeF32Max] = opcodeCostsStruct.F32Max - opcodeCosts[OpcodeF32Copysign] = opcodeCostsStruct.F32Copysign - opcodeCosts[OpcodeF64Abs] = opcodeCostsStruct.F64Abs - opcodeCosts[OpcodeF64Neg] = opcodeCostsStruct.F64Neg - opcodeCosts[OpcodeF64Ceil] = opcodeCostsStruct.F64Ceil - opcodeCosts[OpcodeF64Floor] = opcodeCostsStruct.F64Floor - opcodeCosts[OpcodeF64Trunc] = opcodeCostsStruct.F64Trunc - opcodeCosts[OpcodeF64Nearest] = opcodeCostsStruct.F64Nearest - opcodeCosts[OpcodeF64Sqrt] = opcodeCostsStruct.F64Sqrt - opcodeCosts[OpcodeF64Add] = opcodeCostsStruct.F64Add - opcodeCosts[OpcodeF64Sub] = opcodeCostsStruct.F64Sub - opcodeCosts[OpcodeF64Mul] = opcodeCostsStruct.F64Mul - opcodeCosts[OpcodeF64Div] = opcodeCostsStruct.F64Div - opcodeCosts[OpcodeF64Min] = opcodeCostsStruct.F64Min - opcodeCosts[OpcodeF64Max] = opcodeCostsStruct.F64Max - opcodeCosts[OpcodeF64Copysign] = opcodeCostsStruct.F64Copysign - opcodeCosts[OpcodeI32WrapI64] = opcodeCostsStruct.I32WrapI64 - opcodeCosts[OpcodeI32TruncF32S] = opcodeCostsStruct.I32TruncF32S - opcodeCosts[OpcodeI32TruncF32U] = opcodeCostsStruct.I32TruncF32U - opcodeCosts[OpcodeI32TruncF64S] = opcodeCostsStruct.I32TruncF64S - opcodeCosts[OpcodeI32TruncF64U] = opcodeCostsStruct.I32TruncF64U - opcodeCosts[OpcodeI64ExtendI32S] = opcodeCostsStruct.I64ExtendI32S - opcodeCosts[OpcodeI64ExtendI32U] = opcodeCostsStruct.I64ExtendI32U - opcodeCosts[OpcodeI64TruncF32S] = opcodeCostsStruct.I64TruncF32S - opcodeCosts[OpcodeI64TruncF32U] = opcodeCostsStruct.I64TruncF32U - opcodeCosts[OpcodeI64TruncF64S] = opcodeCostsStruct.I64TruncF64S - opcodeCosts[OpcodeI64TruncF64U] = opcodeCostsStruct.I64TruncF64U - opcodeCosts[OpcodeF32ConvertI32S] = opcodeCostsStruct.F32ConvertI32S - opcodeCosts[OpcodeF32ConvertI32U] = opcodeCostsStruct.F32ConvertI32U - opcodeCosts[OpcodeF32ConvertI64S] = opcodeCostsStruct.F32ConvertI64S - opcodeCosts[OpcodeF32ConvertI64U] = opcodeCostsStruct.F32ConvertI64U - opcodeCosts[OpcodeF32DemoteF64] = opcodeCostsStruct.F32DemoteF64 - opcodeCosts[OpcodeF64ConvertI32S] = opcodeCostsStruct.F64ConvertI32S - opcodeCosts[OpcodeF64ConvertI32U] = opcodeCostsStruct.F64ConvertI32U - opcodeCosts[OpcodeF64ConvertI64S] = opcodeCostsStruct.F64ConvertI64S - opcodeCosts[OpcodeF64ConvertI64U] = opcodeCostsStruct.F64ConvertI64U - opcodeCosts[OpcodeF64PromoteF32] = opcodeCostsStruct.F64PromoteF32 - opcodeCosts[OpcodeI32ReinterpretF32] = opcodeCostsStruct.I32ReinterpretF32 - opcodeCosts[OpcodeI64ReinterpretF64] = opcodeCostsStruct.I64ReinterpretF64 - opcodeCosts[OpcodeF32ReinterpretI32] = opcodeCostsStruct.F32ReinterpretI32 - opcodeCosts[OpcodeF64ReinterpretI64] = opcodeCostsStruct.F64ReinterpretI64 - opcodeCosts[OpcodeI32Extend8S] = opcodeCostsStruct.I32Extend8S - opcodeCosts[OpcodeI32Extend16S] = opcodeCostsStruct.I32Extend16S - opcodeCosts[OpcodeI64Extend8S] = opcodeCostsStruct.I64Extend8S - opcodeCosts[OpcodeI64Extend16S] = opcodeCostsStruct.I64Extend16S - opcodeCosts[OpcodeI64Extend32S] = opcodeCostsStruct.I64Extend32S - opcodeCosts[OpcodeI32TruncSatF32S] = opcodeCostsStruct.I32TruncSatF32S - opcodeCosts[OpcodeI32TruncSatF32U] = opcodeCostsStruct.I32TruncSatF32U - opcodeCosts[OpcodeI32TruncSatF64S] = opcodeCostsStruct.I32TruncSatF64S - opcodeCosts[OpcodeI32TruncSatF64U] = opcodeCostsStruct.I32TruncSatF64U - opcodeCosts[OpcodeI64TruncSatF32S] = opcodeCostsStruct.I64TruncSatF32S - opcodeCosts[OpcodeI64TruncSatF32U] = opcodeCostsStruct.I64TruncSatF32U - opcodeCosts[OpcodeI64TruncSatF64S] = opcodeCostsStruct.I64TruncSatF64S - opcodeCosts[OpcodeI64TruncSatF64U] = opcodeCostsStruct.I64TruncSatF64U - opcodeCosts[OpcodeMemoryInit] = opcodeCostsStruct.MemoryInit - opcodeCosts[OpcodeDataDrop] = opcodeCostsStruct.DataDrop - opcodeCosts[OpcodeMemoryCopy] = opcodeCostsStruct.MemoryCopy - opcodeCosts[OpcodeMemoryFill] = opcodeCostsStruct.MemoryFill - opcodeCosts[OpcodeTableInit] = opcodeCostsStruct.TableInit - opcodeCosts[OpcodeElemDrop] = opcodeCostsStruct.ElemDrop - opcodeCosts[OpcodeTableCopy] = opcodeCostsStruct.TableCopy - opcodeCosts[OpcodeTableFill] = opcodeCostsStruct.TableFill - opcodeCosts[OpcodeTableGet] = opcodeCostsStruct.TableGet - opcodeCosts[OpcodeTableSet] = opcodeCostsStruct.TableSet - opcodeCosts[OpcodeTableGrow] = opcodeCostsStruct.TableGrow - opcodeCosts[OpcodeTableSize] = opcodeCostsStruct.TableSize - opcodeCosts[OpcodeAtomicNotify] = opcodeCostsStruct.AtomicNotify - opcodeCosts[OpcodeI32AtomicWait] = opcodeCostsStruct.I32AtomicWait - opcodeCosts[OpcodeI64AtomicWait] = opcodeCostsStruct.I64AtomicWait - opcodeCosts[OpcodeAtomicFence] = opcodeCostsStruct.AtomicFence - opcodeCosts[OpcodeI32AtomicLoad] = opcodeCostsStruct.I32AtomicLoad - opcodeCosts[OpcodeI64AtomicLoad] = opcodeCostsStruct.I64AtomicLoad - opcodeCosts[OpcodeI32AtomicLoad8U] = opcodeCostsStruct.I32AtomicLoad8U - opcodeCosts[OpcodeI32AtomicLoad16U] = opcodeCostsStruct.I32AtomicLoad16U - opcodeCosts[OpcodeI64AtomicLoad8U] = opcodeCostsStruct.I64AtomicLoad8U - opcodeCosts[OpcodeI64AtomicLoad16U] = opcodeCostsStruct.I64AtomicLoad16U - opcodeCosts[OpcodeI64AtomicLoad32U] = opcodeCostsStruct.I64AtomicLoad32U - opcodeCosts[OpcodeI32AtomicStore] = opcodeCostsStruct.I32AtomicStore - opcodeCosts[OpcodeI64AtomicStore] = opcodeCostsStruct.I64AtomicStore - opcodeCosts[OpcodeI32AtomicStore8] = opcodeCostsStruct.I32AtomicStore8 - opcodeCosts[OpcodeI32AtomicStore16] = opcodeCostsStruct.I32AtomicStore16 - opcodeCosts[OpcodeI64AtomicStore8] = opcodeCostsStruct.I64AtomicStore8 - opcodeCosts[OpcodeI64AtomicStore16] = opcodeCostsStruct.I64AtomicStore16 - opcodeCosts[OpcodeI64AtomicStore32] = opcodeCostsStruct.I64AtomicStore32 - opcodeCosts[OpcodeI32AtomicRmwAdd] = opcodeCostsStruct.I32AtomicRmwAdd - opcodeCosts[OpcodeI64AtomicRmwAdd] = opcodeCostsStruct.I64AtomicRmwAdd - opcodeCosts[OpcodeI32AtomicRmw8AddU] = opcodeCostsStruct.I32AtomicRmw8AddU - opcodeCosts[OpcodeI32AtomicRmw16AddU] = opcodeCostsStruct.I32AtomicRmw16AddU - opcodeCosts[OpcodeI64AtomicRmw8AddU] = opcodeCostsStruct.I64AtomicRmw8AddU - opcodeCosts[OpcodeI64AtomicRmw16AddU] = opcodeCostsStruct.I64AtomicRmw16AddU - opcodeCosts[OpcodeI64AtomicRmw32AddU] = opcodeCostsStruct.I64AtomicRmw32AddU - opcodeCosts[OpcodeI32AtomicRmwSub] = opcodeCostsStruct.I32AtomicRmwSub - opcodeCosts[OpcodeI64AtomicRmwSub] = opcodeCostsStruct.I64AtomicRmwSub - opcodeCosts[OpcodeI32AtomicRmw8SubU] = opcodeCostsStruct.I32AtomicRmw8SubU - opcodeCosts[OpcodeI32AtomicRmw16SubU] = opcodeCostsStruct.I32AtomicRmw16SubU - opcodeCosts[OpcodeI64AtomicRmw8SubU] = opcodeCostsStruct.I64AtomicRmw8SubU - opcodeCosts[OpcodeI64AtomicRmw16SubU] = opcodeCostsStruct.I64AtomicRmw16SubU - opcodeCosts[OpcodeI64AtomicRmw32SubU] = opcodeCostsStruct.I64AtomicRmw32SubU - opcodeCosts[OpcodeI32AtomicRmwAnd] = opcodeCostsStruct.I32AtomicRmwAnd - opcodeCosts[OpcodeI64AtomicRmwAnd] = opcodeCostsStruct.I64AtomicRmwAnd - opcodeCosts[OpcodeI32AtomicRmw8AndU] = opcodeCostsStruct.I32AtomicRmw8AndU - opcodeCosts[OpcodeI32AtomicRmw16AndU] = opcodeCostsStruct.I32AtomicRmw16AndU - opcodeCosts[OpcodeI64AtomicRmw8AndU] = opcodeCostsStruct.I64AtomicRmw8AndU - opcodeCosts[OpcodeI64AtomicRmw16AndU] = opcodeCostsStruct.I64AtomicRmw16AndU - opcodeCosts[OpcodeI64AtomicRmw32AndU] = opcodeCostsStruct.I64AtomicRmw32AndU - opcodeCosts[OpcodeI32AtomicRmwOr] = opcodeCostsStruct.I32AtomicRmwOr - opcodeCosts[OpcodeI64AtomicRmwOr] = opcodeCostsStruct.I64AtomicRmwOr - opcodeCosts[OpcodeI32AtomicRmw8OrU] = opcodeCostsStruct.I32AtomicRmw8OrU - opcodeCosts[OpcodeI32AtomicRmw16OrU] = opcodeCostsStruct.I32AtomicRmw16OrU - opcodeCosts[OpcodeI64AtomicRmw8OrU] = opcodeCostsStruct.I64AtomicRmw8OrU - opcodeCosts[OpcodeI64AtomicRmw16OrU] = opcodeCostsStruct.I64AtomicRmw16OrU - opcodeCosts[OpcodeI64AtomicRmw32OrU] = opcodeCostsStruct.I64AtomicRmw32OrU - opcodeCosts[OpcodeI32AtomicRmwXor] = opcodeCostsStruct.I32AtomicRmwXor - opcodeCosts[OpcodeI64AtomicRmwXor] = opcodeCostsStruct.I64AtomicRmwXor - opcodeCosts[OpcodeI32AtomicRmw8XorU] = opcodeCostsStruct.I32AtomicRmw8XorU - opcodeCosts[OpcodeI32AtomicRmw16XorU] = opcodeCostsStruct.I32AtomicRmw16XorU - opcodeCosts[OpcodeI64AtomicRmw8XorU] = opcodeCostsStruct.I64AtomicRmw8XorU - opcodeCosts[OpcodeI64AtomicRmw16XorU] = opcodeCostsStruct.I64AtomicRmw16XorU - opcodeCosts[OpcodeI64AtomicRmw32XorU] = opcodeCostsStruct.I64AtomicRmw32XorU - opcodeCosts[OpcodeI32AtomicRmwXchg] = opcodeCostsStruct.I32AtomicRmwXchg - opcodeCosts[OpcodeI64AtomicRmwXchg] = opcodeCostsStruct.I64AtomicRmwXchg - opcodeCosts[OpcodeI32AtomicRmw8XchgU] = opcodeCostsStruct.I32AtomicRmw8XchgU - opcodeCosts[OpcodeI32AtomicRmw16XchgU] = opcodeCostsStruct.I32AtomicRmw16XchgU - opcodeCosts[OpcodeI64AtomicRmw8XchgU] = opcodeCostsStruct.I64AtomicRmw8XchgU - opcodeCosts[OpcodeI64AtomicRmw16XchgU] = opcodeCostsStruct.I64AtomicRmw16XchgU - opcodeCosts[OpcodeI64AtomicRmw32XchgU] = opcodeCostsStruct.I64AtomicRmw32XchgU - opcodeCosts[OpcodeI32AtomicRmwCmpxchg] = opcodeCostsStruct.I32AtomicRmwCmpxchg - opcodeCosts[OpcodeI64AtomicRmwCmpxchg] = opcodeCostsStruct.I64AtomicRmwCmpxchg - opcodeCosts[OpcodeI32AtomicRmw8CmpxchgU] = opcodeCostsStruct.I32AtomicRmw8CmpxchgU - opcodeCosts[OpcodeI32AtomicRmw16CmpxchgU] = opcodeCostsStruct.I32AtomicRmw16CmpxchgU - opcodeCosts[OpcodeI64AtomicRmw8CmpxchgU] = opcodeCostsStruct.I64AtomicRmw8CmpxchgU - opcodeCosts[OpcodeI64AtomicRmw16CmpxchgU] = opcodeCostsStruct.I64AtomicRmw16CmpxchgU - opcodeCosts[OpcodeI64AtomicRmw32CmpxchgU] = opcodeCostsStruct.I64AtomicRmw32CmpxchgU - opcodeCosts[OpcodeV128Load] = opcodeCostsStruct.V128Load - opcodeCosts[OpcodeV128Store] = opcodeCostsStruct.V128Store - opcodeCosts[OpcodeV128Const] = opcodeCostsStruct.V128Const - opcodeCosts[OpcodeI8x16Splat] = opcodeCostsStruct.I8x16Splat - opcodeCosts[OpcodeI8x16ExtractLaneS] = opcodeCostsStruct.I8x16ExtractLaneS - opcodeCosts[OpcodeI8x16ExtractLaneU] = opcodeCostsStruct.I8x16ExtractLaneU - opcodeCosts[OpcodeI8x16ReplaceLane] = opcodeCostsStruct.I8x16ReplaceLane - opcodeCosts[OpcodeI16x8Splat] = opcodeCostsStruct.I16x8Splat - opcodeCosts[OpcodeI16x8ExtractLaneS] = opcodeCostsStruct.I16x8ExtractLaneS - opcodeCosts[OpcodeI16x8ExtractLaneU] = opcodeCostsStruct.I16x8ExtractLaneU - opcodeCosts[OpcodeI16x8ReplaceLane] = opcodeCostsStruct.I16x8ReplaceLane - opcodeCosts[OpcodeI32x4Splat] = opcodeCostsStruct.I32x4Splat - opcodeCosts[OpcodeI32x4ExtractLane] = opcodeCostsStruct.I32x4ExtractLane - opcodeCosts[OpcodeI32x4ReplaceLane] = opcodeCostsStruct.I32x4ReplaceLane - opcodeCosts[OpcodeI64x2Splat] = opcodeCostsStruct.I64x2Splat - opcodeCosts[OpcodeI64x2ExtractLane] = opcodeCostsStruct.I64x2ExtractLane - opcodeCosts[OpcodeI64x2ReplaceLane] = opcodeCostsStruct.I64x2ReplaceLane - opcodeCosts[OpcodeF32x4Splat] = opcodeCostsStruct.F32x4Splat - opcodeCosts[OpcodeF32x4ExtractLane] = opcodeCostsStruct.F32x4ExtractLane - opcodeCosts[OpcodeF32x4ReplaceLane] = opcodeCostsStruct.F32x4ReplaceLane - opcodeCosts[OpcodeF64x2Splat] = opcodeCostsStruct.F64x2Splat - opcodeCosts[OpcodeF64x2ExtractLane] = opcodeCostsStruct.F64x2ExtractLane - opcodeCosts[OpcodeF64x2ReplaceLane] = opcodeCostsStruct.F64x2ReplaceLane - opcodeCosts[OpcodeI8x16Eq] = opcodeCostsStruct.I8x16Eq - opcodeCosts[OpcodeI8x16Ne] = opcodeCostsStruct.I8x16Ne - opcodeCosts[OpcodeI8x16LtS] = opcodeCostsStruct.I8x16LtS - opcodeCosts[OpcodeI8x16LtU] = opcodeCostsStruct.I8x16LtU - opcodeCosts[OpcodeI8x16GtS] = opcodeCostsStruct.I8x16GtS - opcodeCosts[OpcodeI8x16GtU] = opcodeCostsStruct.I8x16GtU - opcodeCosts[OpcodeI8x16LeS] = opcodeCostsStruct.I8x16LeS - opcodeCosts[OpcodeI8x16LeU] = opcodeCostsStruct.I8x16LeU - opcodeCosts[OpcodeI8x16GeS] = opcodeCostsStruct.I8x16GeS - opcodeCosts[OpcodeI8x16GeU] = opcodeCostsStruct.I8x16GeU - opcodeCosts[OpcodeI16x8Eq] = opcodeCostsStruct.I16x8Eq - opcodeCosts[OpcodeI16x8Ne] = opcodeCostsStruct.I16x8Ne - opcodeCosts[OpcodeI16x8LtS] = opcodeCostsStruct.I16x8LtS - opcodeCosts[OpcodeI16x8LtU] = opcodeCostsStruct.I16x8LtU - opcodeCosts[OpcodeI16x8GtS] = opcodeCostsStruct.I16x8GtS - opcodeCosts[OpcodeI16x8GtU] = opcodeCostsStruct.I16x8GtU - opcodeCosts[OpcodeI16x8LeS] = opcodeCostsStruct.I16x8LeS - opcodeCosts[OpcodeI16x8LeU] = opcodeCostsStruct.I16x8LeU - opcodeCosts[OpcodeI16x8GeS] = opcodeCostsStruct.I16x8GeS - opcodeCosts[OpcodeI16x8GeU] = opcodeCostsStruct.I16x8GeU - opcodeCosts[OpcodeI32x4Eq] = opcodeCostsStruct.I32x4Eq - opcodeCosts[OpcodeI32x4Ne] = opcodeCostsStruct.I32x4Ne - opcodeCosts[OpcodeI32x4LtS] = opcodeCostsStruct.I32x4LtS - opcodeCosts[OpcodeI32x4LtU] = opcodeCostsStruct.I32x4LtU - opcodeCosts[OpcodeI32x4GtS] = opcodeCostsStruct.I32x4GtS - opcodeCosts[OpcodeI32x4GtU] = opcodeCostsStruct.I32x4GtU - opcodeCosts[OpcodeI32x4LeS] = opcodeCostsStruct.I32x4LeS - opcodeCosts[OpcodeI32x4LeU] = opcodeCostsStruct.I32x4LeU - opcodeCosts[OpcodeI32x4GeS] = opcodeCostsStruct.I32x4GeS - opcodeCosts[OpcodeI32x4GeU] = opcodeCostsStruct.I32x4GeU - opcodeCosts[OpcodeF32x4Eq] = opcodeCostsStruct.F32x4Eq - opcodeCosts[OpcodeF32x4Ne] = opcodeCostsStruct.F32x4Ne - opcodeCosts[OpcodeF32x4Lt] = opcodeCostsStruct.F32x4Lt - opcodeCosts[OpcodeF32x4Gt] = opcodeCostsStruct.F32x4Gt - opcodeCosts[OpcodeF32x4Le] = opcodeCostsStruct.F32x4Le - opcodeCosts[OpcodeF32x4Ge] = opcodeCostsStruct.F32x4Ge - opcodeCosts[OpcodeF64x2Eq] = opcodeCostsStruct.F64x2Eq - opcodeCosts[OpcodeF64x2Ne] = opcodeCostsStruct.F64x2Ne - opcodeCosts[OpcodeF64x2Lt] = opcodeCostsStruct.F64x2Lt - opcodeCosts[OpcodeF64x2Gt] = opcodeCostsStruct.F64x2Gt - opcodeCosts[OpcodeF64x2Le] = opcodeCostsStruct.F64x2Le - opcodeCosts[OpcodeF64x2Ge] = opcodeCostsStruct.F64x2Ge - opcodeCosts[OpcodeV128Not] = opcodeCostsStruct.V128Not - opcodeCosts[OpcodeV128And] = opcodeCostsStruct.V128And - opcodeCosts[OpcodeV128AndNot] = opcodeCostsStruct.V128AndNot - opcodeCosts[OpcodeV128Or] = opcodeCostsStruct.V128Or - opcodeCosts[OpcodeV128Xor] = opcodeCostsStruct.V128Xor - opcodeCosts[OpcodeV128Bitselect] = opcodeCostsStruct.V128Bitselect - opcodeCosts[OpcodeI8x16Neg] = opcodeCostsStruct.I8x16Neg - opcodeCosts[OpcodeI8x16AnyTrue] = opcodeCostsStruct.I8x16AnyTrue - opcodeCosts[OpcodeI8x16AllTrue] = opcodeCostsStruct.I8x16AllTrue - opcodeCosts[OpcodeI8x16Shl] = opcodeCostsStruct.I8x16Shl - opcodeCosts[OpcodeI8x16ShrS] = opcodeCostsStruct.I8x16ShrS - opcodeCosts[OpcodeI8x16ShrU] = opcodeCostsStruct.I8x16ShrU - opcodeCosts[OpcodeI8x16Add] = opcodeCostsStruct.I8x16Add - opcodeCosts[OpcodeI8x16AddSaturateS] = opcodeCostsStruct.I8x16AddSaturateS - opcodeCosts[OpcodeI8x16AddSaturateU] = opcodeCostsStruct.I8x16AddSaturateU - opcodeCosts[OpcodeI8x16Sub] = opcodeCostsStruct.I8x16Sub - opcodeCosts[OpcodeI8x16SubSaturateS] = opcodeCostsStruct.I8x16SubSaturateS - opcodeCosts[OpcodeI8x16SubSaturateU] = opcodeCostsStruct.I8x16SubSaturateU - opcodeCosts[OpcodeI8x16MinS] = opcodeCostsStruct.I8x16MinS - opcodeCosts[OpcodeI8x16MinU] = opcodeCostsStruct.I8x16MinU - opcodeCosts[OpcodeI8x16MaxS] = opcodeCostsStruct.I8x16MaxS - opcodeCosts[OpcodeI8x16MaxU] = opcodeCostsStruct.I8x16MaxU - opcodeCosts[OpcodeI8x16Mul] = opcodeCostsStruct.I8x16Mul - opcodeCosts[OpcodeI16x8Neg] = opcodeCostsStruct.I16x8Neg - opcodeCosts[OpcodeI16x8AnyTrue] = opcodeCostsStruct.I16x8AnyTrue - opcodeCosts[OpcodeI16x8AllTrue] = opcodeCostsStruct.I16x8AllTrue - opcodeCosts[OpcodeI16x8Shl] = opcodeCostsStruct.I16x8Shl - opcodeCosts[OpcodeI16x8ShrS] = opcodeCostsStruct.I16x8ShrS - opcodeCosts[OpcodeI16x8ShrU] = opcodeCostsStruct.I16x8ShrU - opcodeCosts[OpcodeI16x8Add] = opcodeCostsStruct.I16x8Add - opcodeCosts[OpcodeI16x8AddSaturateS] = opcodeCostsStruct.I16x8AddSaturateS - opcodeCosts[OpcodeI16x8AddSaturateU] = opcodeCostsStruct.I16x8AddSaturateU - opcodeCosts[OpcodeI16x8Sub] = opcodeCostsStruct.I16x8Sub - opcodeCosts[OpcodeI16x8SubSaturateS] = opcodeCostsStruct.I16x8SubSaturateS - opcodeCosts[OpcodeI16x8SubSaturateU] = opcodeCostsStruct.I16x8SubSaturateU - opcodeCosts[OpcodeI16x8Mul] = opcodeCostsStruct.I16x8Mul - opcodeCosts[OpcodeI16x8MinS] = opcodeCostsStruct.I16x8MinS - opcodeCosts[OpcodeI16x8MinU] = opcodeCostsStruct.I16x8MinU - opcodeCosts[OpcodeI16x8MaxS] = opcodeCostsStruct.I16x8MaxS - opcodeCosts[OpcodeI16x8MaxU] = opcodeCostsStruct.I16x8MaxU - opcodeCosts[OpcodeI32x4Neg] = opcodeCostsStruct.I32x4Neg - opcodeCosts[OpcodeI32x4AnyTrue] = opcodeCostsStruct.I32x4AnyTrue - opcodeCosts[OpcodeI32x4AllTrue] = opcodeCostsStruct.I32x4AllTrue - opcodeCosts[OpcodeI32x4Shl] = opcodeCostsStruct.I32x4Shl - opcodeCosts[OpcodeI32x4ShrS] = opcodeCostsStruct.I32x4ShrS - opcodeCosts[OpcodeI32x4ShrU] = opcodeCostsStruct.I32x4ShrU - opcodeCosts[OpcodeI32x4Add] = opcodeCostsStruct.I32x4Add - opcodeCosts[OpcodeI32x4Sub] = opcodeCostsStruct.I32x4Sub - opcodeCosts[OpcodeI32x4Mul] = opcodeCostsStruct.I32x4Mul - opcodeCosts[OpcodeI32x4MinS] = opcodeCostsStruct.I32x4MinS - opcodeCosts[OpcodeI32x4MinU] = opcodeCostsStruct.I32x4MinU - opcodeCosts[OpcodeI32x4MaxS] = opcodeCostsStruct.I32x4MaxS - opcodeCosts[OpcodeI32x4MaxU] = opcodeCostsStruct.I32x4MaxU - opcodeCosts[OpcodeI64x2Neg] = opcodeCostsStruct.I64x2Neg - opcodeCosts[OpcodeI64x2AnyTrue] = opcodeCostsStruct.I64x2AnyTrue - opcodeCosts[OpcodeI64x2AllTrue] = opcodeCostsStruct.I64x2AllTrue - opcodeCosts[OpcodeI64x2Shl] = opcodeCostsStruct.I64x2Shl - opcodeCosts[OpcodeI64x2ShrS] = opcodeCostsStruct.I64x2ShrS - opcodeCosts[OpcodeI64x2ShrU] = opcodeCostsStruct.I64x2ShrU - opcodeCosts[OpcodeI64x2Add] = opcodeCostsStruct.I64x2Add - opcodeCosts[OpcodeI64x2Sub] = opcodeCostsStruct.I64x2Sub - opcodeCosts[OpcodeI64x2Mul] = opcodeCostsStruct.I64x2Mul - opcodeCosts[OpcodeF32x4Abs] = opcodeCostsStruct.F32x4Abs - opcodeCosts[OpcodeF32x4Neg] = opcodeCostsStruct.F32x4Neg - opcodeCosts[OpcodeF32x4Sqrt] = opcodeCostsStruct.F32x4Sqrt - opcodeCosts[OpcodeF32x4Add] = opcodeCostsStruct.F32x4Add - opcodeCosts[OpcodeF32x4Sub] = opcodeCostsStruct.F32x4Sub - opcodeCosts[OpcodeF32x4Mul] = opcodeCostsStruct.F32x4Mul - opcodeCosts[OpcodeF32x4Div] = opcodeCostsStruct.F32x4Div - opcodeCosts[OpcodeF32x4Min] = opcodeCostsStruct.F32x4Min - opcodeCosts[OpcodeF32x4Max] = opcodeCostsStruct.F32x4Max - opcodeCosts[OpcodeF64x2Abs] = opcodeCostsStruct.F64x2Abs - opcodeCosts[OpcodeF64x2Neg] = opcodeCostsStruct.F64x2Neg - opcodeCosts[OpcodeF64x2Sqrt] = opcodeCostsStruct.F64x2Sqrt - opcodeCosts[OpcodeF64x2Add] = opcodeCostsStruct.F64x2Add - opcodeCosts[OpcodeF64x2Sub] = opcodeCostsStruct.F64x2Sub - opcodeCosts[OpcodeF64x2Mul] = opcodeCostsStruct.F64x2Mul - opcodeCosts[OpcodeF64x2Div] = opcodeCostsStruct.F64x2Div - opcodeCosts[OpcodeF64x2Min] = opcodeCostsStruct.F64x2Min - opcodeCosts[OpcodeF64x2Max] = opcodeCostsStruct.F64x2Max - opcodeCosts[OpcodeI32x4TruncSatF32x4S] = opcodeCostsStruct.I32x4TruncSatF32x4S - opcodeCosts[OpcodeI32x4TruncSatF32x4U] = opcodeCostsStruct.I32x4TruncSatF32x4U - opcodeCosts[OpcodeI64x2TruncSatF64x2S] = opcodeCostsStruct.I64x2TruncSatF64x2S - opcodeCosts[OpcodeI64x2TruncSatF64x2U] = opcodeCostsStruct.I64x2TruncSatF64x2U - opcodeCosts[OpcodeF32x4ConvertI32x4S] = opcodeCostsStruct.F32x4ConvertI32x4S - opcodeCosts[OpcodeF32x4ConvertI32x4U] = opcodeCostsStruct.F32x4ConvertI32x4U - opcodeCosts[OpcodeF64x2ConvertI64x2S] = opcodeCostsStruct.F64x2ConvertI64x2S - opcodeCosts[OpcodeF64x2ConvertI64x2U] = opcodeCostsStruct.F64x2ConvertI64x2U - opcodeCosts[OpcodeV8x16Swizzle] = opcodeCostsStruct.V8x16Swizzle - opcodeCosts[OpcodeV8x16Shuffle] = opcodeCostsStruct.V8x16Shuffle - opcodeCosts[OpcodeV8x16LoadSplat] = opcodeCostsStruct.V8x16LoadSplat - opcodeCosts[OpcodeV16x8LoadSplat] = opcodeCostsStruct.V16x8LoadSplat - opcodeCosts[OpcodeV32x4LoadSplat] = opcodeCostsStruct.V32x4LoadSplat - opcodeCosts[OpcodeV64x2LoadSplat] = opcodeCostsStruct.V64x2LoadSplat - opcodeCosts[OpcodeI8x16NarrowI16x8S] = opcodeCostsStruct.I8x16NarrowI16x8S - opcodeCosts[OpcodeI8x16NarrowI16x8U] = opcodeCostsStruct.I8x16NarrowI16x8U - opcodeCosts[OpcodeI16x8NarrowI32x4S] = opcodeCostsStruct.I16x8NarrowI32x4S - opcodeCosts[OpcodeI16x8NarrowI32x4U] = opcodeCostsStruct.I16x8NarrowI32x4U - opcodeCosts[OpcodeI16x8WidenLowI8x16S] = opcodeCostsStruct.I16x8WidenLowI8x16S - opcodeCosts[OpcodeI16x8WidenHighI8x16S] = opcodeCostsStruct.I16x8WidenHighI8x16S - opcodeCosts[OpcodeI16x8WidenLowI8x16U] = opcodeCostsStruct.I16x8WidenLowI8x16U - opcodeCosts[OpcodeI16x8WidenHighI8x16U] = opcodeCostsStruct.I16x8WidenHighI8x16U - opcodeCosts[OpcodeI32x4WidenLowI16x8S] = opcodeCostsStruct.I32x4WidenLowI16x8S - opcodeCosts[OpcodeI32x4WidenHighI16x8S] = opcodeCostsStruct.I32x4WidenHighI16x8S - opcodeCosts[OpcodeI32x4WidenLowI16x8U] = opcodeCostsStruct.I32x4WidenLowI16x8U - opcodeCosts[OpcodeI32x4WidenHighI16x8U] = opcodeCostsStruct.I32x4WidenHighI16x8U - opcodeCosts[OpcodeI16x8Load8x8S] = opcodeCostsStruct.I16x8Load8x8S - opcodeCosts[OpcodeI16x8Load8x8U] = opcodeCostsStruct.I16x8Load8x8U - opcodeCosts[OpcodeI32x4Load16x4S] = opcodeCostsStruct.I32x4Load16x4S - opcodeCosts[OpcodeI32x4Load16x4U] = opcodeCostsStruct.I32x4Load16x4U - opcodeCosts[OpcodeI64x2Load32x2S] = opcodeCostsStruct.I64x2Load32x2S - opcodeCosts[OpcodeI64x2Load32x2U] = opcodeCostsStruct.I64x2Load32x2U - opcodeCosts[OpcodeI8x16RoundingAverageU] = opcodeCostsStruct.I8x16RoundingAverageU - opcodeCosts[OpcodeI16x8RoundingAverageU] = opcodeCostsStruct.I16x8RoundingAverageU - opcodeCosts[OpcodeLocalAllocate] = opcodeCostsStruct.LocalAllocate - // LocalsUnmetered, MaxMemoryGrow and MaxMemoryGrowDelta are not added to the - // opcodeCosts array; the values will be sent to Wasmer as compilation - // options instead - - return opcodeCosts -} diff --git a/wasmer/wasmerStatic.go b/wasmer/wasmerStatic.go deleted file mode 100644 index a10bf98c0..000000000 --- a/wasmer/wasmerStatic.go +++ /dev/null @@ -1,31 +0,0 @@ -package wasmer - -import "github.com/multiversx/mx-chain-vm-go/executor" - -// SetRkyvSerializationEnabled enables or disables RKYV serialization of instances in Wasmer. -func SetRkyvSerializationEnabled(enabled bool) { - if enabled { - cWasmerInstanceEnableRkyv() - } else { - cWasmerInstanceDisableRkyv() - } -} - -// SetSIGSEGVPassthrough instructs Wasmer to never register a handler for -// SIGSEGV. Only has effect if called before creating the first Wasmer instance -// since the process started. Calling this function after the first Wasmer -// instance will not unregister the signal handler set by Wasmer. -func SetSIGSEGVPassthrough() { - cWasmerSetSIGSEGVPassthrough() -} - -// ForceInstallSighandlers triggers a forced installation of signal handlers in Wasmer 1 -func ForceInstallSighandlers() { - cWasmerForceInstallSighandlers() -} - -// SetOpcodeCosts sets gas costs globally for Wasmer. -func SetOpcodeCosts(opcodeCosts *executor.WASMOpcodeCost) { - opcodeCostsArray := toOpcodeCostsArray(opcodeCosts) - cWasmerSetOpcodeCosts(&opcodeCostsArray) -} diff --git a/wasmer2/wasmer2Executor.go b/wasmer2/wasmer2Executor.go index 73523f85b..159b0d567 100644 --- a/wasmer2/wasmer2Executor.go +++ b/wasmer2/wasmer2Executor.go @@ -9,7 +9,7 @@ import ( var _ executor.Executor = (*Wasmer2Executor)(nil) -// WasmerExecutor oversees the creation of Wasmer instances and execution. +// Wasmer2Executor oversees the creation of Wasmer instances and execution. type Wasmer2Executor struct { cgoExecutor *cWasmerExecutorT @@ -27,10 +27,10 @@ func CreateExecutor() (*Wasmer2Executor, error) { localPtr := uintptr(unsafe.Pointer(vmHookPointers)) localPtrPtr := unsafe.Pointer(&localPtr) - var c_executor *cWasmerExecutorT + var cExecutor *cWasmerExecutorT var result = cWasmerNewExecutor( - &c_executor, + &cExecutor, localPtrPtr, ) @@ -40,12 +40,12 @@ func CreateExecutor() (*Wasmer2Executor, error) { cWasmerForceInstallSighandlers() - executor := &Wasmer2Executor{ - cgoExecutor: c_executor, + wasmerExecutor := &Wasmer2Executor{ + cgoExecutor: cExecutor, vmHookPointers: vmHookPointers, } - return executor, nil + return wasmerExecutor, nil } // SetOpcodeCosts sets gas costs globally inside the Wasmer executor. @@ -59,7 +59,7 @@ func (wasmerExecutor *Wasmer2Executor) SetOpcodeCosts(wasmOps *executor.WASMOpco } // SetRkyvSerializationEnabled controls a Wasmer flag. -func (wasmerExecutor *Wasmer2Executor) SetRkyvSerializationEnabled(enabled bool) { +func (wasmerExecutor *Wasmer2Executor) SetRkyvSerializationEnabled(_ bool) { } // SetSIGSEGVPassthrough controls a Wasmer flag. @@ -76,7 +76,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceWithOptions( contractCode []byte, options executor.CompilationOptions, ) (executor.Instance, error) { - var c_instance *cWasmerInstanceT + var cInstance *cWasmerInstanceT if len(contractCode) == 0 { return nil, newWrappedError(ErrInvalidBytecode) @@ -85,7 +85,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceWithOptions( cOptions := unsafe.Pointer(&options) var compileResult = cWasmerInstantiateWithOptions( wasmerExecutor.cgoExecutor, - &c_instance, + &cInstance, (*cUchar)(unsafe.Pointer(&contractCode[0])), cUint(len(contractCode)), (*cWasmerCompilationOptions)(cOptions), @@ -95,7 +95,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceWithOptions( return nil, newWrappedError(ErrFailedInstantiation) } - return newInstance(c_instance) + return newInstance(cInstance) } // NewInstanceFromCompiledCodeWithOptions creates a new Wasmer instance from @@ -104,7 +104,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceFromCompiledCodeWithOptions( compiledCode []byte, options executor.CompilationOptions, ) (executor.Instance, error) { - var c_instance *cWasmerInstanceT + var cInstance *cWasmerInstanceT if len(compiledCode) == 0 { return nil, newWrappedError(ErrInvalidBytecode) @@ -113,7 +113,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceFromCompiledCodeWithOptions( cOptions := unsafe.Pointer(&options) var compileResult = cWasmerInstanceFromCache( wasmerExecutor.cgoExecutor, - &c_instance, + &cInstance, (*cUchar)(unsafe.Pointer(&compiledCode[0])), cUint32T(len(compiledCode)), (*cWasmerCompilationOptions)(cOptions), @@ -123,7 +123,7 @@ func (wasmerExecutor *Wasmer2Executor) NewInstanceFromCompiledCodeWithOptions( return nil, newWrappedError(ErrFailedInstantiation) } - return newInstance(c_instance) + return newInstance(cInstance) } // IsInterfaceNil returns true if underlying object is nil