11cb0ef41Sopenharmony_ci#ifndef __UVWASI_FD_TABLE_H__
21cb0ef41Sopenharmony_ci#define __UVWASI_FD_TABLE_H__
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci#include <stdint.h>
51cb0ef41Sopenharmony_ci#include "uv.h"
61cb0ef41Sopenharmony_ci#include "wasi_types.h"
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cistruct uvwasi_s;
91cb0ef41Sopenharmony_cistruct uvwasi_options_s;
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cistruct uvwasi_fd_wrap_t {
121cb0ef41Sopenharmony_ci  uvwasi_fd_t id;
131cb0ef41Sopenharmony_ci  uv_file fd;
141cb0ef41Sopenharmony_ci  uv_tcp_t* sock;
151cb0ef41Sopenharmony_ci  char* path;
161cb0ef41Sopenharmony_ci  char* real_path;
171cb0ef41Sopenharmony_ci  char* normalized_path;
181cb0ef41Sopenharmony_ci  uvwasi_filetype_t type;
191cb0ef41Sopenharmony_ci  uvwasi_rights_t rights_base;
201cb0ef41Sopenharmony_ci  uvwasi_rights_t rights_inheriting;
211cb0ef41Sopenharmony_ci  int preopen;
221cb0ef41Sopenharmony_ci  uv_mutex_t mutex;
231cb0ef41Sopenharmony_ci};
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cistruct uvwasi_fd_table_t {
261cb0ef41Sopenharmony_ci  struct uvwasi_fd_wrap_t** fds;
271cb0ef41Sopenharmony_ci  uint32_t size;
281cb0ef41Sopenharmony_ci  uint32_t used;
291cb0ef41Sopenharmony_ci  uv_rwlock_t rwlock;
301cb0ef41Sopenharmony_ci};
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi,
331cb0ef41Sopenharmony_ci                                    const struct uvwasi_options_s* options);
341cb0ef41Sopenharmony_civoid uvwasi_fd_table_free(struct uvwasi_s* uvwasi,
351cb0ef41Sopenharmony_ci                          struct uvwasi_fd_table_t* table);
361cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi,
371cb0ef41Sopenharmony_ci                                      struct uvwasi_fd_table_t* table,
381cb0ef41Sopenharmony_ci                                      uv_file fd,
391cb0ef41Sopenharmony_ci                                      uv_tcp_t* sock,
401cb0ef41Sopenharmony_ci                                      const char* mapped_path,
411cb0ef41Sopenharmony_ci                                      const char* real_path,
421cb0ef41Sopenharmony_ci                                      uvwasi_filetype_t type,
431cb0ef41Sopenharmony_ci                                      uvwasi_rights_t rights_base,
441cb0ef41Sopenharmony_ci                                      uvwasi_rights_t rights_inheriting,
451cb0ef41Sopenharmony_ci                                      int preopen,
461cb0ef41Sopenharmony_ci                                      struct uvwasi_fd_wrap_t** wrap);
471cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_s* uvwasi,
481cb0ef41Sopenharmony_ci                                              struct uvwasi_fd_table_t* table,
491cb0ef41Sopenharmony_ci                                              const uv_file fd,
501cb0ef41Sopenharmony_ci                                              const char* path,
511cb0ef41Sopenharmony_ci                                              const char* real_path);
521cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_insert_preopen_socket(struct uvwasi_s* uvwasi,
531cb0ef41Sopenharmony_ci                                              struct uvwasi_fd_table_t* table,
541cb0ef41Sopenharmony_ci                                              uv_tcp_t* sock);
551cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table,
561cb0ef41Sopenharmony_ci                                   const uvwasi_fd_t id,
571cb0ef41Sopenharmony_ci                                   struct uvwasi_fd_wrap_t** wrap,
581cb0ef41Sopenharmony_ci                                   uvwasi_rights_t rights_base,
591cb0ef41Sopenharmony_ci                                   uvwasi_rights_t rights_inheriting);
601cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_get_nolock(struct uvwasi_fd_table_t* table,
611cb0ef41Sopenharmony_ci                                          const uvwasi_fd_t id,
621cb0ef41Sopenharmony_ci                                          struct uvwasi_fd_wrap_t** wrap,
631cb0ef41Sopenharmony_ci                                          uvwasi_rights_t rights_base,
641cb0ef41Sopenharmony_ci                                          uvwasi_rights_t rights_inheriting);
651cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_remove_nolock(struct uvwasi_s* uvwasi,
661cb0ef41Sopenharmony_ci                                             struct uvwasi_fd_table_t* table,
671cb0ef41Sopenharmony_ci                                             const uvwasi_fd_t id);
681cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_renumber(struct uvwasi_s* uvwasi,
691cb0ef41Sopenharmony_ci                                        struct uvwasi_fd_table_t* table,
701cb0ef41Sopenharmony_ci                                        const uvwasi_fd_t dst,
711cb0ef41Sopenharmony_ci                                        const uvwasi_fd_t src);
721cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_lock(struct uvwasi_fd_table_t* table);
731cb0ef41Sopenharmony_ciuvwasi_errno_t uvwasi_fd_table_unlock(struct uvwasi_fd_table_t* table);
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci#endif /* __UVWASI_FD_TABLE_H__ */
76