Skip to content

Missing UserData in LinearMemory for custom allocator #4024

Closed
@thomasbechet

Description

@thomasbechet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions