If fork flags != 0, share the file table..

..now xdu and xls work in xv6 userspace with the wq stuff..
上级 33750412
......@@ -1628,6 +1628,41 @@ tls_test(void)
fprintf(1, "tls_test ok\n");
}
static pthread_barrier_t ftable_bar;
static volatile int ftable_fd;
static void*
ftablethr(void *arg)
{
char buf[32];
int r;
pthread_barrier_wait(&ftable_bar);
r = read(ftable_fd, buf, sizeof(buf));
if (r < 0)
fprintf(2, "ftablethr: FAILED bad fd\n");
return 0;
}
static void
ftabletest(void)
{
printf("ftabletest...\n");
pthread_barrier_init(&ftable_bar, 0, 2);
pthread_t th;
pthread_create(&th, 0, &ftablethr, 0);
ftable_fd = open("README", 0);
if (ftable_fd < 0)
die("open");
pthread_barrier_wait(&ftable_bar);
wait();
printf("ftabletest ok\n");
}
static pthread_key_t tkey;
static pthread_barrier_t bar0, bar1;
enum { nthread = 8 };
......@@ -1718,6 +1753,7 @@ main(int argc, char *argv[])
bigdir(); // slow
tls_test();
thrtest();
ftabletest();
exectest();
......
......@@ -460,12 +460,17 @@ fork(int flags)
// Clear %eax so that fork returns 0 in the child.
np->tf->rax = 0;
if (flags == 0) {
np->ftable = new filetable(*myproc()->ftable);
if (np->ftable == nullptr) {
// XXX(sbw) leaking?
freeproc(np);
return -1;
}
} else {
myproc()->ftable->incref();
np->ftable = myproc()->ftable;
}
np->cwd = idup(myproc()->cwd);
pid = np->pid;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论