Print this page
patch as-lock-macro-simplification

*** 960,972 **** if ((p->p_flag & SSYS) || as == &kas) n = 0; else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); n = prnsegs(as, 0); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); } prunlock(pnp); if (copyout(&n, cmaddr, sizeof (int))) error = EFAULT; --- 960,972 ---- if ((p->p_flag & SSYS) || as == &kas) n = 0; else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_WRITER); n = prnsegs(as, 0); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); } prunlock(pnp); if (copyout(&n, cmaddr, sizeof (int))) error = EFAULT;
*** 981,993 **** if ((p->p_flag & SSYS) || as == &kas) { error = 0; prunlock(pnp); } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); error = oprgetmap(p, &iolhead); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); prunlock(pnp); error = pr_iol_copyout_and_free(&iolhead, &cmaddr, error); --- 981,993 ---- if ((p->p_flag & SSYS) || as == &kas) { error = 0; prunlock(pnp); } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_WRITER); error = oprgetmap(p, &iolhead); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); prunlock(pnp); error = pr_iol_copyout_and_free(&iolhead, &cmaddr, error);
*** 1655,1669 **** psp->pr_size = 0; psp->pr_rssize = 0; psp->pr_pctmem = 0; } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_READER); psp->pr_size = (size32_t)btopr(as->a_resvsize); psp->pr_rssize = (size32_t)rm_asrss(as); psp->pr_pctmem = rm_pctmemory(as); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); } } psp->pr_bysize = (size32_t)ptob(psp->pr_size); psp->pr_byrssize = (size32_t)ptob(psp->pr_rssize); --- 1655,1669 ---- psp->pr_size = 0; psp->pr_rssize = 0; psp->pr_pctmem = 0; } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_READER); psp->pr_size = (size32_t)btopr(as->a_resvsize); psp->pr_rssize = (size32_t)rm_asrss(as); psp->pr_pctmem = rm_pctmemory(as); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); } } psp->pr_bysize = (size32_t)ptob(psp->pr_size); psp->pr_byrssize = (size32_t)ptob(psp->pr_rssize);
*** 2587,2599 **** if ((p->p_flag & SSYS) || as == &kas) n = 0; else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); n = prnsegs(as, 0); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); } prunlock(pnp); if (copyout(&n, cmaddr, sizeof (int))) error = EFAULT; --- 2587,2599 ---- if ((p->p_flag & SSYS) || as == &kas) n = 0; else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_WRITER); n = prnsegs(as, 0); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); } prunlock(pnp); if (copyout(&n, cmaddr, sizeof (int))) error = EFAULT;
*** 2611,2623 **** } else if (PROCESS_NOT_32BIT(p)) { error = EOVERFLOW; prunlock(pnp); } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); error = oprgetmap32(p, &iolhead); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); prunlock(pnp); error = pr_iol_copyout_and_free(&iolhead, &cmaddr, error); --- 2611,2623 ---- } else if (PROCESS_NOT_32BIT(p)) { error = EOVERFLOW; prunlock(pnp); } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_WRITER); error = oprgetmap32(p, &iolhead); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); prunlock(pnp); error = pr_iol_copyout_and_free(&iolhead, &cmaddr, error);
*** 3140,3161 **** * the clock thread. The process will not * disappear and its address space will not * change because it is marked P_PR_LOCK. */ mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_READER); seg = as_segat(as, va); if (seg != NULL && seg->s_ops == &segvn_ops && SEGOP_GETVP(seg, va, &xvp) == 0 && xvp != NULL && xvp->v_type == VREG) { VN_HOLD(xvp); } else { error = EINVAL; } ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); } else if ((xvp = p->p_exec) == NULL) { error = EINVAL; } else { VN_HOLD(xvp); --- 3140,3161 ---- * the clock thread. The process will not * disappear and its address space will not * change because it is marked P_PR_LOCK. */ mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_READER); seg = as_segat(as, va); if (seg != NULL && seg->s_ops == &segvn_ops && SEGOP_GETVP(seg, va, &xvp) == 0 && xvp != NULL && xvp->v_type == VREG) { VN_HOLD(xvp); } else { error = EINVAL; } ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); } else if ((xvp = p->p_exec) == NULL) { error = EINVAL; } else { VN_HOLD(xvp);
*** 3494,3508 **** psp->pr_size = 0; psp->pr_rssize = 0; psp->pr_pctmem = 0; } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, &as->a_lock, RW_READER); psp->pr_size = btopr(as->a_resvsize); psp->pr_rssize = rm_asrss(as); psp->pr_pctmem = rm_pctmemory(as); ! AS_LOCK_EXIT(as, &as->a_lock); mutex_enter(&p->p_lock); } } psp->pr_bysize = ptob(psp->pr_size); psp->pr_byrssize = ptob(psp->pr_rssize); --- 3494,3508 ---- psp->pr_size = 0; psp->pr_rssize = 0; psp->pr_pctmem = 0; } else { mutex_exit(&p->p_lock); ! AS_LOCK_ENTER(as, RW_READER); psp->pr_size = btopr(as->a_resvsize); psp->pr_rssize = rm_asrss(as); psp->pr_pctmem = rm_pctmemory(as); ! AS_LOCK_EXIT(as); mutex_enter(&p->p_lock); } } psp->pr_bysize = ptob(psp->pr_size); psp->pr_byrssize = ptob(psp->pr_rssize);
*** 3521,3531 **** prmap_t *mp; struct seg *seg; struct seg *brkseg, *stkseg; uint_t prot; ! ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock)); /* * Request an initial buffer size that doesn't waste memory * if the address space has only a small number of segments. */ --- 3521,3531 ---- prmap_t *mp; struct seg *seg; struct seg *brkseg, *stkseg; uint_t prot; ! ASSERT(as != &kas && AS_WRITE_HELD(as)); /* * Request an initial buffer size that doesn't waste memory * if the address space has only a small number of segments. */
*** 3581,3591 **** ioc_prmap32_t *mp; struct seg *seg; struct seg *brkseg, *stkseg; uint_t prot; ! ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock)); /* * Request an initial buffer size that doesn't waste memory * if the address space has only a small number of segments. */ --- 3581,3591 ---- ioc_prmap32_t *mp; struct seg *seg; struct seg *brkseg, *stkseg; uint_t prot; ! ASSERT(as != &kas && AS_WRITE_HELD(as)); /* * Request an initial buffer size that doesn't waste memory * if the address space has only a small number of segments. */
*** 3641,3651 **** oprpdsize(struct as *as) { struct seg *seg; size_t size; ! ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock)); if ((seg = AS_SEGFIRST(as)) == NULL) return (0); size = sizeof (prpageheader_t); --- 3641,3651 ---- oprpdsize(struct as *as) { struct seg *seg; size_t size; ! ASSERT(as != &kas && AS_WRITE_HELD(as)); if ((seg = AS_SEGFIRST(as)) == NULL) return (0); size = sizeof (prpageheader_t);
*** 3671,3681 **** oprpdsize32(struct as *as) { struct seg *seg; size_t size; ! ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock)); if ((seg = AS_SEGFIRST(as)) == NULL) return (0); size = sizeof (ioc_prpageheader32_t); --- 3671,3681 ---- oprpdsize32(struct as *as) { struct seg *seg; size_t size; ! ASSERT(as != &kas && AS_WRITE_HELD(as)); if ((seg = AS_SEGFIRST(as)) == NULL) return (0); size = sizeof (ioc_prpageheader32_t);
*** 3709,3727 **** prasmap_t *pmp; struct seg *seg; int error; again: ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); if ((seg = AS_SEGFIRST(as)) == NULL) { ! AS_LOCK_EXIT(as, &as->a_lock); return (0); } size = oprpdsize(as); if (uiop->uio_resid < size) { ! AS_LOCK_EXIT(as, &as->a_lock); return (E2BIG); } buf = kmem_zalloc(size, KM_SLEEP); php = (prpageheader_t *)buf; --- 3709,3727 ---- prasmap_t *pmp; struct seg *seg; int error; again: ! AS_LOCK_ENTER(as, RW_WRITER); if ((seg = AS_SEGFIRST(as)) == NULL) { ! AS_LOCK_EXIT(as); return (0); } size = oprpdsize(as); if (uiop->uio_resid < size) { ! AS_LOCK_EXIT(as); return (E2BIG); } buf = kmem_zalloc(size, KM_SLEEP); php = (prpageheader_t *)buf;
*** 3763,3773 **** * EINTR so that this thread can be dislodged if * a latent bug causes us to spin indefinitely. */ if (next > (uintptr_t)buf + size) { pr_getprot_done(&tmp); ! AS_LOCK_EXIT(as, &as->a_lock); kmem_free(buf, size); if (ISSIG(curthread, JUSTLOOKING)) return (EINTR); --- 3763,3773 ---- * EINTR so that this thread can be dislodged if * a latent bug causes us to spin indefinitely. */ if (next > (uintptr_t)buf + size) { pr_getprot_done(&tmp); ! AS_LOCK_EXIT(as); kmem_free(buf, size); if (ISSIG(curthread, JUSTLOOKING)) return (EINTR);
*** 3795,3805 **** pmp = (prasmap_t *)next; } ASSERT(tmp == NULL); } while ((seg = AS_SEGNEXT(as, seg)) != NULL); ! AS_LOCK_EXIT(as, &as->a_lock); ASSERT((uintptr_t)pmp <= (uintptr_t)buf + size); error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop); kmem_free(buf, size); --- 3795,3805 ---- pmp = (prasmap_t *)next; } ASSERT(tmp == NULL); } while ((seg = AS_SEGNEXT(as, seg)) != NULL); ! AS_LOCK_EXIT(as); ASSERT((uintptr_t)pmp <= (uintptr_t)buf + size); error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop); kmem_free(buf, size);
*** 3816,3834 **** ioc_prasmap32_t *pmp; struct seg *seg; int error; again: ! AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER); if ((seg = AS_SEGFIRST(as)) == NULL) { ! AS_LOCK_EXIT(as, &as->a_lock); return (0); } size = oprpdsize32(as); if (uiop->uio_resid < size) { ! AS_LOCK_EXIT(as, &as->a_lock); return (E2BIG); } buf = kmem_zalloc(size, KM_SLEEP); php = (ioc_prpageheader32_t *)buf; --- 3816,3834 ---- ioc_prasmap32_t *pmp; struct seg *seg; int error; again: ! AS_LOCK_ENTER(as, RW_WRITER); if ((seg = AS_SEGFIRST(as)) == NULL) { ! AS_LOCK_EXIT(as); return (0); } size = oprpdsize32(as); if (uiop->uio_resid < size) { ! AS_LOCK_EXIT(as); return (E2BIG); } buf = kmem_zalloc(size, KM_SLEEP); php = (ioc_prpageheader32_t *)buf;
*** 3870,3880 **** * EINTR so that this thread can be dislodged if * a latent bug causes us to spin indefinitely. */ if (next > (uintptr_t)buf + size) { pr_getprot_done(&tmp); ! AS_LOCK_EXIT(as, &as->a_lock); kmem_free(buf, size); if (ISSIG(curthread, JUSTLOOKING)) return (EINTR); --- 3870,3880 ---- * EINTR so that this thread can be dislodged if * a latent bug causes us to spin indefinitely. */ if (next > (uintptr_t)buf + size) { pr_getprot_done(&tmp); ! AS_LOCK_EXIT(as); kmem_free(buf, size); if (ISSIG(curthread, JUSTLOOKING)) return (EINTR);
*** 3902,3912 **** pmp = (ioc_prasmap32_t *)next; } ASSERT(tmp == NULL); } while ((seg = AS_SEGNEXT(as, seg)) != NULL); ! AS_LOCK_EXIT(as, &as->a_lock); ASSERT((uintptr_t)pmp == (uintptr_t)buf + size); error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop); kmem_free(buf, size); --- 3902,3912 ---- pmp = (ioc_prasmap32_t *)next; } ASSERT(tmp == NULL); } while ((seg = AS_SEGNEXT(as, seg)) != NULL); ! AS_LOCK_EXIT(as); ASSERT((uintptr_t)pmp == (uintptr_t)buf + size); error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop); kmem_free(buf, size);