diff options
Diffstat (limited to 'sys/kern')
| -rw-r--r-- | sys/kern/kern_exec.c | 13 | ||||
| -rw-r--r-- | sys/kern/kern_sysctl.c | 86 | ||||
| -rw-r--r-- | sys/kern/kern_xxx.c | 9 | ||||
| -rw-r--r-- | sys/kern/sys_generic.c | 22 | ||||
| -rw-r--r-- | sys/kern/sysv_shm.c | 6 | ||||
| -rw-r--r-- | sys/kern/vfs_bio.c | 48 | ||||
| -rw-r--r-- | sys/kern/vfs_cluster.c | 14 |
7 files changed, 125 insertions, 73 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 41d5ca05dbe8..c77fe20ba65c 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_exec.c,v 1.83 1998/06/07 17:11:33 dfr Exp $ + * $Id: kern_exec.c,v 1.84 1998/07/15 06:19:33 bde Exp $ */ #include <sys/param.h> @@ -65,16 +65,11 @@ static long *exec_copyout_strings __P((struct image_params *)); -/* - * XXX trouble here if sizeof(caddr_t) != sizeof(int), other parts - * of the sysctl code also assumes this, and sizeof(int) == sizeof(long). - */ static struct ps_strings *ps_strings = PS_STRINGS; -SYSCTL_INT(_kern, KERN_PS_STRINGS, ps_strings, 0, &ps_strings, 0, ""); +SYSCTL_INTPTR(_kern, KERN_PS_STRINGS, ps_strings, 0, &ps_strings, 0, ""); static caddr_t usrstack = (caddr_t)USRSTACK; -SYSCTL_INT(_kern, KERN_USRSTACK, usrstack, 0, &usrstack, 0, ""); - +SYSCTL_INTPTR(_kern, KERN_USRSTACK, usrstack, 0, &usrstack, 0, ""); /* * execsw_set is constructed for us by the linker. Each of the items * is a pointer to a `const struct execsw', hence the double pointer here. @@ -375,7 +370,7 @@ exec_map_first_page(imgp) break; if (ma[i]->valid) break; - ma[i]->flags |= PG_BUSY; + PAGE_SET_FLAG(ma[i], PG_BUSY); } else { ma[i] = vm_page_alloc(object, i, VM_ALLOC_NORMAL); if (ma[i] == NULL) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index b1dc38f9ecff..df744f5fb538 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 - * $Id: kern_sysctl.c,v 1.73 1997/11/06 19:29:15 phk Exp $ + * $Id: kern_sysctl.c,v 1.74 1997/12/16 17:40:20 eivind Exp $ */ #include "opt_compat.h" @@ -514,6 +514,60 @@ sysctl_handle_int SYSCTL_HANDLER_ARGS } /* + * Handle an integer, signed or unsigned. + * Two cases: + * a variable: point arg1 at it. + * a constant: pass it in arg2. + */ + +int +sysctl_handle_long SYSCTL_HANDLER_ARGS +{ + int error = 0; + + if (arg1) + error = SYSCTL_OUT(req, arg1, sizeof(long)); + else + error = SYSCTL_OUT(req, &arg2, sizeof(long)); + + if (error || !req->newptr) + return (error); + + if (!arg1) + error = EPERM; + else + error = SYSCTL_IN(req, arg1, sizeof(long)); + return (error); +} + +/* + * Handle an integer, signed or unsigned. + * Two cases: + * a variable: point arg1 at it. + * a constant: pass it in arg2. + */ + +int +sysctl_handle_intptr SYSCTL_HANDLER_ARGS +{ + int error = 0; + + if (arg1) + error = SYSCTL_OUT(req, arg1, sizeof(intptr_t)); + else + error = SYSCTL_OUT(req, &arg2, sizeof(intptr_t)); + + if (error || !req->newptr) + return (error); + + if (!arg1) + error = EPERM; + else + error = SYSCTL_IN(req, arg1, sizeof(intptr_t)); + return (error); +} + +/* * Handle our generic '\0' terminated 'C' string. * Two cases: * a variable string: point arg1 at it, arg2 is max length. @@ -566,12 +620,14 @@ sysctl_handle_opaque SYSCTL_HANDLER_ARGS * XXX: rather untested at this point */ static int -sysctl_old_kernel(struct sysctl_req *req, const void *p, int l) +sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l) { - int i = 0; + size_t i = 0; if (req->oldptr) { - i = min(req->oldlen - req->oldidx, l); + i = l; + if (i > req->oldlen - req->oldidx) + i = req->oldlen - req->oldidx; if (i > 0) bcopy(p, (char *)req->oldptr + req->oldidx, i); } @@ -582,7 +638,7 @@ sysctl_old_kernel(struct sysctl_req *req, const void *p, int l) } static int -sysctl_new_kernel(struct sysctl_req *req, void *p, int l) +sysctl_new_kernel(struct sysctl_req *req, void *p, size_t l) { if (!req->newptr) return 0; @@ -594,7 +650,7 @@ sysctl_new_kernel(struct sysctl_req *req, void *p, int l) } int -kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, void *new, size_t newlen, int *retval) +kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, void *new, size_t newlen, size_t *retval) { int error = 0; struct sysctl_req req; @@ -656,16 +712,19 @@ kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldle * Transfer function to/from user space. */ static int -sysctl_old_user(struct sysctl_req *req, const void *p, int l) +sysctl_old_user(struct sysctl_req *req, const void *p, size_t l) { - int error = 0, i = 0; + int error = 0; + size_t i = 0; if (req->lock == 1 && req->oldptr) { vslock(req->oldptr, req->oldlen); req->lock = 2; } if (req->oldptr) { - i = min(req->oldlen - req->oldidx, l); + i = l; + if (i > req->oldlen - req->oldidx) + i = req->oldlen - req->oldidx; if (i > 0) error = copyout(p, (char *)req->oldptr + req->oldidx, i); @@ -679,7 +738,7 @@ sysctl_old_user(struct sysctl_req *req, const void *p, int l) } static int -sysctl_new_user(struct sysctl_req *req, void *p, int l) +sysctl_new_user(struct sysctl_req *req, void *p, size_t l) { int error; @@ -773,7 +832,8 @@ struct sysctl_args { int __sysctl(struct proc *p, struct sysctl_args *uap) { - int error, i, j, name[CTL_MAXNAME]; + int error, i, name[CTL_MAXNAME]; + size_t j; if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) return (EINVAL); @@ -800,7 +860,7 @@ __sysctl(struct proc *p, struct sysctl_args *uap) * must be in kernel space. */ int -userland_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, int *retval) +userland_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval) { int error = 0; struct sysctl_req req, req2; @@ -944,7 +1004,7 @@ int ogetkerninfo(struct proc *p, struct getkerninfo_args *uap) { int error, name[6]; - u_int size; + size_t size; switch (uap->op & 0xff00) { diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c index 8a61710a5b52..b7cb83bc976c 100644 --- a/sys/kern/kern_xxx.c +++ b/sys/kern/kern_xxx.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 - * $Id: kern_xxx.c,v 1.26 1997/11/06 19:29:18 phk Exp $ + * $Id: kern_xxx.c,v 1.27 1997/12/16 17:40:21 eivind Exp $ */ #include "opt_compat.h" @@ -60,10 +60,11 @@ ogethostname(p, uap) struct gethostname_args *uap; { int name[2]; + size_t len = uap->len; name[0] = CTL_KERN; name[1] = KERN_HOSTNAME; - return (userland_sysctl(p, name, 2, uap->hostname, &uap->len, + return (userland_sysctl(p, name, 2, uap->hostname, &len, 1, 0, 0, 0)); } @@ -149,7 +150,8 @@ uname(p, uap) struct proc *p; struct uname_args *uap; { - int name[2], len, rtval; + int name[2], rtval; + size_t len; char *s, *us; name[0] = CTL_KERN; @@ -197,6 +199,7 @@ uname(p, uap) if( rtval) return rtval; + name[0] = CTL_HW; name[1] = HW_MACHINE; len = sizeof uap->name->machine; rtval = userland_sysctl(p, name, 2, uap->name->machine, &len, diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index f8adb859a282..3229829a6b68 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 - * $Id: sys_generic.c,v 1.38 1998/05/17 11:52:51 phk Exp $ + * $Id: sys_generic.c,v 1.39 1998/06/10 10:29:31 dfr Exp $ */ #include "opt_ktrace.h" @@ -61,6 +61,8 @@ #include <sys/ktrace.h> #endif +#include <machine/limits.h> + static MALLOC_DEFINE(M_IOCTLOPS, "ioctlops", "ioctl data buffer"); static MALLOC_DEFINE(M_SELECT, "select", "select() buffer"); MALLOC_DEFINE(M_IOV, "iov", "large iov's"); @@ -102,11 +104,9 @@ read(p, uap) auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_offset = -1; - - auio.uio_resid = uap->nbyte; - if (auio.uio_resid < 0) + if (uap->nbyte > INT_MAX) return (EINVAL); - + auio.uio_resid = uap->nbyte; auio.uio_rw = UIO_READ; auio.uio_segflg = UIO_USERSPACE; auio.uio_procp = p; @@ -183,11 +183,11 @@ readv(p, uap) goto done; auio.uio_resid = 0; for (i = 0; i < uap->iovcnt; i++) { - auio.uio_resid += iov->iov_len; - if (auio.uio_resid < 0) { + if (iov->iov_len > INT_MAX - auio.uio_resid) { error = EINVAL; goto done; } + auio.uio_resid += iov->iov_len; iov++; } #ifdef KTRACE @@ -253,6 +253,8 @@ write(p, uap) auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_offset = -1; + if (uap->nbyte > INT_MAX) + return (EINVAL); auio.uio_resid = uap->nbyte; auio.uio_rw = UIO_WRITE; auio.uio_segflg = UIO_USERSPACE; @@ -334,11 +336,11 @@ writev(p, uap) goto done; auio.uio_resid = 0; for (i = 0; i < uap->iovcnt; i++) { - auio.uio_resid += iov->iov_len; - if (auio.uio_resid < 0) { + if (iov->iov_len > INT_MAX - auio.uio_resid) { error = EINVAL; goto done; } + auio.uio_resid += iov->iov_len; iov++; } #ifdef KTRACE @@ -380,7 +382,7 @@ done: #ifndef _SYS_SYSPROTO_H_ struct ioctl_args { int fd; - int com; + u_long com; caddr_t data; }; #endif diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 25e03a2469f8..8aabc9a2e411 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1,4 +1,4 @@ -/* $Id: sysv_shm.c,v 1.36 1998/05/04 03:01:37 dyson Exp $ */ +/* $Id: sysv_shm.c,v 1.37 1998/05/04 17:12:47 dyson Exp $ */ /* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */ /* @@ -503,8 +503,8 @@ shmget_allocate_segment(p, uap, mode) shm_handle->shm_object = vm_pager_allocate(OBJT_SWAP, 0, OFF_TO_IDX(size), VM_PROT_DEFAULT, 0); - shm_handle->shm_object->flags &= ~OBJ_ONEMAPPING; - shm_handle->shm_object->flags |= OBJ_NOSPLIT; + vm_object_clear_flag(shm_handle->shm_object, OBJ_ONEMAPPING); + vm_object_set_flag(shm_handle->shm_object, OBJ_NOSPLIT); shmseg->shm_internal = shm_handle; shmseg->shm_perm.cuid = shmseg->shm_perm.uid = cred->cr_uid; diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 8a759c076ca3..dd63c5ca0fef 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -11,7 +11,7 @@ * 2. Absolutely no warranty of function or purpose is made by the author * John S. Dyson. * - * $Id: vfs_bio.c,v 1.168 1998/08/06 08:33:18 dfr Exp $ + * $Id: vfs_bio.c,v 1.169 1998/08/13 08:09:07 dfr Exp $ */ /* @@ -648,7 +648,7 @@ brelse(struct buf * bp) for (i = 0; i < bp->b_npages; i++) { m = bp->b_pages[i]; - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); if (m == bogus_page) { obj = (vm_object_t) vp->v_object; @@ -835,9 +835,9 @@ vfs_vmio_release(bp) vm_page_cache(m); else vm_page_deactivate(m); - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); } else if (m->hold_count == 0) { - m->flags |= PG_BUSY; + PAGE_SET_FLAG(m, PG_BUSY); vm_page_protect(m, VM_PROT_NONE); vm_page_free(m); } @@ -847,7 +847,7 @@ vfs_vmio_release(bp) * act_count. */ m->act_count = 0; - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); } } } @@ -1357,7 +1357,7 @@ vfs_setdirty(struct buf *bp) { * by users through the VM system. */ for (i = 0; i < bp->b_npages; i++) { - bp->b_pages[i]->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(bp->b_pages[i], PG_ZERO); vm_page_test_dirty(bp->b_pages[i]); } @@ -1789,13 +1789,13 @@ allocbuf(struct buf * bp, int size) } vm_page_wire(m); - m->flags &= ~PG_BUSY; + PAGE_CLEAR_FLAG(m, PG_BUSY); bp->b_flags &= ~B_CACHE; } else if (m->flags & PG_BUSY) { s = splvm(); if (m->flags & PG_BUSY) { - m->flags |= PG_WANTED; + PAGE_SET_FLAG(m, PG_WANTED); tsleep(m, PVM, "pgtblk", 0); } splx(s); @@ -1812,7 +1812,7 @@ allocbuf(struct buf * bp, int size) bytesinpage = newbsize - toff; if (bp->b_flags & B_CACHE) vfs_buf_set_valid(bp, off, toff, bytesinpage, m); - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); vm_page_wire(m); } bp->b_pages[pageindex] = m; @@ -1971,7 +1971,7 @@ biodone(register struct buf * bp) #if defined(VFS_BIO_DEBUG) printf("biodone: page disappeared\n"); #endif - --obj->paging_in_progress; + vm_object_pip_subtract(obj, 1); continue; } bp->b_pages[i] = m; @@ -1994,7 +1994,7 @@ biodone(register struct buf * bp) if ((bp->b_flags & B_READ) && !bogusflag && resid > 0) { vfs_page_set_valid(bp, foff, i, m); } - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); /* * when debugging new filesystems or buffer I/O methods, this @@ -2025,14 +2025,14 @@ biodone(register struct buf * bp) panic("biodone: page busy < 0\n"); } PAGE_BWAKEUP(m); - --obj->paging_in_progress; + vm_object_pip_subtract(obj, 1); foff += resid; iosize -= resid; } if (obj && (obj->paging_in_progress == 0) && (obj->flags & OBJ_PIPWNT)) { - obj->flags &= ~OBJ_PIPWNT; + vm_object_clear_flag(obj, OBJ_PIPWNT); wakeup(obj); } } @@ -2125,15 +2125,13 @@ vfs_unbusy_pages(struct buf * bp) bp->b_pages[i] = m; pmap_qenter(trunc_page(bp->b_data), bp->b_pages, bp->b_npages); } - s = splvm(); - --obj->paging_in_progress; - splx(s); - m->flags &= ~PG_ZERO; + vm_object_pip_subtract(obj, 1); + PAGE_CLEAR_FLAG(m, PG_ZERO); PAGE_BWAKEUP(m); } if (obj->paging_in_progress == 0 && (obj->flags & OBJ_PIPWNT)) { - obj->flags &= ~OBJ_PIPWNT; + vm_object_clear_flag(obj, OBJ_PIPWNT); wakeup(obj); } } @@ -2250,12 +2248,10 @@ retry: for (i = 0; i < bp->b_npages; i++, foff += PAGE_SIZE) { vm_page_t m = bp->b_pages[i]; - m->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(m, PG_ZERO); if ((bp->b_flags & B_CLUSTER) == 0) { - s = splvm(); - obj->paging_in_progress++; - splx(s); - m->busy++; + vm_object_pip_add(obj, 1); + PAGE_BUSY(m); } vm_page_protect(m, VM_PROT_NONE); @@ -2331,7 +2327,7 @@ vfs_bio_clrbuf(struct buf *bp) { } } bp->b_pages[i]->valid = VM_PAGE_BITS_ALL; - bp->b_pages[i]->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(bp->b_pages[i], PG_ZERO); } bp->b_resid = 0; } else { @@ -2369,7 +2365,7 @@ tryagain: } vm_page_wire(p); p->valid = VM_PAGE_BITS_ALL; - p->flags &= ~PG_ZERO; + PAGE_CLEAR_FLAG(p, PG_ZERO); pmap_kenter(pg, VM_PAGE_TO_PHYS(p)); bp->b_pages[index] = p; PAGE_WAKEUP(p); @@ -2399,7 +2395,7 @@ vm_hold_free_pages(struct buf * bp, vm_offset_t from, vm_offset_t to) #endif bp->b_pages[index] = NULL; pmap_kremove(pg); - p->flags |= PG_BUSY; + PAGE_SET_FLAG(p, PG_BUSY); vm_page_unwire(p); vm_page_free(p); } diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c index 3f969adae147..8eeeb8a40855 100644 --- a/sys/kern/vfs_cluster.c +++ b/sys/kern/vfs_cluster.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * @(#)vfs_cluster.c 8.7 (Berkeley) 2/13/94 - * $Id: vfs_cluster.c,v 1.67 1998/08/06 08:33:18 dfr Exp $ + * $Id: vfs_cluster.c,v 1.68 1998/08/13 08:09:07 dfr Exp $ */ #include "opt_debug_cluster.h" @@ -417,10 +417,8 @@ cluster_rbuild(vp, filesize, lbn, blkno, size, run, fbp) for (j = 0; j < tbp->b_npages; j += 1) { vm_page_t m; m = tbp->b_pages[j]; - s = splvm(); - ++m->busy; - ++m->object->paging_in_progress; - splx(s); + PAGE_BUSY(m); + vm_object_pip_add(m->object, 1); if ((bp->b_npages == 0) || (bp->b_pages[bp->b_npages-1] != m)) { bp->b_pages[bp->b_npages] = m; @@ -784,10 +782,8 @@ cluster_wbuild(vp, size, start_lbn, len) for (j = 0; j < tbp->b_npages; j += 1) { m = tbp->b_pages[j]; - s = splvm(); - ++m->busy; - ++m->object->paging_in_progress; - splx(s); + PAGE_BUSY(m); + vm_object_pip_add(m->object, 1); if ((bp->b_npages == 0) || (bp->b_pages[bp->b_npages - 1] != m)) { bp->b_pages[bp->b_npages] = m; |
