| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "wasi_types.h" | |
| 7 | 7 | ||
| 8 | 8 | struct uvwasi_s; | |
| 9 | + struct uvwasi_options_s; | ||
| 9 | 10 | ||
| 10 | 11 | struct uvwasi_fd_wrap_t { | |
| 11 | 12 | uvwasi_fd_t id; | |
@@ -27,8 +28,7 @@ struct uvwasi_fd_table_t { | |||
| 27 | 28 | }; | |
| 28 | 29 | ||
| 29 | 30 | uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi, | |
| 30 | - struct uvwasi_fd_table_t* table, | ||
| 31 | - uint32_t init_size); | ||
| 31 | + struct uvwasi_options_s* options); | ||
| 32 | 32 | void uvwasi_fd_table_free(struct uvwasi_s* uvwasi, | |
| 33 | 33 | struct uvwasi_fd_table_t* table); | |
| 34 | 34 | uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ extern "C" { | |||
| 11 | 11 | ||
| 12 | 12 | #define UVWASI_VERSION_MAJOR 0 | |
| 13 | 13 | #define UVWASI_VERSION_MINOR 0 | |
| 14 | - #define UVWASI_VERSION_PATCH 5 | ||
| 14 | + #define UVWASI_VERSION_PATCH 6 | ||
| 15 | 15 | #define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \ | |
| 16 | 16 | (UVWASI_VERSION_MINOR << 8) | \ | |
| 17 | 17 | (UVWASI_VERSION_PATCH)) | |
@@ -60,6 +60,9 @@ typedef struct uvwasi_options_s { | |||
| 60 | 60 | size_t argc; | |
| 61 | 61 | char** argv; | |
| 62 | 62 | char** envp; | |
| 63 | + uvwasi_fd_t in; | ||
| 64 | + uvwasi_fd_t out; | ||
| 65 | + uvwasi_fd_t err; | ||
| 63 | 66 | const uvwasi_mem_t* allocator; | |
| 64 | 67 | } uvwasi_options_t; | |
| 65 | 68 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #endif /* _WIN32 */ | |
| 7 | 7 | ||
| 8 | 8 | #include "uv.h" | |
| 9 | + #include "clocks.h" | ||
| 9 | 10 | #include "wasi_types.h" | |
| 10 | 11 | #include "uv_mapping.h" | |
| 11 | 12 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,46 @@ | |||
| 14 | 14 | #include "uvwasi_alloc.h" | |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi, | ||
| 18 | + struct uvwasi_fd_table_t* table, | ||
| 19 | + const uvwasi_fd_t fd, | ||
| 20 | + const uvwasi_fd_t expected, | ||
| 21 | + const char* name) { | ||
| 22 | + struct uvwasi_fd_wrap_t* wrap; | ||
| 23 | + uvwasi_filetype_t type; | ||
| 24 | + uvwasi_rights_t base; | ||
| 25 | + uvwasi_rights_t inheriting; | ||
| 26 | + uvwasi_errno_t err; | ||
| 27 | + | ||
| 28 | + err = uvwasi__get_filetype_by_fd(fd, &type); | ||
| 29 | + if (err != UVWASI_ESUCCESS) | ||
| 30 | + return err; | ||
| 31 | + | ||
| 32 | + err = uvwasi__get_rights(fd, UV_FS_O_RDWR, type, &base, &inheriting); | ||
| 33 | + if (err != UVWASI_ESUCCESS) | ||
| 34 | + return err; | ||
| 35 | + | ||
| 36 | + err = uvwasi_fd_table_insert(uvwasi, | ||
| 37 | + table, | ||
| 38 | + fd, | ||
| 39 | + name, | ||
| 40 | + name, | ||
| 41 | + type, | ||
| 42 | + base, | ||
| 43 | + inheriting, | ||
| 44 | + 0, | ||
| 45 | + &wrap); | ||
| 46 | + if (err != UVWASI_ESUCCESS) | ||
| 47 | + return err; | ||
| 48 | + | ||
| 49 | + if (wrap->id != expected) | ||
| 50 | + err = UVWASI_EBADF; | ||
| 51 | + | ||
| 52 | + uv_mutex_unlock(&wrap->mutex); | ||
| 53 | + return err; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + | ||
| 17 | 57 | uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | |
| 18 | 58 | struct uvwasi_fd_table_t* table, | |
| 19 | 59 | uv_file fd, | |
@@ -28,7 +68,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | |||
| 28 | 68 | struct uvwasi_fd_wrap_t** new_fds; | |
| 29 | 69 | uvwasi_errno_t err; | |
| 30 | 70 | uint32_t new_size; | |
| 31 | - int index; | ||
| 71 | + uint32_t index; | ||
| 32 | 72 | uint32_t i; | |
| 33 | 73 | int r; | |
| 34 | 74 | size_t mp_len; | |
@@ -69,16 +109,17 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | |||
| 69 | 109 | table->size = new_size; | |
| 70 | 110 | } else { | |
| 71 | 111 | /* The table is big enough, so find an empty slot for the new data. */ | |
| 72 | - index = -1; | ||
| 112 | + int valid_slot = 0; | ||
| 73 | 113 | for (i = 0; i < table->size; ++i) { | |
| 74 | 114 | if (table->fds[i] == NULL) { | |
| 115 | + valid_slot = 1; | ||
| 75 | 116 | index = i; | |
| 76 | 117 | break; | |
| 77 | 118 | } | |
| 78 | 119 | } | |
| 79 | 120 | ||
| 80 | - /* index should never be -1. */ | ||
| 81 | - if (index == -1) { | ||
| 121 | + /* This should never happen. */ | ||
| 122 | + if (valid_slot == 0) { | ||
| 82 | 123 | uvwasi__free(uvwasi, entry); | |
| 83 | 124 | err = UVWASI_ENOSPC; | |
| 84 | 125 | goto exit; | |
@@ -116,25 +157,21 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | |||
| 116 | 157 | ||
| 117 | 158 | ||
| 118 | 159 | uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, | |
| 119 | - struct uvwasi_fd_table_t* table, | ||
| 120 | - uint32_t init_size) { | ||
| 121 | - struct uvwasi_fd_wrap_t* wrap; | ||
| 122 | - uvwasi_filetype_t type; | ||
| 123 | - uvwasi_rights_t base; | ||
| 124 | - uvwasi_rights_t inheriting; | ||
| 160 | + uvwasi_options_t* options) { | ||
| 161 | + struct uvwasi_fd_table_t* table; | ||
| 125 | 162 | uvwasi_errno_t err; | |
| 126 | - uvwasi_fd_t i; | ||
| 127 | 163 | int r; | |
| 128 | 164 | ||
| 129 | 165 | /* Require an initial size of at least three to store the stdio FDs. */ | |
| 130 | - if (table == NULL || init_size < 3) | ||
| 166 | + if (uvwasi == NULL || options == NULL || options->fd_table_size < 3) | ||
| 131 | 167 | return UVWASI_EINVAL; | |
| 132 | 168 | ||
| 169 | + table = &uvwasi->fds; | ||
| 133 | 170 | table->fds = NULL; | |
| 134 | 171 | table->used = 0; | |
| 135 | - table->size = init_size; | ||
| 172 | + table->size = options->fd_table_size; | ||
| 136 | 173 | table->fds = uvwasi__calloc(uvwasi, | |
| 137 | - init_size, | ||
| 174 | + options->fd_table_size, | ||
| 138 | 175 | sizeof(struct uvwasi_fd_wrap_t*)); | |
| 139 | 176 | ||
| 140 | 177 | if (table->fds == NULL) | |
@@ -153,35 +190,17 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, | |||
| 153 | 190 | } | |
| 154 | 191 | ||
| 155 | 192 | /* Create the stdio FDs. */ | |
| 156 | - for (i = 0; i < 3; ++i) { | ||
| 157 | - err = uvwasi__get_filetype_by_fd(i, &type); | ||
| 158 | - if (err != UVWASI_ESUCCESS) | ||
| 159 | - goto error_exit; | ||
| 160 | - | ||
| 161 | - err = uvwasi__get_rights(i, UV_FS_O_RDWR, type, &base, &inheriting); | ||
| 162 | - if (err != UVWASI_ESUCCESS) | ||
| 163 | - goto error_exit; | ||
| 164 | - | ||
| 165 | - err = uvwasi_fd_table_insert(uvwasi, | ||
| 166 | - table, | ||
| 167 | - i, | ||
| 168 | - "", | ||
| 169 | - "", | ||
| 170 | - type, | ||
| 171 | - base, | ||
| 172 | - inheriting, | ||
| 173 | - 0, | ||
| 174 | - &wrap); | ||
| 175 | - if (err != UVWASI_ESUCCESS) | ||
| 176 | - goto error_exit; | ||
| 177 | - | ||
| 178 | - r = wrap->id != i || wrap->id != (uvwasi_fd_t) wrap->fd; | ||
| 179 | - uv_mutex_unlock(&wrap->mutex); | ||
| 180 | - if (r) { | ||
| 181 | - err = UVWASI_EBADF; | ||
| 182 | - goto error_exit; | ||
| 183 | - } | ||
| 184 | - } | ||
| 193 | + err = uvwasi__insert_stdio(uvwasi, table, options->in, 0, "<stdin>"); | ||
| 194 | + if (err != UVWASI_ESUCCESS) | ||
| 195 | + goto error_exit; | ||
| 196 | + | ||
| 197 | + err = uvwasi__insert_stdio(uvwasi, table, options->out, 1, "<stdout>"); | ||
| 198 | + if (err != UVWASI_ESUCCESS) | ||
| 199 | + goto error_exit; | ||
| 200 | + | ||
| 201 | + err = uvwasi__insert_stdio(uvwasi, table, options->err, 2, "<stderr>"); | ||
| 202 | + if (err != UVWASI_ESUCCESS) | ||
| 203 | + goto error_exit; | ||
| 185 | 204 | ||
| 186 | 205 | return UVWASI_ESUCCESS; | |
| 187 | 206 | error_exit: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,11 @@ | |||
| 34 | 34 | # define PATH_MAX_BYTES (PATH_MAX) | |
| 35 | 35 | #endif | |
| 36 | 36 | ||
| 37 | + /* IBMi PASE does not support posix_fadvise() */ | ||
| 38 | + #ifdef __PASE__ | ||
| 39 | + # undef POSIX_FADV_NORMAL | ||
| 40 | + #endif | ||
| 41 | + | ||
| 37 | 42 | static void* default_malloc(size_t size, void* mem_user_data) { | |
| 38 | 43 | return malloc(size); | |
| 39 | 44 | } | |
@@ -569,7 +574,7 @@ uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options) { | |||
| 569 | 574 | } | |
| 570 | 575 | } | |
| 571 | 576 | ||
| 572 | - err = uvwasi_fd_table_init(uvwasi, &uvwasi->fds, options->fd_table_size); | ||
| 577 | + err = uvwasi_fd_table_init(uvwasi, options); | ||
| 573 | 578 | if (err != UVWASI_ESUCCESS) | |
| 574 | 579 | goto exit; | |
| 575 | 580 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,6 +170,9 @@ void WASI::New(const FunctionCallbackInfo<Value>& args) { | |||
| 170 | 170 | const uint32_t argc = argv->Length(); | |
| 171 | 171 | uvwasi_options_t options; | |
| 172 | 172 | ||
| 173 | + options.in = 0; | ||
| 174 | + options.out = 1; | ||
| 175 | + options.err = 2; | ||
| 173 | 176 | options.fd_table_size = 3; | |
| 174 | 177 | options.argc = argc; | |
| 175 | 178 | options.argv = argc == 0 ? nullptr : new char*[argc]; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments