GithubHelp home page GithubHelp logo

Comments (4)

wenyongh avatar wenyongh commented on May 27, 2024

Maybe the second way is better, since the issue not only occurs in the host function, but also may occur in runtime, .e.g. allocating argv buffer in wasm_runtime_invoke_native:

if (argc1 > sizeof(argv_buf) / sizeof(uint64)) {
size = sizeof(uint64) * (uint64)argc1;
if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst, NULL,
0))) {
return false;
}

It didn't happen since it is allocated only when the default buffer in local variable isn't enough and by default the latter is large enough (allows to call a wasm/host function with 31 arguments).

If we only care about the memory allocated by wasm_runtime_malloc, maybe we can auto handle it wasm_runtime_malloc, wasm_runtime_free and after longjmp:

  • in wasm_runtime_malloc, check whether runtime is calling the wasm/host function (e.g. whether the global exec_env_tls is not NULL and its jmp stack isn't NULL), and if yes, allocate an extra node to take the memory allocated, and add the node into current WASMJmpBuf's node list
  • in wasm_runtime_free, remove node which has the memory pointer to free in current WASMJmpBuf's node list
  • after longjmp, free current WASMJmpBuf's node list and the memory pointers inside them

from wasm-micro-runtime.

yamt avatar yamt commented on May 27, 2024

Maybe the second way is better, since the issue not only occurs in the host function, but also may occur in runtime, .e.g. allocating argv buffer in wasm_runtime_invoke_native:

right now i'm inclined towards the first approach because those checks are necessary for OS_ENABLE_HW_BOUND_CHECK=0 anyway.

from wasm-micro-runtime.

wenyongh avatar wenyongh commented on May 27, 2024

OK, and it would be good if we also fix the argv buffer allocation issue in wasm_runtime_invoke_native.

from wasm-micro-runtime.

yamt avatar yamt commented on May 27, 2024

another reason why (b) isn't enough is host-provided apis like libc functions.
when we hit the guard pages in the middle of libc, it's impossible to recover gracefully.

from wasm-micro-runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.