wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

AOT function call crashes due to issues with handling variable length types

Open sosotan opened this issue 10 months ago • 1 comments

Defining these types as function parameters can lead to this issue:size_t、intptr_t、long、void*

The wasm compiler defines size_t as 32-bit,but the aot runtime compile with msvc_x86_64,the size_t is 64-bit。

If we define a function in wasm with size_t param: foo(size_t a, size_t b, size_t c, size_t d, size_t e) // size_t as 32-bit

and it will call into aot runtime: aot_foo(size_t a, size_t b, size_t c, size_t d, size_t e) // size_t as 64-bit

The program may crash。

The reason is due to stack imbalance, especially for functions with more than 4 parameters, because the convention of MSVC is that the first 4 parameters are passed through registers, and the 5th parameter starts to be passed through the stack。

sosotan avatar Feb 27 '25 09:02 sosotan

Are you registering some native API? If so, you can refer to this document to use correct function signature to handle issue like this.

TianlongLiang avatar Feb 28 '25 03:02 TianlongLiang