1 #ifndef __UVWASI_FD_TABLE_H__ 2 #define __UVWASI_FD_TABLE_H__ 3 4 #include <stdint.h> 5 #include "uv.h" 6 #include "wasi_types.h" 7 8 struct uvwasi_s; 9 struct uvwasi_options_s; 10 11 struct uvwasi_fd_wrap_t { 12 uvwasi_fd_t id; 13 uv_file fd; 14 uv_tcp_t* sock; 15 char* path; 16 char* real_path; 17 char* normalized_path; 18 uvwasi_filetype_t type; 19 uvwasi_rights_t rights_base; 20 uvwasi_rights_t rights_inheriting; 21 int preopen; 22 uv_mutex_t mutex; 23 }; 24 25 struct uvwasi_fd_table_t { 26 struct uvwasi_fd_wrap_t** fds; 27 uint32_t size; 28 uint32_t used; 29 uv_rwlock_t rwlock; 30 }; 31 32 uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi, 33 const struct uvwasi_options_s* options); 34 void uvwasi_fd_table_free(struct uvwasi_s* uvwasi, 35 struct uvwasi_fd_table_t* table); 36 uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi, 37 struct uvwasi_fd_table_t* table, 38 uv_file fd, 39 uv_tcp_t* sock, 40 const char* mapped_path, 41 const char* real_path, 42 uvwasi_filetype_t type, 43 uvwasi_rights_t rights_base, 44 uvwasi_rights_t rights_inheriting, 45 int preopen, 46 struct uvwasi_fd_wrap_t** wrap); 47 uvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_s* uvwasi, 48 struct uvwasi_fd_table_t* table, 49 const uv_file fd, 50 const char* path, 51 const char* real_path); 52 uvwasi_errno_t uvwasi_fd_table_insert_preopen_socket(struct uvwasi_s* uvwasi, 53 struct uvwasi_fd_table_t* table, 54 uv_tcp_t* sock); 55 uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table, 56 const uvwasi_fd_t id, 57 struct uvwasi_fd_wrap_t** wrap, 58 uvwasi_rights_t rights_base, 59 uvwasi_rights_t rights_inheriting); 60 uvwasi_errno_t uvwasi_fd_table_get_nolock(struct uvwasi_fd_table_t* table, 61 const uvwasi_fd_t id, 62 struct uvwasi_fd_wrap_t** wrap, 63 uvwasi_rights_t rights_base, 64 uvwasi_rights_t rights_inheriting); 65 uvwasi_errno_t uvwasi_fd_table_remove_nolock(struct uvwasi_s* uvwasi, 66 struct uvwasi_fd_table_t* table, 67 const uvwasi_fd_t id); 68 uvwasi_errno_t uvwasi_fd_table_renumber(struct uvwasi_s* uvwasi, 69 struct uvwasi_fd_table_t* table, 70 const uvwasi_fd_t dst, 71 const uvwasi_fd_t src); 72 uvwasi_errno_t uvwasi_fd_table_lock(struct uvwasi_fd_table_t* table); 73 uvwasi_errno_t uvwasi_fd_table_unlock(struct uvwasi_fd_table_t* table); 74 75 #endif /* __UVWASI_FD_TABLE_H__ */ 76