Skip to content

Conversation

@TianlongLiang
Copy link
Collaborator

No description provided.

@yamt
Copy link
Collaborator

yamt commented Dec 8, 2025

can you elaborate use cases a bit?

@TianlongLiang
Copy link
Collaborator Author

can you elaborate use cases a bit?

For example, if a WASM module calls shared_heap_malloc a few times and an exception occurs before it gets a chance to free it, then the WAMR runtime-managed shared heap will have some dangling pointer(some memory block can't be allocated) until the runtime destroys and reinitializes. This api provides a lighter way to reset(allow the whole WAMR runtime-managed shared heap to become allocatable) the shared heaps without re-initializing the runtime.

@yamt
Copy link
Collaborator

yamt commented Dec 8, 2025

can you elaborate use cases a bit?

For example, if a WASM module calls shared_heap_malloc a few times and an exception occurs before it gets a chance to free it, then the WAMR runtime-managed shared heap will have some dangling pointer(some memory block can't be allocated) until the runtime destroys and reinitializes. This api provides a lighter way to reset(allow the whole WAMR runtime-managed shared heap to become allocatable) the shared heaps without re-initializing the runtime.

so,

  • it's an equivalent of destroy + re-create
  • not intended to be used for a chain being used by running instances

right?

unsigned int wasm_file_size = 0;
unsigned int stack_size = 16 * 1024, heap_size = app_heap_size;
char error_buf[128] = { 0 };
char error_buf[128] = {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a change for "fix some warnings"?
what warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

warning: missing initializer for member ‘SharedHeapInitArgs::pre_allocated_addr’ [-Wmissing-field-initializers]
1081 |     SharedHeapInitArgs args = { 0 };

I simply replaced all occurrences in this file.

I remember that we had a discussion about the choice between {0} and {}, for C++, {} should be a more future-proof version, right?

EXPECT_EQ(offset, offset_after_reset);
EXPECT_EQ(native_ptr, native_ptr_after_reset);

/* Only on some platform, the os_mmap will memset the memory to 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this mean that in some cases shared memory may have uninitialized user-visible contents?
is it documented somewhere?

Copy link
Collaborator Author

@TianlongLiang TianlongLiang Dec 9, 2025

Choose a reason for hiding this comment

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

Seems that on Linux it won't reset to 0(the commented-out lines will fail), though it should, given our implementation uses MAP_ANONYMOUS., I will dig into it

@TianlongLiang
Copy link
Collaborator Author

can you elaborate use cases a bit?

For example, if a WASM module calls shared_heap_malloc a few times and an exception occurs before it gets a chance to free it, then the WAMR runtime-managed shared heap will have some dangling pointer(some memory block can't be allocated) until the runtime destroys and reinitializes. This api provides a lighter way to reset(allow the whole WAMR runtime-managed shared heap to become allocatable) the shared heaps without re-initializing the runtime.

so,

  • it's an equivalent of destroy + re-create
  • not intended to be used for a chain being used by running instances

right?

Yes, you are right :)

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.

2 participants