diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2010-06-30 01:47:36 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2010-06-30 01:47:36 +0000 |
commit | fcce5eb94d61a5966c73a4f8730b7c075e715459 (patch) | |
tree | 05115366a221ef8d5b0ab772be0a0537df31e81a /sys | |
parent | c51973e5d1de0ff9dbe78f5004f098837b107a10 (diff) |
lots of SCARG simplification. ok matthew
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_sig.c | 54 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 125 |
2 files changed, 103 insertions, 76 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 5bdcfcc2bf2..f7c01ad4fe5 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.112 2010/06/29 20:48:50 guenther Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.113 2010/06/30 01:47:35 tedu Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -219,16 +219,21 @@ sys_sigaction(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct sigaction vec; struct sigaction *sa; + const struct sigaction *nsa; + struct sigaction *osa; struct sigacts *ps = p->p_sigacts; int signum; int bit, error; signum = SCARG(uap, signum); + nsa = SCARG(uap, nsa); + osa = SCARG(uap, osa); + if (signum <= 0 || signum >= NSIG || - (SCARG(uap, nsa) && (signum == SIGKILL || signum == SIGSTOP))) + (nsa && (signum == SIGKILL || signum == SIGSTOP))) return (EINVAL); sa = &vec; - if (SCARG(uap, osa)) { + if (osa) { sa->sa_handler = ps->ps_sigact[signum]; sa->sa_mask = ps->ps_catchmask[signum]; bit = sigmask(signum); @@ -250,12 +255,12 @@ sys_sigaction(struct proc *p, void *v, register_t *retval) if ((sa->sa_mask & bit) == 0) sa->sa_flags |= SA_NODEFER; sa->sa_mask &= ~bit; - error = copyout(sa, SCARG(uap, osa), sizeof (vec)); + error = copyout(sa, osa, sizeof (vec)); if (error) return (error); } - if (SCARG(uap, nsa)) { - error = copyin(SCARG(uap, nsa), sa, sizeof (vec)); + if (nsa) { + error = copyin(nsa, sa, sizeof (vec)); if (error) return (error); setsigvec(p, signum, sa); @@ -416,23 +421,22 @@ sys_sigprocmask(struct proc *p, void *v, register_t *retval) } */ *uap = v; int error = 0; int s; + sigset_t mask; *retval = p->p_sigmask; + mask = SCARG(uap, mask); s = splhigh(); switch (SCARG(uap, how)) { case SIG_BLOCK: - p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask; + p->p_sigmask |= mask &~ sigcantmask; break; - case SIG_UNBLOCK: - p->p_sigmask &= ~SCARG(uap, mask); + p->p_sigmask &= ~mask; break; - case SIG_SETMASK: - p->p_sigmask = SCARG(uap, mask) &~ sigcantmask; + p->p_sigmask = mask &~ sigcantmask; break; - default: error = EINVAL; break; @@ -490,21 +494,26 @@ sys_osigaltstack(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct sigacts *psp; struct osigaltstack ss; + const struct osigaltstack *nss; + struct osigaltstack *oss; int error; + nss = SCARG(uap, nss); + oss = SCARG(uap, oss); + psp = p->p_sigacts; if ((psp->ps_flags & SAS_ALTSTACK) == 0) psp->ps_sigstk.ss_flags |= SS_DISABLE; - if (SCARG(uap, oss)) { + if (oss) { ss.ss_sp = psp->ps_sigstk.ss_sp; ss.ss_size = psp->ps_sigstk.ss_size; ss.ss_flags = psp->ps_sigstk.ss_flags; - if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss)))) + if ((error = copyout(&ss, oss, sizeof(ss)))) return (error); } - if (SCARG(uap, nss) == NULL) + if (nss == NULL) return (0); - error = copyin(SCARG(uap, nss), &ss, sizeof(ss)); + error = copyin(nss, &ss, sizeof(ss)); if (error) return (error); if (ss.ss_flags & SS_DISABLE) { @@ -532,17 +541,22 @@ sys_sigaltstack(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct sigacts *psp; struct sigaltstack ss; + const struct sigaltstack *nss; + struct sigaltstack *oss; int error; + nss = SCARG(uap, nss); + oss = SCARG(uap, oss); + psp = p->p_sigacts; if ((psp->ps_flags & SAS_ALTSTACK) == 0) psp->ps_sigstk.ss_flags |= SS_DISABLE; - if (SCARG(uap, oss) && (error = copyout(&psp->ps_sigstk, - SCARG(uap, oss), sizeof(struct sigaltstack)))) + if (oss && (error = copyout(&psp->ps_sigstk, + oss, sizeof(struct sigaltstack)))) return (error); - if (SCARG(uap, nss) == NULL) + if (nss == NULL) return (0); - error = copyin(SCARG(uap, nss), &ss, sizeof(ss)); + error = copyin(nss, &ss, sizeof(ss)); if (error) return (error); if (ss.ss_flags & SS_DISABLE) { diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 6fff2cd75d7..db6625040a7 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.70 2010/06/28 21:23:20 art Exp $ */ +/* $OpenBSD: kern_time.c,v 1.71 2010/06/30 01:47:35 tedu Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -292,11 +292,12 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct timespec rqt, rmt; struct timespec sts, ets; + struct timespec *rmtp; struct timeval tv; int error, error1; - error = copyin((const void *)SCARG(uap, rqtp), (void *)&rqt, - sizeof(struct timespec)); + rmtp = SCARG(uap, rmtp); + error = copyin(SCARG(uap, rqtp), &rqt, sizeof(struct timespec)); if (error) return (error); @@ -304,7 +305,7 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) if (itimerfix(&tv)) return (EINVAL); - if (SCARG(uap, rmtp)) + if (rmtp) getnanouptime(&sts); error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", @@ -314,7 +315,7 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) if (error == EWOULDBLOCK) error = 0; - if (SCARG(uap, rmtp)) { + if (rmtp) { getnanouptime(&ets); timespecsub(&ets, &sts, &sts); @@ -323,8 +324,7 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval) if (rmt.tv_sec < 0) timespecclear(&rmt); - error1 = copyout((void *)&rmt, (void *)SCARG(uap,rmtp), - sizeof(rmt)); + error1 = copyout(&rmt, rmtp, sizeof(rmt)); if (error1 != 0) error = error1; } @@ -341,17 +341,20 @@ sys_gettimeofday(struct proc *p, void *v, register_t *retval) syscallarg(struct timezone *) tzp; } */ *uap = v; struct timeval atv; + struct timeval *tp; + struct timezone *tzp; int error = 0; - if (SCARG(uap, tp)) { + tp = SCARG(uap, tp); + tzp = SCARG(uap, tzp); + + if (tp) { microtime(&atv); - if ((error = copyout((void *)&atv, (void *)SCARG(uap, tp), - sizeof (atv)))) + if ((error = copyout(&atv, tp, sizeof (atv)))) return (error); } - if (SCARG(uap, tzp)) - error = copyout((void *)&tz, (void *)SCARG(uap, tzp), - sizeof (tz)); + if (tzp) + error = copyout(&tz, tzp, sizeof (tz)); return (error); } @@ -365,25 +368,28 @@ sys_settimeofday(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct timezone atz; struct timeval atv; + const struct timeval *tv; + const struct timezone *tzp; int error; + tv = SCARG(uap, tv); + tzp = SCARG(uap, tzp); + if ((error = suser(p, 0))) return (error); /* Verify all parameters before changing time. */ - if (SCARG(uap, tv) && (error = copyin((void *)SCARG(uap, tv), - (void *)&atv, sizeof(atv)))) + if (tv && (error = copyin(tv, &atv, sizeof(atv)))) return (error); - if (SCARG(uap, tzp) && (error = copyin((void *)SCARG(uap, tzp), - (void *)&atz, sizeof(atz)))) + if (tzp && (error = copyin(tzp, &atz, sizeof(atz)))) return (error); - if (SCARG(uap, tv)) { + if (tv) { struct timespec ts; TIMEVAL_TO_TIMESPEC(&atv, &ts); if ((error = settime(&ts)) != 0) return (error); } - if (SCARG(uap, tzp)) + if (tzp) tz = atz; return (0); } @@ -398,38 +404,38 @@ sys_adjfreq(struct proc *p, void *v, register_t *retval) } */ *uap = v; int error; int64_t f; + const int64_t *freq = SCARG(uap, freq); + int64_t *oldfreq = SCARG(uap, oldfreq); #ifndef __HAVE_TIMECOUNTER int s; - if (SCARG(uap, oldfreq)) { + if (oldfreq) { f = ntp_tick_permanent * hz; - if ((error = copyout((void *)&f, (void *)SCARG(uap, oldfreq), - sizeof(int64_t)))) + if ((error = copyout(&f, oldfreq, sizeof(int64_t)))) return (error); } - if (SCARG(uap, freq)) { + if (freq) { if ((error = suser(p, 0))) return (error); - if ((error = copyin((void *)SCARG(uap, freq), (void *)&f, - sizeof(int64_t)))) + if ((error = copyin(freq, &f, sizeof(int64_t)))) return (error); s = splclock(); ntp_tick_permanent = f / hz; splx(s); } #else - if (SCARG(uap, oldfreq)) { - if ((error = tc_adjfreq(&f, NULL)) != 0) + if (oldfreq) { + if ((error = tc_adjfreq(&f, NULL))) return (error); - if ((error = copyout(&f, SCARG(uap, oldfreq), sizeof(f))) != 0) + if ((error = copyout(&f, oldfreq, sizeof(f)))) return (error); } - if (SCARG(uap, freq)) { + if (freq) { if ((error = suser(p, 0))) return (error); - if ((error = copyin(SCARG(uap, freq), &f, sizeof(f))) != 0) + if ((error = copyin(freq, &f, sizeof(f)))) return (error); - if ((error = tc_adjfreq(NULL, &f)) != 0) + if ((error = tc_adjfreq(NULL, &f))) return (error); } #endif @@ -444,20 +450,22 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) syscallarg(const struct timeval *) delta; syscallarg(struct timeval *) olddelta; } */ *uap = v; + const struct timeval *delta = SCARG(uap, delta); + struct timeval *olddelta = SCARG(uap, olddelta); #ifdef __HAVE_TIMECOUNTER int error; - if (SCARG(uap, olddelta)) - if ((error = copyout((void *)&adjtimedelta, - (void *)SCARG(uap, olddelta), sizeof(struct timeval)))) + if (olddelta) + if ((error = copyout(&adjtimedelta, olddelta, + sizeof(struct timeval)))) return (error); - if (SCARG(uap, delta)) { + if (delta) { if ((error = suser(p, 0))) return (error); - if ((error = copyin((void *)SCARG(uap, delta), - (void *)&adjtimedelta, sizeof(struct timeval)))) + if ((error = copyin(delta, &adjtimedelta, + sizeof(struct timeval)))) return (error); } @@ -476,7 +484,7 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) long ndelta, ntickdelta, odelta; int s, error; - if (!SCARG(uap, delta)) { + if (!delta) { s = splclock(); odelta = timedelta; splx(s); @@ -484,8 +492,7 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) } if ((error = suser(p, 0))) return (error); - if ((error = copyin((void *)SCARG(uap, delta), (void *)&atv, - sizeof(struct timeval)))) + if ((error = copyin(delta, &atv, sizeof(struct timeval)))) return (error); /* @@ -530,11 +537,10 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) splx(s); out: - if (SCARG(uap, olddelta)) { + if (olddelta) { atv.tv_sec = odelta / 1000000; atv.tv_usec = odelta % 1000000; - if ((error = copyout((void *)&atv, (void *)SCARG(uap, olddelta), - sizeof(struct timeval)))) + if ((error = copyout(&atv, olddelta, sizeof(struct timeval)))) return (error); } return (0); @@ -573,11 +579,14 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) } */ *uap = v; struct itimerval aitv; int s; + int which; + + which = SCARG(uap, which); - if (SCARG(uap, which) < ITIMER_REAL || SCARG(uap, which) > ITIMER_PROF) + if (which < ITIMER_REAL || which > ITIMER_PROF) return (EINVAL); s = splclock(); - if (SCARG(uap, which) == ITIMER_REAL) { + if (which == ITIMER_REAL) { struct timeval now; getmicrouptime(&now); @@ -596,10 +605,9 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) &aitv.it_value); } } else - aitv = p->p_stats->p_timer[SCARG(uap, which)]; + aitv = p->p_stats->p_timer[which]; splx(s); - return (copyout((void *)&aitv, (void *)SCARG(uap, itv), - sizeof (struct itimerval))); + return (copyout(&aitv, SCARG(uap, itv), sizeof (struct itimerval))); } /* ARGSUSED */ @@ -614,18 +622,23 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) struct sys_getitimer_args getargs; struct itimerval aitv; const struct itimerval *itvp; + struct itimerval *oitv; int error; int timo; + int which; + + which = SCARG(uap, which); + oitv = SCARG(uap, oitv); - if (SCARG(uap, which) < ITIMER_REAL || SCARG(uap, which) > ITIMER_PROF) + if (which < ITIMER_REAL || which > ITIMER_PROF) return (EINVAL); itvp = SCARG(uap, itv); if (itvp && (error = copyin((void *)itvp, (void *)&aitv, sizeof(struct itimerval)))) return (error); - if (SCARG(uap, oitv) != NULL) { - SCARG(&getargs, which) = SCARG(uap, which); - SCARG(&getargs, itv) = SCARG(uap, oitv); + if (oitv != NULL) { + SCARG(&getargs, which) = which; + SCARG(&getargs, itv) = oitv; if ((error = sys_getitimer(p, &getargs, retval))) return (error); } @@ -633,7 +646,7 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) return (0); if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) return (EINVAL); - if (SCARG(uap, which) == ITIMER_REAL) { + if (which == ITIMER_REAL) { struct timeval ctv; timeout_del(&p->p_realit_to); @@ -649,10 +662,10 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) itimerround(&aitv.it_interval); s = splclock(); - p->p_stats->p_timer[SCARG(uap, which)] = aitv; - if (SCARG(uap, which) == ITIMER_VIRTUAL) + p->p_stats->p_timer[which] = aitv; + if (which == ITIMER_VIRTUAL) timeout_del(&p->p_stats->p_virt_to); - if (SCARG(uap, which) == ITIMER_PROF) + if (which == ITIMER_PROF) timeout_del(&p->p_stats->p_prof_to); splx(s); } |