mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-24 07:43:44 +02:00
Fix WASI file descriptor deserialization bugs in libretro builds
This commit is contained in:
parent
b664b3c8c7
commit
c802e24f1b
1 changed files with 9 additions and 2 deletions
|
@ -93,6 +93,10 @@ uint32_t wasi_t::allocate_file_descriptor(enum wasi_fd_type type, void *handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
void wasi_t::deallocate_file_descriptor(uint32_t fd) {
|
void wasi_t::deallocate_file_descriptor(uint32_t fd) {
|
||||||
|
if (fdtable[fd].type == wasi_fd_type::VACANT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (fdtable[fd].handle != nullptr) {
|
if (fdtable[fd].handle != nullptr) {
|
||||||
switch (fdtable[fd].type) {
|
switch (fdtable[fd].type) {
|
||||||
case wasi_fd_type::FS:
|
case wasi_fd_type::FS:
|
||||||
|
@ -103,7 +107,7 @@ void wasi_t::deallocate_file_descriptor(uint32_t fd) {
|
||||||
delete fdtable[fd].file_handle();
|
delete fdtable[fd].file_handle();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +192,9 @@ bool wasi_t::sandbox_deserialize(const void *&data, mkxp_sandbox::wasm_size_t &m
|
||||||
if (!::sandbox_deserialize(num_free_handles, data, max_size)) return false;
|
if (!::sandbox_deserialize(num_free_handles, data, max_size)) return false;
|
||||||
if (i + num_free_handles > size || i + num_free_handles < i) return false;
|
if (i + num_free_handles > size || i + num_free_handles < i) return false;
|
||||||
for (uint32_t j = i; j < i + num_free_handles; ++j) {
|
for (uint32_t j = i; j < i + num_free_handles; ++j) {
|
||||||
|
if (fdtable[i].type != wasi_fd_type::FSDIR && fdtable[i].type != wasi_fd_type::FSFILE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
deallocate_file_descriptor(j);
|
deallocate_file_descriptor(j);
|
||||||
vacant_fds.clear();
|
vacant_fds.clear();
|
||||||
}
|
}
|
||||||
|
@ -232,7 +239,7 @@ bool wasi_t::sandbox_deserialize(const void *&data, mkxp_sandbox::wasm_size_t &m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t j = 0; i < fdtable.size(); ++j) {
|
for (uint32_t j = 0; j < fdtable.size(); ++j) {
|
||||||
if (fdtable[j].type == wasi_fd_type::VACANT) {
|
if (fdtable[j].type == wasi_fd_type::VACANT) {
|
||||||
vacant_fds.push_back(j);
|
vacant_fds.push_back(j);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue