From 63d860eb99b35a2200620809dce3addf5cebee1e Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Sun, 24 Nov 2019 15:47:11 +0100 Subject: [PATCH] u.h: refactoring of syscalls --- arch/amd64/include/u.h | 13 ------------- sys/src/lib/c/9sys/qlock.c | 5 ++--- sys/src/lib/c/9sys/read.c | 4 ++-- sys/src/lib/c/9sys/write.c | 4 ++-- sys/src/lib/c/amd64/argv0.c | 2 -- sys/src/lib/c/amd64/initlib.c | 4 +--- sys/src/lib/posix/environment.c | 7 +++---- sys/src/lib/posix/errors.c | 6 +++--- sys/src/lib/posix/files.c | 20 ++++++++++---------- sys/src/lib/posix/ids.c | 4 ++-- sys/src/lib/posix/others.c | 4 ++-- sys/src/lib/posix/posixly.c | 4 ++-- sys/src/lib/posix/processes.c | 8 ++++---- 13 files changed, 33 insertions(+), 52 deletions(-) diff --git a/arch/amd64/include/u.h b/arch/amd64/include/u.h index 59aacff..462b68b 100644 --- a/arch/amd64/include/u.h +++ b/arch/amd64/include/u.h @@ -85,17 +85,4 @@ typedef __builtin_va_list va_list; #define va_arg(v,l) __builtin_va_arg(v,l) #define va_copy(v,l) __builtin_va_copy(v,l) -typedef union NativeTypes -{ - volatile char c; - volatile unsigned char uc; - volatile short s; - volatile unsigned short us; - volatile int i; - volatile unsigned int ui; - volatile long l; - volatile unsigned long ul; - void* p; -} NativeTypes; -extern volatile NativeTypes* _sysargs; # include "syscalls.h" diff --git a/sys/src/lib/c/9sys/qlock.c b/sys/src/lib/c/9sys/qlock.c index 232341b..e8285e8 100644 --- a/sys/src/lib/c/9sys/qlock.c +++ b/sys/src/lib/c/9sys/qlock.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2016-2017 Giacomo Tesio + * Copyright (C) 2016-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -120,7 +120,7 @@ static void* (*_rendezvousp)(void*, void*) = __rendezvous; #endif # define RENDEZVOUS(...) (*_rendezvousp)(__VA_ARGS__) -//# define RENDEZVOUS(...) sys_rendezvous(__VA_ARGS__) +//# define RENDEZVOUS(...) rendezvous(__VA_ARGS__) //# define RENDEZVOUS(tag, val) __rendezvous(tag, __builtin_return_address(0)) /* this gets called by the thread library ONLY to get us to use its rendezvous */ @@ -821,4 +821,3 @@ jehanne_rwakeupall(Rendez *r) ; return i; } - diff --git a/sys/src/lib/c/9sys/read.c b/sys/src/lib/c/9sys/read.c index b2ccd7b..4ba8218 100644 --- a/sys/src/lib/c/9sys/read.c +++ b/sys/src/lib/c/9sys/read.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2015 Giacomo Tesio + * Copyright (C) 2015-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,5 +22,5 @@ int read(int fd, void* buf, int nbytes) { - return sys_pread(fd, buf, nbytes, ~0LL); + return pread(fd, buf, nbytes, ~0LL); } diff --git a/sys/src/lib/c/9sys/write.c b/sys/src/lib/c/9sys/write.c index 839104a..81dc315 100644 --- a/sys/src/lib/c/9sys/write.c +++ b/sys/src/lib/c/9sys/write.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2015 Giacomo Tesio + * Copyright (C) 2015-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,5 +22,5 @@ int write(int fd, const void* buf, int nbytes) { - return sys_pwrite(fd, buf, nbytes, ~0LL); + return pwrite(fd, buf, nbytes, ~0LL); } diff --git a/sys/src/lib/c/amd64/argv0.c b/sys/src/lib/c/amd64/argv0.c index 978ed41..9950b37 100644 --- a/sys/src/lib/c/amd64/argv0.c +++ b/sys/src/lib/c/amd64/argv0.c @@ -6,5 +6,3 @@ char *argv0; int32_t _mainpid; char *_privates; char *_nprivates; -volatile NativeTypes* _sysargs; - diff --git a/sys/src/lib/c/amd64/initlib.c b/sys/src/lib/c/amd64/initlib.c index 8e8d840..d2c7276 100644 --- a/sys/src/lib/c/amd64/initlib.c +++ b/sys/src/lib/c/amd64/initlib.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,13 +31,11 @@ __jehanne_libc_init(int argc, char *argv[]) { /* Initialize per process structures on the stack */ void *privates[NPRIVATES]; - NativeTypes sysargs[6]; _nprivates = NPRIVATES; for(_nprivates = 0; _nprivates < NPRIVATES; ++_nprivates) privates[_nprivates] = nil; _privates = privates; - _sysargs = &sysargs[0]; if(__libc_init != nil) __libc_init(argc, argv); diff --git a/sys/src/lib/posix/environment.c b/sys/src/lib/posix/environment.c index cb0d82e..3d1e30c 100644 --- a/sys/src/lib/posix/environment.c +++ b/sys/src/lib/posix/environment.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -240,8 +240,7 @@ __libposix_setup_exec_environment(char * const *env) continue; end++; /* after '=' */ len = strlen(end); - sys_pwrite(fd, end, len, -1); - sys_close(fd); + pwrite(fd, end, len, -1); + close(fd); } } - diff --git a/sys/src/lib/posix/errors.c b/sys/src/lib/posix/errors.c index 0b4f2d5..9c21e81 100644 --- a/sys/src/lib/posix/errors.c +++ b/sys/src/lib/posix/errors.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -173,7 +173,7 @@ __libposix_translate_errstr(uintptr_t caller) char err[ERRMAX]; int ret; - if(sys_errstr(err, ERRMAX) < 0) + if(errstr(err, ERRMAX) < 0) return __libposix_get_errno(PosixEINVAL); handler = custom_handlers; @@ -189,6 +189,6 @@ __libposix_translate_errstr(uintptr_t caller) if(perr == 0) perr = libposix_translate_kernel_errors(err); ret = __libposix_get_errno(perr); - sys_errstr(err, ERRMAX); + errstr(err, ERRMAX); return ret; } diff --git a/sys/src/lib/posix/files.c b/sys/src/lib/posix/files.c index d28dbfd..5b3791f 100644 --- a/sys/src/lib/posix/files.c +++ b/sys/src/lib/posix/files.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017-2018 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -343,7 +343,7 @@ POSIX_open(int *errnop, const char *name, int flags, int mode) omode &= ~DMDIR; } if(cperm == 0){ - f = sys_open(name, omode); + f = open(name, omode); } else { f = ocreate(name, (unsigned int)omode, (unsigned int)cperm); } @@ -372,7 +372,7 @@ POSIX_read(int *errnop, int fd, char *buf, size_t len) OnIgnoredSignalInterrupt: if(__libposix_should_not_block(fd)) wkp = awake(2); - r = sys_pread(fd, buf, len, -1); + r = pread(fd, buf, len, -1); if(r < 0){ if(wkp){ if(!awakened(wkp)) @@ -402,7 +402,7 @@ POSIX_write(int *errnop, int fd, const void *buf, size_t len) OnIgnoredSignalInterrupt: if(__libposix_should_not_block(fd)) wkp = awake(2); - w = sys_pwrite(fd, buf, len, -1); + w = pwrite(fd, buf, len, -1); if(w < 0){ if(wkp){ if(!awakened(wkp)) @@ -435,7 +435,7 @@ POSIX_lseek(int *errnop, int fd, off_t pos, int whence) *errnop = __libposix_get_errno(PosixEBADF); return -1; } - r = sys_seek(fd, pos, stype); + r = seek(fd, pos, stype); if(r >= 0) return r; *errnop = __libposix_translate_errstr((uintptr_t)POSIX_lseek); @@ -454,7 +454,7 @@ POSIX_pread(int *errnop, int fd, char *buf, size_t len, long offset) OnIgnoredSignalInterrupt: if(__libposix_should_not_block(fd)) wkp = awake(2); - r = sys_pread(fd, buf, len, offset); + r = pread(fd, buf, len, offset); if(r < 0){ if(wkp){ if(!awakened(wkp)) @@ -484,7 +484,7 @@ POSIX_pwrite(int *errnop, int fd, const char *buf, size_t len, long offset) OnIgnoredSignalInterrupt: if(__libposix_should_not_block(fd)) wkp = awake(2); - w = sys_pwrite(fd, buf, len, offset); + w = pwrite(fd, buf, len, offset); if(w < 0){ if(wkp){ if(!awakened(wkp)) @@ -507,7 +507,7 @@ POSIX_close(int *errno, int file) { long ret; - ret = sys_close(file); + ret = close(file); switch(ret){ case 0: return 0; @@ -529,7 +529,7 @@ POSIX_unlink(int *errnop, const char *name) *errnop = __libposix_get_errno(PosixENOENT); return -1; } - ret = sys_remove(name); + ret = remove(name); switch(ret){ case 0: return 0; @@ -552,7 +552,7 @@ POSIX_rmdir(int *errnop, const char *name) *errnop = __libposix_get_errno(PosixENOENT); return -1; } - ret = sys_remove(name); + ret = remove(name); switch(ret){ case 0: return 0; diff --git a/sys/src/lib/posix/ids.c b/sys/src/lib/posix/ids.c index 749867a..2fc63dc 100644 --- a/sys/src/lib/posix/ids.c +++ b/sys/src/lib/posix/ids.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -239,7 +239,7 @@ POSIX_setsid(int *errnop) assert(access("/dev/posix", AEXIST) != 0); /* start the new session */ - switch(controlpid = sys_rfork(RFPROC|RFNOTEG|RFENVG|RFFDG)){ + switch(controlpid = rfork(RFPROC|RFNOTEG|RFENVG|RFFDG)){ case -1: goto FailWithEPERM; case 0: diff --git a/sys/src/lib/posix/others.c b/sys/src/lib/posix/others.c index 2fe9b40..5af9615 100644 --- a/sys/src/lib/posix/others.c +++ b/sys/src/lib/posix/others.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -29,7 +29,7 @@ POSIX_isatty(int *errnop, int fd) *errnop = __libposix_get_errno(PosixEBADF); return 0; } - if(sys_fd2path(fd, buf, sizeof(buf)) < 0){ + if(fd2path(fd, buf, sizeof(buf)) < 0){ *errnop = __libposix_get_errno(PosixENOTTY); return 0; } diff --git a/sys/src/lib/posix/posixly.c b/sys/src/lib/posix/posixly.c index 6d735ef..af2b5e8 100644 --- a/sys/src/lib/posix/posixly.c +++ b/sys/src/lib/posix/posixly.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -1765,7 +1765,7 @@ tty_from_cons(int fd, int mode) int tmp; char buf[256]; - if(sys_fd2path(fd, buf, sizeof(buf)) < 0) + if(fd2path(fd, buf, sizeof(buf)) < 0) sysfatal("fd2path: %d", fd); tmp = strlen(buf); if(tmp < 9 || strcmp(buf+tmp-9, "/dev/cons") != 0) diff --git a/sys/src/lib/posix/processes.c b/sys/src/lib/posix/processes.c index a3a35a7..f49084e 100644 --- a/sys/src/lib/posix/processes.c +++ b/sys/src/lib/posix/processes.c @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2017 Giacomo Tesio + * Copyright (C) 2017-2019 Giacomo Tesio * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -179,9 +179,9 @@ POSIX_execve(int *errnop, const char *name, char * const*argv, char * const*env) // see http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html if(env == environ){ /* just get a copy of the current environment */ - sys_rfork(RFENVG); + rfork(RFENVG); } else { - sys_rfork(RFCENVG); + rfork(RFCENVG); __libposix_setup_exec_environment(env); } @@ -189,7 +189,7 @@ POSIX_execve(int *errnop, const char *name, char * const*argv, char * const*env) __libposix_close_on_exec(); __libposix_sighelper_cmd(PHCallingExec, 0); - sys_exec(name, argv); + exec(name, argv); *errnop = __libposix_translate_errstr((uintptr_t)POSIX_execve); return -1; }