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

wasi: Add UVWASI interface #792

Merged
merged 3 commits into from
May 11, 2021
Merged

wasi: Add UVWASI interface #792

merged 3 commits into from
May 11, 2021

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented May 5, 2021

Pulled out of #790

@gumb0 gumb0 marked this pull request as draft May 5, 2021 14:04
uvwasi_t m_state{};

public:
~UVWASIImpl() final { uvwasi_destroy(&m_state); }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently we'll need a flag to check if uvwasi_init was already called sucessfully.

@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #792 (18440ee) into master (5a3b3fc) will decrease coverage by 0.08%.
The diff coverage is 77.27%.

@@            Coverage Diff             @@
##           master     #792      +/-   ##
==========================================
- Coverage   99.23%   99.14%   -0.09%     
==========================================
  Files          79       80       +1     
  Lines       12394    12443      +49     
==========================================
+ Hits        12299    12337      +38     
- Misses         95      106      +11     
Flag Coverage Δ
rust 99.90% <ø> (+<0.01%) ⬆️
spectests 90.54% <ø> (ø)
unittests 99.07% <77.27%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tools/wasi/uvwasi.cpp 69.23% <69.23%> (ø)
tools/wasi/wasi.cpp 59.40% <72.00%> (-0.17%) ⬇️
test/unittests/wasi_test.cpp 100.00% <100.00%> (ø)
bindings/rust/src/lib.rs 99.90% <0.00%> (+<0.01%) ⬆️

auto module = parse(wasm_binary);
auto imports = resolve_imported_functions(*module, wasi_functions);
return instantiate(std::move(module), std::move(imports), {}, {}, {}, MaxMemoryPagesLimit);
}
Copy link
Member

Choose a reason for hiding this comment

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

We had an assert(instance != nullptr) in the old place. Worth keeping here or unique_ptr ensures it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unique_ptr doesn't care, but instantiate reports errors by throwing, so I don't think it's useful.

@@ -26,6 +31,18 @@ std::optional<bytes> load_file(std::string_view file, std::ostream& err) noexcep
/// @todo Make noexcept.
bool load_and_run(int argc, const char** argv, std::ostream& err);

/// Instantiates a module that imports WASI functions.
std::unique_ptr<Instance> instantiate(bytes_view wasm_binary);
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason behind splitting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To access instance in tests after run.

@gumb0 gumb0 force-pushed the wasi-instance branch 2 times, most recently from 8739786 to d43a350 Compare May 6, 2021 11:24
tools/wasi/uvwasi.hpp Show resolved Hide resolved
const uvwasi_errno_t uvwasi_err = uvwasi_init(&state, &options);
bool run(Instance& instance, int argc, const char* argv[], std::ostream& err)
{
if (!uvwasi)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is good idea, for many reasons (e.g. not thread-safe, hidden dependencies). Why just not add UVWASI& param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good idea.

Do you want also to pass it into WASI functions via host_context to make it thread-safe?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why this would be needed. This object will be bound to the imported functions, right?
By "not-thread-safe" I mean the initialization. I think this should be propagated up to the main() function which should invoke create_uvwasi(). And fizzy-unittest-wasi will execute create_mocked_uvwasi() if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see why this would be needed. This object will be bound to the imported functions, right?

What do you mean by bound? The way to bind it in current API is to pass it via host_context.

See the latest version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks good.

public:
~UVWASIImpl() final
{
if (m_inited)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also suggested a change to uvwasi to handle this nodejs/uvwasi#163

But it won't help the case with calling init twice, so we need a flag anyway.

@gumb0 gumb0 marked this pull request as ready for review May 10, 2021 08:10
@gumb0 gumb0 requested review from axic and chfast May 10, 2021 08:10
@@ -13,10 +13,20 @@ class UVWASIImpl final : public UVWASI
{
/// UVWASI state.
uvwasi_t m_state{};
bool m_inited = false;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps m_initialised is more correct, but fine either way.

@gumb0 gumb0 merged commit 620b71d into master May 11, 2021
@gumb0 gumb0 deleted the wasi-instance branch May 11, 2021 09:54
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.

3 participants