Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/fd_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ uvwasi_errno_t uvwasi_fd_table_get_nolock(struct uvwasi_fd_table_t* table,
struct uvwasi_fd_wrap_t** wrap,
uvwasi_rights_t rights_base,
uvwasi_rights_t rights_inheriting);
uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_s* uvwasi,
struct uvwasi_fd_table_t* table,
const uvwasi_fd_t id);
uvwasi_errno_t uvwasi_fd_table_remove_nolock(struct uvwasi_s* uvwasi,
struct uvwasi_fd_table_t* table,
const uvwasi_fd_t id);
uvwasi_errno_t uvwasi_fd_table_renumber(struct uvwasi_s* uvwasi,
struct uvwasi_fd_table_t* table,
const uvwasi_fd_t dst,
Expand Down
26 changes: 8 additions & 18 deletions src/fd_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,37 +306,27 @@ uvwasi_errno_t uvwasi_fd_table_get_nolock(struct uvwasi_fd_table_t* table,
}


uvwasi_errno_t uvwasi_fd_table_remove(uvwasi_t* uvwasi,
struct uvwasi_fd_table_t* table,
const uvwasi_fd_t id) {
uvwasi_errno_t uvwasi_fd_table_remove_nolock(uvwasi_t* uvwasi,
struct uvwasi_fd_table_t* table,
const uvwasi_fd_t id) {
struct uvwasi_fd_wrap_t* entry;
uvwasi_errno_t err;

if (table == NULL)
return UVWASI_EINVAL;

uv_rwlock_wrlock(&table->rwlock);

if (id >= table->size) {
err = UVWASI_EBADF;
goto exit;
}
if (id >= table->size)
return UVWASI_EBADF;

entry = table->fds[id];

if (entry == NULL || entry->id != id) {
err = UVWASI_EBADF;
goto exit;
}
if (entry == NULL || entry->id != id)
return UVWASI_EBADF;

uv_mutex_destroy(&entry->mutex);
uvwasi__free(uvwasi, entry);
table->fds[id] = NULL;
table->used--;
err = UVWASI_ESUCCESS;
exit:
uv_rwlock_wrunlock(&table->rwlock);
return err;
return UVWASI_ESUCCESS;
}


Expand Down
18 changes: 13 additions & 5 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,18 +878,26 @@ uvwasi_errno_t uvwasi_fd_close(uvwasi_t* uvwasi, uvwasi_fd_t fd) {
if (uvwasi == NULL)
return UVWASI_EINVAL;

err = uvwasi_fd_table_get(&uvwasi->fds, fd, &wrap, 0, 0);
uvwasi_fd_table_lock(&uvwasi->fds);

err = uvwasi_fd_table_get_nolock(&uvwasi->fds, fd, &wrap, 0, 0);
if (err != UVWASI_ESUCCESS)
return err;
goto exit;

r = uv_fs_close(NULL, &req, wrap->fd, NULL);
uv_mutex_unlock(&wrap->mutex);
uv_fs_req_cleanup(&req);

if (r != 0)
return uvwasi__translate_uv_error(r);
if (r != 0) {
err = uvwasi__translate_uv_error(r);
goto exit;
}

err = uvwasi_fd_table_remove_nolock(uvwasi, &uvwasi->fds, fd);

return uvwasi_fd_table_remove(uvwasi, &uvwasi->fds, fd);
exit:
uvwasi_fd_table_unlock(&uvwasi->fds);
return err;
}


Expand Down