Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory errors on Wasm32 due to wrong pointer size #755

Open
benozol opened this issue Sep 11, 2023 · 1 comment
Open

Memory errors on Wasm32 due to wrong pointer size #755

benozol opened this issue Sep 11, 2023 · 1 comment

Comments

@benozol
Copy link

benozol commented Sep 11, 2023

(follow up to #753)

Executing a program that uses ocaml-ctypes on a platform where the word size differs from the word size of the platform where the program was originally compiled results in memory errors due to the wrong pointer arithmetic. We ran into this issue after first compiling an OCaml program on a 64-bit platform to OCaml bytecode and then compiling the OCaml bytecode to 32-bit WebAssembly (in our case using wasicaml, but the same issue is expected using wasm_of_ocaml).

In #753 we experimented with deriving sizes and alignments of pointers (and size_t) from Sys.word_size, but this isn't enough in general (the size of other C types might differ too, also depending on the compiler).

@benozol
Copy link
Author

benozol commented Sep 11, 2023

Retrieving the sizes from the C implementation is problematic for Wasm, because gen_c_primitives won't run as is on Wasm (and even a simplified form would require a Wasm toolchain to compile the library). One alternative might be to pre-define sizes and alignments for specific, non-native platforms (like Wasm32), and select that at runtime (e.g. using an environment variable CTYPES_PLATFORM=WASM32).

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

No branches or pull requests

1 participant