-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2021 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "uvwasi.hpp" | ||
#include <uvwasi.h> | ||
|
||
namespace fizzy::wasi | ||
{ | ||
namespace | ||
{ | ||
class UVWASIImpl final : public UVWASI | ||
{ | ||
/// UVWASI state. | ||
uvwasi_t m_state{}; | ||
|
||
public: | ||
uvwasi_errno_t init(uvwasi_size_t argc, const char** argv) noexcept final | ||
{ | ||
// Initialisation settings. | ||
// TODO: Make const after https://github.com/nodejs/uvwasi/pull/155 is merged. | ||
uvwasi_options_t options = { | ||
3, // sizeof fd_table | ||
0, nullptr, // NOTE: no remappings | ||
argc, argv, | ||
nullptr, // TODO: support env | ||
0, 1, 2, | ||
nullptr, // NOTE: no special allocator | ||
}; | ||
return uvwasi_init(&m_state, &options); | ||
} | ||
|
||
uvwasi_errno_t proc_exit(uvwasi_exitcode_t exit_code) noexcept final | ||
{ | ||
return uvwasi_proc_exit(&m_state, exit_code); | ||
} | ||
|
||
uvwasi_errno_t fd_write(uvwasi_fd_t fd, const uvwasi_ciovec_t* iovs, uvwasi_size_t iovs_len, | ||
uvwasi_size_t* nwritten) noexcept final | ||
{ | ||
return uvwasi_fd_write(&m_state, fd, iovs, iovs_len, nwritten); | ||
} | ||
|
||
uvwasi_errno_t fd_read(uvwasi_fd_t fd, const uvwasi_iovec_t* iovs, uvwasi_size_t iovs_len, | ||
uvwasi_size_t* nread) noexcept final | ||
{ | ||
return uvwasi_fd_read(&m_state, fd, iovs, iovs_len, nread); | ||
} | ||
|
||
uvwasi_errno_t fd_prestat_get(uvwasi_fd_t fd, uvwasi_prestat_t* buf) noexcept final | ||
{ | ||
return uvwasi_fd_prestat_get(&m_state, fd, buf); | ||
} | ||
|
||
uvwasi_errno_t environ_sizes_get( | ||
uvwasi_size_t* environ_count, uvwasi_size_t* environ_buf_size) noexcept final | ||
{ | ||
return uvwasi_environ_sizes_get(&m_state, environ_count, environ_buf_size); | ||
} | ||
}; | ||
} // namespace | ||
|
||
UVWASI::~UVWASI() {} | ||
|
||
std::unique_ptr<UVWASI> create_uvwasi() | ||
{ | ||
return std::make_unique<UVWASIImpl>(); | ||
} | ||
} // namespace fizzy::wasi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2021 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <wasi_types.h> | ||
#include <memory> | ||
|
||
namespace fizzy::wasi | ||
{ | ||
/// UVWASI interface. | ||
class UVWASI | ||
{ | ||
public: | ||
virtual ~UVWASI(); | ||
|
||
virtual uvwasi_errno_t init(uvwasi_size_t argc, const char** argv) noexcept = 0; | ||
|
||
virtual uvwasi_errno_t proc_exit(uvwasi_exitcode_t exit_code) noexcept = 0; | ||
|
||
virtual uvwasi_errno_t fd_write(uvwasi_fd_t fd, const uvwasi_ciovec_t* iovs, | ||
uvwasi_size_t iovs_len, uvwasi_size_t* nwritten) noexcept = 0; | ||
|
||
virtual uvwasi_errno_t fd_read(uvwasi_fd_t fd, const uvwasi_iovec_t* iovs, | ||
uvwasi_size_t iovs_len, uvwasi_size_t* nread) noexcept = 0; | ||
|
||
virtual uvwasi_errno_t fd_prestat_get(uvwasi_fd_t fd, uvwasi_prestat_t* buf) noexcept = 0; | ||
|
||
virtual uvwasi_errno_t environ_sizes_get( | ||
uvwasi_size_t* environ_count, uvwasi_size_t* environ_buf_size) noexcept = 0; | ||
}; | ||
|
||
std::unique_ptr<UVWASI> create_uvwasi(); | ||
|
||
} // namespace fizzy::wasi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters