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 char* path; 15 char* real_path; 16 char* normalized_path; 17 uvwasi_filetype_t type; 18 uvwasi_rights_t rights_base; 19 uvwasi_rights_t rights_inheriting; 20 int preopen; 21 uv_mutex_t mutex; 22 }; 23 24 struct uvwasi_fd_table_t { 25 struct uvwasi_fd_wrap_t** fds; 26 uint32_t size; 27 uint32_t used; 28 uv_rwlock_t rwlock; 29 }; 30 31 uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi, 32 struct uvwasi_options_s* options); 33 void uvwasi_fd_table_free(struct uvwasi_s* uvwasi, 34 struct uvwasi_fd_table_t* table); 35 uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi, 36 struct uvwasi_fd_table_t* table, 37 uv_file fd, 38 const char* mapped_path, 39 const char* real_path, 40 uvwasi_filetype_t type, 41 uvwasi_rights_t rights_base, 42 uvwasi_rights_t rights_inheriting, 43 int preopen, 44 struct uvwasi_fd_wrap_t** wrap); 45 uvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_s* uvwasi, 46 struct uvwasi_fd_table_t* table, 47 const uv_file fd, 48 const char* path, 49 const char* real_path); 50 uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table, 51 const uvwasi_fd_t id, 52 struct uvwasi_fd_wrap_t** wrap, 53 uvwasi_rights_t rights_base, 54 uvwasi_rights_t rights_inheriting); 55 uvwasi_errno_t uvwasi_fd_table_get_nolock(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_remove_nolock(struct uvwasi_s* uvwasi, 61 struct uvwasi_fd_table_t* table, 62 const uvwasi_fd_t id); 63 uvwasi_errno_t uvwasi_fd_table_renumber(struct uvwasi_s* uvwasi, 64 struct uvwasi_fd_table_t* table, 65 const uvwasi_fd_t dst, 66 const uvwasi_fd_t src); 67 uvwasi_errno_t uvwasi_fd_table_lock(struct uvwasi_fd_table_t* table); 68 uvwasi_errno_t uvwasi_fd_table_unlock(struct uvwasi_fd_table_t* table); 69 70 #endif /* __UVWASI_FD_TABLE_H__ */ 71