Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gkgoat1
Copy link

@gkgoat1 gkgoat1 commented Jan 22, 2025

This implements lazy-loaded and file-backed mappings for WASI.

TODO: Browser and Native Support.

This should not be merged until I can work those targets out, but I am open to review on the WASI part, to start.

Copy link
Owner

@yomaytk yomaytk left a comment

Choose a reason for hiding this comment

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

@gkgoat1
Thank you for the suggestion! And I'm sorry for the late reply.

In the latest implementation, mmap is implemented only for heap areas(for using malloc and so on), so it may be good to implement every memory area and lazy mapping. However, In the recent analysis, I found that address translation (i.e. TranslateVMA) incurs large performance overheads. So, we'll need to be careful about the memory access implementation (Now, I am trying to avoid address translation as much as possible).
So, if you change the process of memory access, please check the performance comparing the latest commit (it is easy to try to execute linpack: examples/benchmarks/linpack).

return *(uint8_t *) runtime_manager->TranslateVMA(addr);
uint8_t __remill_read_memory_8(RuntimeManager *g_run_mgr, addr_t addr) {
uint8_t a;
g_run_mgr->read(addr, &a);
Copy link
Owner

Choose a reason for hiding this comment

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

Calling g_run_mgr->read or g_run_mgr->write for every memory access may incur performance overhead.

}
uint8_t RuntimeManager::get(uint64_t vma_addr) {
if (vma_addr >= stack_memory->vma) {
if (stack_memory->other_memory) {
Copy link
Owner

Choose a reason for hiding this comment

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

Probably, the conditional check for other_memory should not be used for general memory access in terms of performances.

void read(uint64_t p, T *b, size_t c = 1) {
uint8_t buf[sizeof(T) * c];
for (size_t a = 0; a < sizeof(T) * c; a++)
buf[a] = get(p + a);
Copy link
Owner

Choose a reason for hiding this comment

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

calliing get for every character may incur performance overhead.

uint8_t buf[sizeof(T) * c];
memcpy((void *) buf, (const void *) b, sizeof(T) * c);
for (size_t a = 0; a < sizeof(T) * c; a++)
set(p + a, buf[a]);
Copy link
Owner

Choose a reason for hiding this comment

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

Same above (line 94).

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