kernel: move chdir to libc using devself/devproc

Added wdir to devself and devproc:

- read '#0/wdir' to get the working directory of the calling process
  NOTE that a read(fd, nil, -1) will return the negated length
  of the working directory, just in case you want to
  allocate the memory required

- read '/proc/n/wdir' to know the working directory of process n
  (read(fd, nil, -1) still returns the negated length)

- write '#0/wdir' to change the working directory of the calling process
  NOTE: no offset is allowed and the provided string must
  be null terminated

- write '/proc/n/wdir' to change the working directory of process n
  NOTE: no offset is allowed and the provided string must
  be null terminated; moreover if another process change the working
  directory change during the write, the current process will
  receive an error.

In libc updated getwd() and chdir().
Also modified pwd to get advantage of the new file.

To test, run /arch/amd64/qa/kern/wdir.rc or simply try

	% pwd
	/usr/glenda
	% echo -n /tmp > /proc/$pid/wdir
        % pwd
        /tmp
        % cat '#0/wdir' && echo
        /tmp

The expected use cases for wdir in devproc are rio and acme.

Also, note that we could theoretically remove the cd builtin
from rc and simply implement it as a rc function.
We don't do that to preserve rc portability to other OS.
This commit is contained in:
2016-12-15 22:42:01 +01:00
parent c6de6b66e9
commit 99855d60d6
20 changed files with 357 additions and 308 deletions

View File

@@ -20,41 +20,6 @@
int verbose = 1;
#define asm_nsec() ({ \
register long __ret asm ("rax"); \
__asm__ __volatile__ ( \
"syscall" \
: "=r" (__ret) \
: "0"(19) \
: "cc", "rcx", "r11", "memory" \
); \
__ret; })
#define asm_mount(/* int */ fd, /* int */ afd, /* char* */ old, /* int */ flag, /* char* */ aname, /* int */ mdev) ({ \
register long r10 asm("r10") = flag; \
register long r8 asm("r8") = (uintptr_t)aname; \
register long r9 asm("r9") = mdev; \
register int __ret asm ("eax"); \
__asm__ __volatile__ ( \
"syscall" \
: "=r" (__ret) \
: "0"(16), "D"(fd), "S"(afd), "d"(old), "r"(r10), "r"(r8), "r"(r9) \
: "cc", "rcx", "r11", "memory" \
); \
__ret; })
/*
long
asm_nsec(void)
{
register int *p1 asm ("r0");
register int *p2 asm ("r1");
register int *result asm ("r0");
asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
return result ;
}
*/
void
main(void)
{
@@ -62,9 +27,9 @@ main(void)
uint64_t start, end;
char *msg;
start = asm_nsec();
start = sys_nsec();
sleep(1);
end = asm_nsec();
end = sys_nsec();
if (end <= start)
ret = 1;
@@ -80,7 +45,7 @@ main(void)
int fd;
fd = open("#|", ORDWR);
asm_mount(fd, -1, "/tmp", MREPL, "", 'M');
sys_mount(fd, -1, "/tmp", MREPL, "", 'M');
print("PASS\n");
exits("PASS");