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

Implement missing unistd readv() #9631

Merged
merged 3 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions system/lib/libc/musl/src/unistd/readv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@

ssize_t readv(int fd, const struct iovec *iov, int count)
{
#if __EMSCRIPTEN__
size_t num;
if (__wasi_syscall_ret(__wasi_fd_read(fd, (struct __wasi_iovec_t*)iov, count, &num))) {
num = -1;
}
return num;
#else
return syscall_cp(SYS_readv, fd, iov, count);
#endif
}
1 change: 0 additions & 1 deletion tests/other/metadce/hello_world_O3_MAIN_MODULE.sent
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ __syscall133
__syscall14
__syscall142
__syscall144
__syscall145
__syscall147
__syscall148
__syscall15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ ___syscall133
___syscall14
___syscall142
___syscall144
___syscall145
___syscall147
___syscall148
___syscall15
Expand Down
4 changes: 2 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8087,7 +8087,7 @@ def test_binaryen_metadce_cxx_fastcomp(self, *args):
# don't compare the # of functions in a main module, which changes a lot
# TODO(sbc): Investivate why the number of exports is order of magnitude
# larger for wasm backend.
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 175, [], [], 517336, None, 1518, None), # noqa
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 174, [], [], 517336, None, 1518, None), # noqa
'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 12, [], [], 10770, 12, 10, None), # noqa
})
@no_fastcomp()
Expand All @@ -8107,7 +8107,7 @@ def test_binaryen_metadce_hello(self, *args):
4, [], [], 8, 0, 0, 0), # noqa; totally empty!
# we don't metadce with linkable code! other modules may want stuff
# don't compare the # of functions in a main module, which changes a lot
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1611, [], [], 226403, None, 107, None), # noqa
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1610, [], [], 226403, None, 107, None), # noqa
'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 20), # noqa
})
@no_wasm_backend()
Expand Down
21 changes: 21 additions & 0 deletions tests/unistd/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/uio.h>
#include <emscripten.h>

int main() {
Expand Down Expand Up @@ -188,5 +189,25 @@ int main() {
}
printf("\n");

// readv
printf("\n");
memset(readBuffer, 0, sizeof readBuffer);
struct iovec iov;
iov.iov_base = readBuffer;
iov.iov_len = sizeof readBuffer;
printf("seek: %d\n", lseek(f, 0, SEEK_SET));
printf("read after write: %d\n", bytesRead = readv(f, &iov, 1));
printf("errno: %d\n", errno);
errno = 0;
printf("final: ");
for (int i = 0; i < bytesRead; i++) {
if (readBuffer[i] == 0) {
printf("\\0");
} else {
printf("%c", readBuffer[i]);
}
}
printf("\n");

return 0;
}
5 changes: 5 additions & 0 deletions tests/unistd/io.out
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ seek: 0
read after write: 37
errno: 0
final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write

seek: 0
read after write: 37
errno: 0
final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write