Implement __zipos_dup (#972)

* Implement __zipos_dup

Makes ZiposHandle reference-counted by an `rc` field in a union with its
freelist `next` pointer. The functions `__zipos_free` and `__zipos_keep`
function as incref/decref for it. Adds `__zipos_postdup` to fix metadata
on file descriptors after dup-like operations, and adds zipos support to
`sys_dup_nt` + `sys_close_nt`.

* Remove noop __zipos_postdup

rc is never a zipos file because it is always a previously unused file
descriptor. fd is never a zipos file because that case has been handled
above by __zipos_fcntl.
This commit is contained in:
Jōshin 2023-12-01 03:08:30 -05:00 committed by GitHub
parent 6556dd2673
commit d1a745c17c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 138 additions and 39 deletions

View file

@ -32,6 +32,9 @@
#include "libc/thread/thread.h"
#include "libc/x/x.h"
__static_yoink("libc/testlib/hyperion.txt");
__static_yoink("zipos");
int Lock(int fd, int type, long start, long len) {
int e;
struct flock lock = {
@ -121,6 +124,17 @@ TEST(fcntl, F_DUPFD_CLOEXEC) {
ASSERT_SYS(0, 0, close(3));
}
TEST(fcntl, ziposDupFd) {
char b[8];
ASSERT_SYS(0, 3, open("/zip/libc/testlib/hyperion.txt", O_RDONLY));
ASSERT_SYS(0, 4, fcntl(3, F_DUPFD, 4));
ASSERT_SYS(0, 8, read(3, b, 8));
ASSERT_SYS(0, 0, lseek(4, 0, SEEK_SET));
ASSERT_SYS(0, 8, read(4, b, 8));
ASSERT_SYS(0, 0, close(3));
ASSERT_SYS(0, 0, close(4));
}
void OnSig(int sig) {
}