-
Notifications
You must be signed in to change notification settings - Fork 15
Problem using "_innative_funcptr" #25
Description
Sorry for the cross-post with the Discord channel but I thought it might be better for InNative users to see this discussion here.
I am currently trying to get a pointer to a function that resides in a WASM module so that it can be called back by a C module. I used the "_innative_funcptr" function to get a C-style pointer from within my WASM module, but it always returns ERR_INVALID_ARGUMENT_TYPE instead of the expected pointer.
Tracing into the code, I found that the cast "auto v = llvm::dyn_cast<llvm::ConstantInt, llvm::Value>(params[0]);" done in "innative::code::IN_Intrinsic_FuncPtr" always failed.
Here is (part of) the WAT code I am using (made it dead simple while debugging, just trying to access the 7th function in the module - the "final" aim is actually to call another C-function with the correct i64 pointer as a parameter...).
(type (;6;) (func (param i32) (result i64)))
(type (;9;) (func (result i32)))
(import "env" "_innative_funcptr" (func $_innative_funcptr (type 6)))
(func $do_simple_test(type 9) (result i32)
(local i32 i32)
i32.const 0
local.set 0
i32.const 7
local.set 1
local.get 1
call $_innative_funcptr
drop
local.get 0
return)
It looks like LLVM does not consider the parameter passed to _innative_funcptr as a constant (which is not totally wrong!). However, I don't understand how to make this work - hope someone can help!