From 4676c65a3d85970ea27441d113599c4608e19d06 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Fri, 6 Jan 2017 00:45:35 +0100 Subject: [PATCH] kernel: move nsec to libc --- qa/lib/c/asmscall.c | 4 ++-- sys/include/libc.h | 3 ++- sys/src/kern/port/devcons.c | 13 ++++++++++++- sys/src/kern/port/sysproc.c | 6 ------ sys/src/lib/c/9sys/nsec.c | 30 ++++++++++++++++++++++++++++++ sys/src/lib/c/build.json | 1 + sys/src/sysconf.json | 31 ++++++++++++------------------- 7 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 sys/src/lib/c/9sys/nsec.c diff --git a/qa/lib/c/asmscall.c b/qa/lib/c/asmscall.c index 7ba2297..4aacda4 100644 --- a/qa/lib/c/asmscall.c +++ b/qa/lib/c/asmscall.c @@ -27,9 +27,9 @@ main(void) uint64_t start, end; char *msg; - start = sys_nsec(); + start = sys_remove("#c/time"); sleep(1); - end = sys_nsec(); + end = sys_remove("#c/time"); if (end <= start) ret = 1; diff --git a/sys/include/libc.h b/sys/include/libc.h index 0e6e596..5206123 100644 --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Giacomo Tesio + * Copyright (C) 2015-2017 Giacomo Tesio * * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this @@ -396,6 +396,7 @@ extern void longjmp(jmp_buf, int); extern char* mktemp(char*); extern double modf(double, double*); extern void notejmp(void*, jmp_buf, int); +extern unsigned long nsec(void); extern int dup(int oldfd, int newfd); extern int ocreate(const char* path, unsigned int omode, unsigned int perm); extern void perror(const char*); diff --git a/sys/src/kern/port/devcons.c b/sys/src/kern/port/devcons.c index 7cebd59..47b61a3 100644 --- a/sys/src/kern/port/devcons.c +++ b/sys/src/kern/port/devcons.c @@ -1039,6 +1039,17 @@ consread(Chan *c, void *buf, long n, int64_t off) return -1; /* never reached */ } +static void +consremove(Chan* c) +{ + switch((uint32_t)c->qid.path){ + default: + error(Eperm); + case Qtime: + errorl("fugit irreparabile tempus", todget(nil)); + } +} + static long conswrite(Chan *c, void *va, long n, int64_t off) { @@ -1198,7 +1209,7 @@ Dev consdevtab = { devbread, conswrite, devbwrite, - devremove, + consremove, devwstat, }; diff --git a/sys/src/kern/port/sysproc.c b/sys/src/kern/port/sysproc.c index 8618c78..5a864e5 100644 --- a/sys/src/kern/port/sysproc.c +++ b/sys/src/kern/port/sysproc.c @@ -1163,9 +1163,3 @@ syssemrelease(int* addr, int delta) return semrelease(s, addr, delta); } - -long -sysnsec(void) -{ - return todget(nil); -} diff --git a/sys/src/lib/c/9sys/nsec.c b/sys/src/lib/c/9sys/nsec.c new file mode 100644 index 0000000..732d286 --- /dev/null +++ b/sys/src/lib/c/9sys/nsec.c @@ -0,0 +1,30 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 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 + * the Free Software Foundation, version 2 of the License. + * + * Jehanne is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jehanne. If not, see . + */ +#define PORTABLE_SYSCALLS +#include +#include + +unsigned long +nsec(void) +{ + long r; + r = remove("/dev/time"); + if(r == -1) + r = remove("#c/time"); + return r; +} diff --git a/sys/src/lib/c/build.json b/sys/src/lib/c/build.json index 4674df8..f1dd69c 100644 --- a/sys/src/lib/c/build.json +++ b/sys/src/lib/c/build.json @@ -59,6 +59,7 @@ "9sys/getppid.c", "9sys/getwd.c", "9sys/iounit.c", + "9sys/nsec.c", "9sys/nulldir.c", "9sys/ocreate.c", "9sys/pipe.c", diff --git a/sys/src/sysconf.json b/sys/src/sysconf.json index a8c207f..d911ccb 100644 --- a/sys/src/sysconf.json +++ b/sys/src/sysconf.json @@ -202,19 +202,12 @@ "int" ] }, - { - "Id": 16, - "Name": "nsec", - "Ret": [ - "long" - ] - }, { "Args": [ "const char*", "uint32_t" ], - "Id": 17, + "Id": 16, "Name": "open", "Ret": [ "long" @@ -227,7 +220,7 @@ "long", "long" ], - "Id": 18, + "Id": 17, "Name": "pread", "Ret": [ "long" @@ -240,7 +233,7 @@ "long", "long" ], - "Id": 19, + "Id": 18, "Name": "pwrite", "Ret": [ "long" @@ -250,7 +243,7 @@ "Args": [ "const char*" ], - "Id": 20, + "Id": 19, "Name": "remove", "Ret": [ "long" @@ -261,7 +254,7 @@ "const void*", "void*" ], - "Id": 21, + "Id": 20, "Name": "rendezvous", "Ret": [ "void*" @@ -271,7 +264,7 @@ "Args": [ "uint32_t" ], - "Id": 22, + "Id": 21, "Name": "rfork", "Ret": [ "int" @@ -283,7 +276,7 @@ "long", "int" ], - "Id": 23, + "Id": 22, "Name": "seek", "Ret": [ "long" @@ -294,7 +287,7 @@ "int*", "int" ], - "Id": 24, + "Id": 23, "Name": "semacquire", "Ret": [ "int" @@ -305,7 +298,7 @@ "int*", "int" ], - "Id": 25, + "Id": 24, "Name": "semrelease", "Ret": [ "int" @@ -316,7 +309,7 @@ "int*", "uint64_t" ], - "Id": 26, + "Id": 25, "Name": "tsemacquire", "Ret": [ "int" @@ -327,7 +320,7 @@ "const char*", "const char*" ], - "Id": 27, + "Id": 26, "Name": "unmount", "Ret": [ "int" @@ -337,7 +330,7 @@ "Args": [ "unsigned long" ], - "Id": 28, + "Id": 27, "Name": "alarm", "Ret": [ "long"