Fix ZipOS deadlock/segfault (#1011)

This change adds a new stress test for ZipOS which helped
us improve the locking semantics in open() and close().
This commit is contained in:
Jōshin 2023-12-14 22:59:20 -05:00 committed by GitHub
parent 897fa6ac00
commit 8a10ccf9c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 6 deletions

View file

@ -235,21 +235,21 @@ void __zipos_postdup(int oldfd, int newfd) {
if (oldfd == newfd) {
return;
}
BLOCK_SIGNALS;
__fds_lock();
if (__isfdkind(newfd, kFdZip)) {
__zipos_free((struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle);
if (!__isfdkind(oldfd, kFdZip)) {
__fds_lock();
bzero(g_fds.p + newfd, sizeof(*g_fds.p));
__fds_unlock();
}
}
if (__isfdkind(oldfd, kFdZip)) {
__zipos_keep((struct ZiposHandle *)(intptr_t)g_fds.p[oldfd].handle);
__fds_lock();
__ensurefds_unlocked(newfd);
g_fds.p[newfd] = g_fds.p[oldfd];
__fds_unlock();
}
__fds_unlock();
ALLOW_SIGNALS;
}
/**