From 8c7765733267b17a1d33461c6e1aad8e5e340245 Mon Sep 17 00:00:00 2001 From: tholo Date: Sun, 20 Apr 1997 20:48:27 +0000 Subject: [PATCH] Add new POSIX 1003.1b related syscalls; from pk@NetBSD --- sys/kern/init_sysent.c | 28 +++--- sys/kern/kern_time.c | 198 ++++++++++++++++++++++++++++++++++----- sys/kern/syscalls.c | 20 ++-- sys/kern/syscalls.master | 24 +++-- sys/sys/syscall.h | 6 +- sys/sys/syscallargs.h | 26 ++++- 6 files changed, 241 insertions(+), 61 deletions(-) diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index 07d1800bda3..550a3a01517 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -2,7 +2,7 @@ * System call switch table. * * DO NOT EDIT-- this file is automatically generated. - * created from OpenBSD: syscalls.master,v 1.13 1997/01/26 05:18:27 downsj Exp + * created from OpenBSD: syscalls.master,v 1.14 1997/04/20 20:48:27 tholo Exp */ #include @@ -606,24 +606,24 @@ struct sysent sysent[] = { { 0, 0, sys_nosys }, /* 231 = unimplemented shmget */ #endif + { 2, s(struct sys_clock_gettime_args), + sys_clock_gettime }, /* 232 = clock_gettime */ + { 2, s(struct sys_clock_settime_args), + sys_clock_settime }, /* 233 = clock_settime */ + { 2, s(struct sys_clock_getres_args), + sys_clock_getres }, /* 234 = clock_getres */ { 0, 0, - sys_nosys }, /* 232 = unimplemented */ + sys_nosys }, /* 235 = unimplemented timer_create */ { 0, 0, - sys_nosys }, /* 233 = unimplemented */ + sys_nosys }, /* 236 = unimplemented timer_delete */ { 0, 0, - sys_nosys }, /* 234 = unimplemented */ + sys_nosys }, /* 237 = unimplemented timer_settime */ { 0, 0, - sys_nosys }, /* 235 = unimplemented */ + sys_nosys }, /* 238 = unimplemented timer_gettime */ { 0, 0, - sys_nosys }, /* 236 = unimplemented */ - { 0, 0, - sys_nosys }, /* 237 = unimplemented */ - { 0, 0, - sys_nosys }, /* 238 = unimplemented */ - { 0, 0, - sys_nosys }, /* 239 = unimplemented */ - { 0, 0, - sys_nosys }, /* 240 = unimplemented */ + sys_nosys }, /* 239 = unimplemented timer_getoverrun */ + { 2, s(struct sys_nanosleep_args), + sys_nanosleep }, /* 240 = nanosleep */ { 0, 0, sys_nosys }, /* 241 = unimplemented */ { 0, 0, diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index c6b5ebfcdec..149a9ca2ddc 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.5 1997/03/16 01:18:48 flipk Exp $ */ +/* $OpenBSD: kern_time.c,v 1.6 1997/04/20 20:49:42 tholo Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -55,6 +55,8 @@ #include +static void settime __P((struct timeval *)); + /* * Time of day and interval timer support. * @@ -65,6 +67,172 @@ * timers when they expire. */ +/* This function is used by clock_settime and settimeofday */ +static void +settime(tv) + struct timeval *tv; +{ + struct timeval delta; + int s; + + /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ + s = splclock(); + timersub(tv, &time, &delta); + time = *tv; + (void) splsoftclock(); + timeradd(&boottime, &delta, &boottime); + timeradd(&runtime, &delta, &runtime); +# if defined(NFS) || defined(NFSSERVER) + nqnfs_lease_updatetime(delta.tv_sec); +# endif + splx(s); + resettodr(); +} + +/* ARGSUSED */ +int +sys_clock_gettime(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_clock_gettime_args /* { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; + } */ *uap = v; + clockid_t clock_id; + struct timeval atv; + struct timespec ats; + + clock_id = SCARG(uap, clock_id); + if (clock_id != CLOCK_REALTIME) + return (EINVAL); + + microtime(&atv); + TIMEVAL_TO_TIMESPEC(&atv,&ats); + + return copyout(&ats, SCARG(uap, tp), sizeof(ats)); +} + +/* ARGSUSED */ +int +sys_clock_settime(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_clock_settime_args /* { + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; + } */ *uap = v; + clockid_t clock_id; + struct timeval atv; + struct timespec ats; + int error; + + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return (error); + + clock_id = SCARG(uap, clock_id); + if (clock_id != CLOCK_REALTIME) + return (EINVAL); + + if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0) + return (error); + + TIMESPEC_TO_TIMEVAL(&atv,&ats); + settime(&atv); + + return 0; +} + +int +sys_clock_getres(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_clock_getres_args /* { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; + } */ *uap = v; + clockid_t clock_id; + struct timespec ts; + int error = 0; + + clock_id = SCARG(uap, clock_id); + if (clock_id != CLOCK_REALTIME) + return (EINVAL); + + if (SCARG(uap, tp)) { + ts.tv_sec = 0; + ts.tv_nsec = 1000000000 / hz; + + error = copyout(&ts, SCARG(uap, tp), sizeof (ts)); + } + + return error; +} + +/* ARGSUSED */ +int +sys_nanosleep(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + static int nanowait; + register struct sys_nanosleep_args/* { + syscallarg(struct timespec *) rqtp; + syscallarg(struct timespec *) rmtp; + } */ *uap = v; + struct timespec rqt; + struct timespec rmt; + struct timeval atv, utv; + int error, s, timo; + + error = copyin((caddr_t)SCARG(uap, rqtp), (caddr_t)&rqt, + sizeof(struct timespec)); + if (error) + return (error); + + TIMESPEC_TO_TIMEVAL(&atv,&rqt) + if (itimerfix(&atv)) + return (EINVAL); + + s = splclock(); + timeradd(&atv,&time,&atv); + timo = hzto(&atv); + /* + * Avoid inadvertantly sleeping forever + */ + if (timo == 0) + timo = 1; + splx(s); + + error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo); + if (error == ERESTART) + error = EINTR; + if (error == EWOULDBLOCK) + error = 0; + + if (SCARG(uap, rmtp)) { + s = splclock(); + utv = time; + splx(s); + + timersub(&atv, &utv, &utv); + if (utv.tv_sec < 0) + timerclear(&utv); + + TIMEVAL_TO_TIMESPEC(&utv,&rmt); + error = copyout((caddr_t)&rmt, (caddr_t)SCARG(uap,rmtp), + sizeof(rmt)); + } + + return error; +} + /* ARGSUSED */ int sys_gettimeofday(p, v, retval) @@ -102,9 +270,9 @@ sys_settimeofday(p, v, retval) syscallarg(struct timeval *) tv; syscallarg(struct timezone *) tzp; } */ *uap = v; - struct timeval atv, delta; + struct timeval atv; struct timezone atz; - int error, s; + int error; if ((error = suser(p->p_ucred, &p->p_acflag))) return (error); @@ -115,28 +283,8 @@ sys_settimeofday(p, v, retval) if (SCARG(uap, tzp) && (error = copyin((caddr_t)SCARG(uap, tzp), (caddr_t)&atz, sizeof(atz)))) return (error); - if (SCARG(uap, tv)) { - /* - * If the system is secure, we do not allow the time to be - * set to an earlier value (it may be slowed using adjtime, - * but not set back). This feature prevent interlopers from - * setting arbitrary time stamps on files. - */ - if (securelevel > 1 && timercmp(&atv, &time, <)) - return (EPERM); - /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ - s = splclock(); - timersub(&atv, &time, &delta); - time = atv; - (void) splsoftclock(); - timeradd(&boottime, &delta, &boottime); - timeradd(&runtime, &delta, &runtime); -# if defined(NFSCLIENT) || defined(NFSSERVER) - nqnfs_lease_updatetime(delta.tv_sec); -# endif - splx(s); - resettodr(); - } + if (SCARG(uap, tv)) + settime(&atv); if (SCARG(uap, tzp)) tz = atz; return (0); diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c index 9392b9f7247..5c0b661a307 100644 --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -2,7 +2,7 @@ * System call names. * * DO NOT EDIT-- this file is automatically generated. - * created from OpenBSD: syscalls.master,v 1.13 1997/01/26 05:18:27 downsj Exp + * created from OpenBSD: syscalls.master,v 1.14 1997/04/20 20:48:27 tholo Exp */ char *syscallnames[] = { @@ -312,15 +312,15 @@ char *syscallnames[] = { "#230 (unimplemented shmdt)", /* 230 = unimplemented shmdt */ "#231 (unimplemented shmget)", /* 231 = unimplemented shmget */ #endif - "#232 (unimplemented)", /* 232 = unimplemented */ - "#233 (unimplemented)", /* 233 = unimplemented */ - "#234 (unimplemented)", /* 234 = unimplemented */ - "#235 (unimplemented)", /* 235 = unimplemented */ - "#236 (unimplemented)", /* 236 = unimplemented */ - "#237 (unimplemented)", /* 237 = unimplemented */ - "#238 (unimplemented)", /* 238 = unimplemented */ - "#239 (unimplemented)", /* 239 = unimplemented */ - "#240 (unimplemented)", /* 240 = unimplemented */ + "clock_gettime", /* 232 = clock_gettime */ + "clock_settime", /* 233 = clock_settime */ + "clock_getres", /* 234 = clock_getres */ + "#235 (unimplemented timer_create)", /* 235 = unimplemented timer_create */ + "#236 (unimplemented timer_delete)", /* 236 = unimplemented timer_delete */ + "#237 (unimplemented timer_settime)", /* 237 = unimplemented timer_settime */ + "#238 (unimplemented timer_gettime)", /* 238 = unimplemented timer_gettime */ + "#239 (unimplemented timer_getoverrun)", /* 239 = unimplemented timer_getoverrun */ + "nanosleep", /* 240 = nanosleep */ "#241 (unimplemented)", /* 241 = unimplemented */ "#242 (unimplemented)", /* 242 = unimplemented */ "#243 (unimplemented)", /* 243 = unimplemented */ diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 16f4245b2d0..4c0d4a2c79d 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ - $OpenBSD: syscalls.master,v 1.13 1997/01/26 05:18:27 downsj Exp $ + $OpenBSD: syscalls.master,v 1.14 1997/04/20 20:48:27 tholo Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -434,15 +434,19 @@ 230 UNIMPL shmdt 231 UNIMPL shmget #endif -232 UNIMPL -233 UNIMPL -234 UNIMPL -235 UNIMPL -236 UNIMPL -237 UNIMPL -238 UNIMPL -239 UNIMPL -240 UNIMPL +232 STD { int sys_clock_gettime(clockid_t clock_id, \ + struct timespec *tp); } +233 STD { int sys_clock_settime(clockid_t clock_id, \ + const struct timespec *tp); } +234 STD { int sys_clock_getres(clockid_t clock_id, \ + struct timespec *tp); } +235 UNIMPL timer_create +236 UNIMPL timer_delete +237 UNIMPL timer_settime +238 UNIMPL timer_gettime +239 UNIMPL timer_getoverrun +240 STD { int sys_nanosleep(const struct timespec *rqtp, \ + struct timespec *rmtp); } 241 UNIMPL 242 UNIMPL 243 UNIMPL diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h index cf8550cb56f..005a8826a1d 100644 --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -2,7 +2,7 @@ * System call numbers. * * DO NOT EDIT-- this file is automatically generated. - * created from OpenBSD: syscalls.master,v 1.13 1997/01/26 05:18:27 downsj Exp + * created from OpenBSD: syscalls.master,v 1.14 1997/04/20 20:48:27 tholo Exp */ #define SYS_syscall 0 @@ -206,6 +206,10 @@ #define SYS_shmctl 229 #define SYS_shmdt 230 #define SYS_shmget 231 +#define SYS_clock_gettime 232 +#define SYS_clock_settime 233 +#define SYS_clock_getres 234 +#define SYS_nanosleep 240 #define SYS_minherit 250 #define SYS_rfork 251 #define SYS_poll 252 diff --git a/sys/sys/syscallargs.h b/sys/sys/syscallargs.h index 1cd547a5e07..0eb2922c74d 100644 --- a/sys/sys/syscallargs.h +++ b/sys/sys/syscallargs.h @@ -2,7 +2,7 @@ * System call argument lists. * * DO NOT EDIT-- this file is automatically generated. - * created from OpenBSD: syscalls.master,v 1.13 1997/01/26 05:18:27 downsj Exp + * created from OpenBSD: syscalls.master,v 1.14 1997/04/20 20:48:27 tholo Exp */ #define syscallarg(x) union { x datum; register_t pad; } @@ -953,6 +953,26 @@ struct sys_shmget_args { syscallarg(int) shmflg; }; +struct sys_clock_gettime_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_clock_settime_args { + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; +}; + +struct sys_clock_getres_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_nanosleep_args { + syscallarg(const struct timespec *) rqtp; + syscallarg(struct timespec *) rmtp; +}; + struct sys_minherit_args { syscallarg(caddr_t) addr; syscallarg(size_t) len; @@ -1220,6 +1240,10 @@ int sys_shmdt __P((struct proc *, void *, register_t *)); int sys_shmget __P((struct proc *, void *, register_t *)); #else #endif +int sys_clock_gettime __P((struct proc *, void *, register_t *)); +int sys_clock_settime __P((struct proc *, void *, register_t *)); +int sys_clock_getres __P((struct proc *, void *, register_t *)); +int sys_nanosleep __P((struct proc *, void *, register_t *)); int sys_minherit __P((struct proc *, void *, register_t *)); int sys_rfork __P((struct proc *, void *, register_t *)); int sys_poll __P((struct proc *, void *, register_t *)); -- 2.20.1