-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement directory mapping and WASI file functions
Refactor the importing of WASI functions to be clearer. Implement path_open, fd_seek, fd_read, environ_sizes_get, environ_get for file acces. Implement the mapping of real directories to virtual ones so that WASI can use different directories. Add flag '--mapdirs' 'real' 'virtual' for mapping directories. Add flag '--env' for sharing host envrionment variables. Add flag '--help' for printing available walrus options. Also improve random_get test to not have a result. Signed-off-by: Adam Laszlo Kulcsar <kuladam@inf.u-szeged.hu>
- Loading branch information
1 parent
4de6ab7
commit 478a393
Showing
14 changed files
with
488 additions
and
19 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
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,41 @@ | ||
/* | ||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Walrus { | ||
|
||
void WASI::environ_sizes_get(ExecutionState& state, Value* argv, Value* result, Instance* instance) | ||
{ | ||
uint32_t count = argv[0].asI32(); | ||
uint32_t buf = argv[1].asI32(); | ||
|
||
uvwasi_size_t* uvCount = reinterpret_cast<uvwasi_size_t*>(instance->memory(0)->buffer() + count); | ||
uvwasi_size_t* uvBufSize = reinterpret_cast<uvwasi_size_t*>(instance->memory(0)->buffer() + buf); | ||
|
||
result[0] = Value(static_cast<uint16_t>(uvwasi_environ_sizes_get(WASI::m_uvwasi, uvCount, uvBufSize))); | ||
} | ||
|
||
void WASI::environ_get(ExecutionState& state, Value* argv, Value* result, Instance* instance) | ||
{ | ||
uint32_t env = argv[0].asI32(); | ||
uint32_t environBuf = argv[1].asI32(); | ||
|
||
char** uvEnviron = reinterpret_cast<char**>(instance->memory(0)->buffer() + env); | ||
char* uvEnvironBuf = reinterpret_cast<char*>(instance->memory(0)->buffer() + environBuf); | ||
|
||
result[0] = Value(static_cast<uint16_t>(uvwasi_environ_get(WASI::m_uvwasi, uvEnviron, uvEnvironBuf))); | ||
} | ||
|
||
} // namespace Walrus |
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,48 @@ | ||
/* | ||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Walrus { | ||
|
||
void WASI::path_open(ExecutionState& state, Value* argv, Value* result, Instance* instance) | ||
{ | ||
uint32_t fd = argv[0].asI32(); | ||
uint32_t dirflags = argv[1].asI32(); | ||
uint32_t path_offset = argv[2].asI32(); | ||
uint32_t len = argv[3].asI32(); | ||
uint32_t oflags = argv[4].asI32(); | ||
uint64_t rights = argv[5].asI64(); | ||
uint64_t right_inheriting = argv[6].asI64(); | ||
uint32_t fdflags = argv[7].asI32(); | ||
uint32_t ret_fd_offset = argv[8].asI32(); | ||
|
||
uvwasi_fd_t* ret_fd = reinterpret_cast<uvwasi_fd_t*>(instance->memory(0)->buffer() + ret_fd_offset); | ||
|
||
const char* path = reinterpret_cast<char*>(instance->memory(0)->buffer() + path_offset); | ||
|
||
result[0] = Value(static_cast<uint16_t>( | ||
uvwasi_path_open(WASI::m_uvwasi, | ||
fd, | ||
dirflags, | ||
path, | ||
len, | ||
oflags, | ||
rights, | ||
right_inheriting, | ||
fdflags, | ||
ret_fd))); | ||
} | ||
|
||
} // namespace Walrus |
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
Oops, something went wrong.