Skip to content

Conversation

@yamt
Copy link
Contributor

@yamt yamt commented Oct 11, 2022

Nothing wrong with passing structures and function pointers as far as the native code is aware of and careful about the ABI used in the wasm module.

Nothing wrong with passing structures and function pointers
as far as the native code is aware of and careful about the
ABI used in the wasm module.
@wenyongh wenyongh merged commit 1c89a37 into bytecodealliance:main Oct 12, 2022
A few recommendations:
- Never pass any structure/class object pointer to native (do data serialization instead)
- Do the pointer address conversion in the native API if "$\*" is not used for the pointer in the function signature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pointer address conversion is still a hard rule, not a recommendation?

Copy link
Contributor

@tonibofarull tonibofarull Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @loganek . The main question here is regarding the sentence:

Never pass a function pointer to the native

Can we pass a function pointer (using integer in the signature) to native and from the native side call this function with wasm_runtime_call_indirect? Is this the only way to pass a callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it depends on the api.
eg. a "user data" pointer for a callback, which is just passed back to the calling wasm module, needs no interpretation in native side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think this is more like a different case and I'm not convinced this should be bundled together in here. Or at least we should say something like:

Ground rule: Do the pointer address conversion in the native API if "$*" is not used for the pointer in the function signature, unless the pointer is not used in native code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. i got convinced. #1588

vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Nothing wrong with passing structures and function pointers
as far as the native code is aware of and careful about the
ABI used in the wasm module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants