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

Missing UserData in LinearMemory for custom allocator #4024

Open
thomasbechet opened this issue Jan 14, 2025 · 0 comments
Open

Missing UserData in LinearMemory for custom allocator #4024

thomasbechet opened this issue Jan 14, 2025 · 0 comments

Comments

@thomasbechet
Copy link

thomasbechet commented Jan 14, 2025

Description

UserData is always NULL for custom allocator when usage is Alloc_For_LinearMemory.

Test case

Using this configuration :

set (WAMR_BUILD_GLOBAL_HEAP_POOL 0)
set (WAMR_BUILD_ALLOC_WITH_USAGE 1)
set (WAMR_BUILD_ALLOC_WITH_USER_DATA 1)

With this initialization :

init_args.mem_alloc_type                          = Alloc_With_Allocator;
init_args.mem_alloc_option.allocator.malloc_func  = wasm_malloc;
init_args.mem_alloc_option.allocator.realloc_func = wasm_realloc;
init_args.mem_alloc_option.allocator.free_func    = wasm_free;
init_args.mem_alloc_option.allocator.user_data    = vm;

With this custom allocator :

void * wasm_realloc (mem_alloc_usage_t usage,
              nu_bool_t         full_size_mmapped,
              void             *user,
              void             *p,
              nu_u32_t          n);
void * wasm_malloc (mem_alloc_usage_t usage, void *user, nu_size_t n);
void   wasm_free (mem_alloc_usage_t usage, void *user, void *p);

Implement a custom allocator with the given configuration, callbacks.

Your environment

  • Host OS : Linux
  • WAMR version 2.2.0, Linux

Steps to reproduce

  • Implement custom allocator and print user data pointer.

Expected behavior

I expect 'vm' (my user data) to be visible in the custom allocator callbacks
using the user parameter.

Actual behavior

However, it is NULL when usage = Alloc_For_LinearMemory.

Extra Info

Inspecting the code (wasm_memory.c), it is set to NULL for Alloc_For_LinearMemory allocation
and 'allocator_user_data' for Alloc_For_RuntimeMemory.
Changing the NULL to 'allocator_user_data' fixed the problem.

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