From 065b709a4208baa0e75e974676bd8d7b1393860d Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Fri, 7 Oct 2005 21:55:15 +0000 Subject: [PATCH] 1:1 Userland threading stage 2.1/4: Convert functions to use struct lwp instead struct proc. --- sys/cpu/i386/include/vm86.h | 4 +- sys/i386/i386/machdep.c | 72 +++++++++++++++------------- sys/i386/i386/sys_machdep.c | 54 ++++++++++----------- sys/i386/i386/vm86.c | 12 ++--- sys/i386/include/vm86.h | 4 +- sys/platform/pc32/i386/machdep.c | 72 +++++++++++++++------------- sys/platform/pc32/i386/sys_machdep.c | 54 ++++++++++----------- sys/platform/pc32/i386/vm86.c | 12 ++--- 8 files changed, 146 insertions(+), 138 deletions(-) diff --git a/sys/cpu/i386/include/vm86.h b/sys/cpu/i386/include/vm86.h index dd14aa6f74..c2317457ba 100644 --- a/sys/cpu/i386/include/vm86.h +++ b/sys/cpu/i386/include/vm86.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/vm86.h,v 1.13 1999/09/02 20:59:50 luoqi Exp $ - * $DragonFly: src/sys/cpu/i386/include/vm86.h,v 1.4 2003/11/03 22:50:15 dillon Exp $ + * $DragonFly: src/sys/cpu/i386/include/vm86.h,v 1.5 2005/10/07 21:55:15 corecode Exp $ */ #ifndef _MACHINE_VM86_H_ @@ -150,7 +150,7 @@ extern pt_entry_t *vm86paddr; struct proc; extern int vm86_emulate (struct vm86frame *); -extern int vm86_sysarch (struct proc *, char *); +extern int vm86_sysarch (struct lwp *, char *); extern void vm86_trap (struct vm86frame *); extern int vm86_intcall (int, struct vm86frame *); extern int vm86_datacall (int, struct vm86frame *, struct vm86context *); diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 86613e076d..4e2d1d1a50 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -36,7 +36,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/i386/i386/Attic/machdep.c,v 1.78 2005/10/05 21:53:41 corecode Exp $ + * $DragonFly: src/sys/i386/i386/Attic/machdep.c,v 1.79 2005/10/07 21:55:15 corecode Exp $ */ #include "use_apm.h" @@ -420,29 +420,31 @@ sendsig(catcher, sig, mask, code) sigset_t *mask; u_long code; { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; + struct proc *p = lp->lwp_proc; struct trapframe *regs; struct sigacts *psp = p->p_sigacts; struct sigframe sf, *sfp; int oonstack; - regs = p->p_md.md_regs; - oonstack = (p->p_sigstk.ss_flags & SS_ONSTACK) ? 1 : 0; + regs = lp->lwp_md.md_regs; + oonstack = (lp->lwp_sigstk.ss_flags & SS_ONSTACK) ? 1 : 0; /* save user context */ bzero(&sf, sizeof(struct sigframe)); sf.sf_uc.uc_sigmask = *mask; - sf.sf_uc.uc_stack = p->p_sigstk; + sf.sf_uc.uc_stack = lp->lwp_sigstk; sf.sf_uc.uc_mcontext.mc_onstack = oonstack; sf.sf_uc.uc_mcontext.mc_gs = rgs(); bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(struct trapframe)); /* Allocate and validate space for the signal handler context. */ + /* XXX lwp flags */ if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack && SIGISMEMBER(psp->ps_sigonstack, sig)) { - sfp = (struct sigframe *)(p->p_sigstk.ss_sp + - p->p_sigstk.ss_size - sizeof(struct sigframe)); - p->p_sigstk.ss_flags |= SS_ONSTACK; + sfp = (struct sigframe *)(lp->lwp_sigstk.ss_sp + + lp->lwp_sigstk.ss_size - sizeof(struct sigframe)); + lp->lwp_sigstk.ss_flags |= SS_ONSTACK; } else sfp = (struct sigframe *)regs->tf_esp - 1; @@ -456,7 +458,7 @@ sendsig(catcher, sig, mask, code) /* Build the argument list for the signal handler. */ sf.sf_signum = sig; sf.sf_ucontext = (register_t)&sfp->sf_uc; - if (SIGISMEMBER(p->p_sigacts->ps_siginfo, sig)) { + if (SIGISMEMBER(psp->ps_siginfo, sig)) { /* Signal handler installed with SA_SIGINFO. */ sf.sf_siginfo = (register_t)&sfp->sf_si; sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher; @@ -480,7 +482,7 @@ sendsig(catcher, sig, mask, code) */ if (regs->tf_eflags & PSL_VM) { struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs; - struct vm86_kernel *vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + struct vm86_kernel *vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs; sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs; @@ -540,7 +542,7 @@ sendsig(catcher, sig, mask, code) int sigreturn(struct sigreturn_args *uap) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; ucontext_t *ucp; int cs, eflags; @@ -550,7 +552,7 @@ sigreturn(struct sigreturn_args *uap) if (!useracc((caddr_t)ucp, sizeof(ucontext_t), VM_PROT_READ)) return (EFAULT); - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; eflags = ucp->uc_mcontext.mc_eflags; if (eflags & PSL_VM) { @@ -561,15 +563,15 @@ sigreturn(struct sigreturn_args *uap) * if pcb_ext == 0 or vm86_inited == 0, the user hasn't * set up the vm86 area, and we can't enter vm86 mode. */ - if (p->p_thread->td_pcb->pcb_ext == 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) return (EINVAL); - vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; if (vm86->vm86_inited == 0) return (EINVAL); /* go back to user mode if both flags are set */ if ((eflags & PSL_VIP) && (eflags & PSL_VIF)) - trapsignal(p, SIGBUS, 0); + trapsignal(lp->lwp_proc, SIGBUS, 0); if (vm86->vm86_has_vme) { eflags = (tf->tf_eflags & ~VME_USERCHANGE) | @@ -614,19 +616,19 @@ sigreturn(struct sigreturn_args *uap) cs = ucp->uc_mcontext.mc_cs; if (!CS_SECURE(cs)) { printf("sigreturn: cs = 0x%x\n", cs); - trapsignal(p, SIGBUS, T_PROTFLT); + trapsignal(lp->lwp_proc, SIGBUS, T_PROTFLT); return(EINVAL); } bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(struct trapframe)); } if (ucp->uc_mcontext.mc_onstack & 1) - p->p_sigstk.ss_flags |= SS_ONSTACK; + lp->lwp_sigstk.ss_flags |= SS_ONSTACK; else - p->p_sigstk.ss_flags &= ~SS_ONSTACK; + lp->lwp_sigstk.ss_flags &= ~SS_ONSTACK; - p->p_sigmask = ucp->uc_sigmask; - SIG_CANTMASK(p->p_sigmask); + lp->lwp_sigmask = ucp->uc_sigmask; + SIG_CANTMASK(lp->lwp_sigmask); return(EJUSTRETURN); } @@ -646,7 +648,7 @@ struct upc_frame { void sendupcall(struct vmupcall *vu, int morepending) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; struct upcall upcall; struct upc_frame upc_frame; @@ -655,7 +657,7 @@ sendupcall(struct vmupcall *vu, int morepending) /* * Get the upcall data structure */ - if (copyin(p->p_upcall, &upcall, sizeof(upcall)) || + if (copyin(lp->lwp_upcall, &upcall, sizeof(upcall)) || copyin((char *)upcall.upc_uthread + upcall.upc_critoff, &crit_count, sizeof(int)) ) { vu->vu_pending = 0; @@ -671,7 +673,7 @@ sendupcall(struct vmupcall *vu, int morepending) if (upcall.upc_pending || crit_count >= vu->vu_pending) { if (upcall.upc_pending < vu->vu_pending) { upcall.upc_pending = vu->vu_pending; - copyout(&upcall.upc_pending, &p->p_upcall->upc_pending, + copyout(&upcall.upc_pending, &lp->lwp_upcall->upc_pending, sizeof(upcall.upc_pending)); } return; @@ -688,7 +690,7 @@ sendupcall(struct vmupcall *vu, int morepending) vu->vu_pending = 0; upcall.upc_pending = morepending; crit_count += TDPRI_CRIT; - copyout(&upcall.upc_pending, &p->p_upcall->upc_pending, + copyout(&upcall.upc_pending, &lp->lwp_upcall->upc_pending, sizeof(upcall.upc_pending)); copyout(&crit_count, (char *)upcall.upc_uthread + upcall.upc_critoff, sizeof(int)); @@ -696,7 +698,7 @@ sendupcall(struct vmupcall *vu, int morepending) /* * Construct a stack frame and issue the upcall */ - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; upc_frame.eax = regs->tf_eax; upc_frame.ecx = regs->tf_ecx; upc_frame.edx = regs->tf_edx; @@ -708,7 +710,7 @@ sendupcall(struct vmupcall *vu, int morepending) } else { regs->tf_eax = (register_t)vu->vu_func; regs->tf_ecx = (register_t)vu->vu_data; - regs->tf_edx = (register_t)p->p_upcall; + regs->tf_edx = (register_t)lp->lwp_upcall; regs->tf_eip = (register_t)vu->vu_ctx; regs->tf_esp -= sizeof(upc_frame); } @@ -726,23 +728,22 @@ int fetchupcall (struct vmupcall *vu, int morepending, void *rsp) { struct upc_frame upc_frame; - struct proc *p; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; int error; struct upcall upcall; int crit_count; - p = curproc; - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; - error = copyout(&morepending, &p->p_upcall->upc_pending, sizeof(int)); + error = copyout(&morepending, &lp->lwp_upcall->upc_pending, sizeof(int)); if (error == 0) { if (vu) { /* * This jumps us to the next ready context. */ vu->vu_pending = 0; - error = copyin(p->p_upcall, &upcall, sizeof(upcall)); + error = copyin(lp->lwp_upcall, &upcall, sizeof(upcall)); crit_count = 0; if (error == 0) error = copyin((char *)upcall.upc_uthread + upcall.upc_critoff, &crit_count, sizeof(int)); @@ -751,7 +752,7 @@ fetchupcall (struct vmupcall *vu, int morepending, void *rsp) error = copyout(&crit_count, (char *)upcall.upc_uthread + upcall.upc_critoff, sizeof(int)); regs->tf_eax = (register_t)vu->vu_func; regs->tf_ecx = (register_t)vu->vu_data; - regs->tf_edx = (register_t)p->p_upcall; + regs->tf_edx = (register_t)lp->lwp_upcall; regs->tf_eip = (register_t)vu->vu_ctx; regs->tf_esp = (register_t)rsp; } else { @@ -1865,7 +1866,10 @@ init386(int first) lwkt_init_thread(&thread0, proc0paddr, LWKT_THREAD_STACK, 0, &gd->mi); lwkt_set_comm(&thread0, "thread0"); proc0.p_addr = (void *)thread0.td_kstack; - proc0.p_thread = &thread0; + LIST_INIT(&proc0.p_lwps); + LIST_INSERT_HEAD(&proc0.p_lwps, &proc0.p_lwp, lwp_list); + proc0.p_lwp.lwp_thread = &thread0; + proc0.p_lwp.lwp_proc = &proc0; proc0.p_usched = &usched_bsd4; varsymset_init(&proc0.p_varsymset, NULL); thread0.td_flags |= TDF_RUNNING; @@ -2015,7 +2019,7 @@ init386(int first) thread0.td_pcb->pcb_flags = 0; thread0.td_pcb->pcb_cr3 = (int)IdlePTD; /* should already be setup */ thread0.td_pcb->pcb_ext = 0; - proc0.p_md.md_regs = &proc0_tf; + proc0.p_lwp.lwp_md.md_regs = &proc0_tf; } /* diff --git a/sys/i386/i386/sys_machdep.c b/sys/i386/i386/sys_machdep.c index 66777bf077..d9f1d979b8 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -32,7 +32,7 @@ * * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91 * $FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.47.2.3 2002/10/07 17:20:00 jhb Exp $ - * $DragonFly: src/sys/i386/i386/Attic/sys_machdep.c,v 1.19 2005/08/29 21:08:02 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/sys_machdep.c,v 1.20 2005/10/07 21:55:15 corecode Exp $ * */ @@ -71,12 +71,12 @@ -static int i386_get_ldt (struct proc *, char *, int *); -static int i386_set_ldt (struct proc *, char *, int *); -static int i386_get_ioperm (struct proc *, char *); -static int i386_set_ioperm (struct proc *, char *); +static int i386_get_ldt(struct lwp *, char *, int *); +static int i386_set_ldt(struct lwp *, char *, int *); +static int i386_get_ioperm(struct lwp *, char *); +static int i386_set_ioperm(struct lwp *, char *); static int check_descs(union descriptor *, int); -int i386_extend_pcb (struct proc *); +int i386_extend_pcb(struct lwp *); /* * sysarch_args(int op, char *params) @@ -85,24 +85,24 @@ int i386_extend_pcb (struct proc *); int sysarch(struct sysarch_args *uap) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; int error = 0; switch(uap->op) { case I386_GET_LDT: - error = i386_get_ldt(p, uap->parms, &uap->sysmsg_result); + error = i386_get_ldt(lp, uap->parms, &uap->sysmsg_result); break; case I386_SET_LDT: - error = i386_set_ldt(p, uap->parms, &uap->sysmsg_result); + error = i386_set_ldt(lp, uap->parms, &uap->sysmsg_result); break; case I386_GET_IOPERM: - error = i386_get_ioperm(p, uap->parms); + error = i386_get_ioperm(lp, uap->parms); break; case I386_SET_IOPERM: - error = i386_set_ioperm(p, uap->parms); + error = i386_set_ioperm(lp, uap->parms); break; case I386_VM86: - error = vm86_sysarch(p, uap->parms); + error = vm86_sysarch(lp, uap->parms); break; default: error = EOPNOTSUPP; @@ -112,7 +112,7 @@ sysarch(struct sysarch_args *uap) } int -i386_extend_pcb(struct proc *p) +i386_extend_pcb(struct lwp *lp) { int i, offset; u_long *addr; @@ -131,9 +131,9 @@ i386_extend_pcb(struct proc *p) ext = (struct pcb_ext *)kmem_alloc(kernel_map, ctob(IOPAGES+1)); if (ext == 0) return (ENOMEM); - p->p_thread->td_pcb->pcb_ext = ext; + lp->lwp_thread->td_pcb->pcb_ext = ext; bzero(ext, sizeof(struct pcb_ext)); - ext->ext_tss.tss_esp0 = (unsigned)((char *)p->p_thread->td_pcb - 16); + ext->ext_tss.tss_esp0 = (unsigned)((char *)lp->lwp_thread->td_pcb - 16); ext->ext_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); /* * The last byte of the i/o map must be followed by an 0xff byte. @@ -161,7 +161,7 @@ i386_extend_pcb(struct proc *p) } static int -i386_set_ioperm(struct proc *p, char *args) +i386_set_ioperm(struct lwp *lp, char *args) { int i, error; struct i386_ioperm_args ua; @@ -170,7 +170,7 @@ i386_set_ioperm(struct proc *p, char *args) if ((error = copyin(args, &ua, sizeof(struct i386_ioperm_args))) != 0) return (error); - if ((error = suser_cred(p->p_ucred, 0)) != 0) + if ((error = suser_cred(lp->lwp_proc->p_ucred, 0)) != 0) return (error); if (securelevel > 0) return (EPERM); @@ -181,10 +181,10 @@ i386_set_ioperm(struct proc *p, char *args) * cause confusion. This probably requires a global 'usage registry'. */ - if (p->p_thread->td_pcb->pcb_ext == 0) - if ((error = i386_extend_pcb(p)) != 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) + if ((error = i386_extend_pcb(lp)) != 0) return (error); - iomap = (char *)p->p_thread->td_pcb->pcb_ext->ext_iomap; + iomap = (char *)lp->lwp_thread->td_pcb->pcb_ext->ext_iomap; if (ua.start + ua.length > IOPAGES * PAGE_SIZE * NBBY) return (EINVAL); @@ -199,7 +199,7 @@ i386_set_ioperm(struct proc *p, char *args) } static int -i386_get_ioperm(struct proc *p, char *args) +i386_get_ioperm(struct lwp *lp, char *args) { int i, state, error; struct i386_ioperm_args ua; @@ -210,12 +210,12 @@ i386_get_ioperm(struct proc *p, char *args) if (ua.start >= IOPAGES * PAGE_SIZE * NBBY) return (EINVAL); - if (p->p_thread->td_pcb->pcb_ext == 0) { + if (lp->lwp_thread->td_pcb->pcb_ext == 0) { ua.length = 0; goto done; } - iomap = (char *)p->p_thread->td_pcb->pcb_ext->ext_iomap; + iomap = (char *)lp->lwp_thread->td_pcb->pcb_ext->ext_iomap; i = ua.start; state = (iomap[i >> 3] >> (i & 7)) & 1; @@ -344,10 +344,10 @@ user_ldt_free(struct pcb *pcb) } static int -i386_get_ldt(struct proc *p, char *args, int *res) +i386_get_ldt(struct lwp *lwp, char *args, int *res) { int error = 0; - struct pcb *pcb = p->p_thread->td_pcb; + struct pcb *pcb = lwp->lwp_thread->td_pcb; struct pcb_ldt *pcb_ldt = pcb->pcb_ldt; unsigned int nldt, num; union descriptor *lp; @@ -390,11 +390,11 @@ i386_get_ldt(struct proc *p, char *args, int *res) } static int -i386_set_ldt(struct proc *p, char *args, int *res) +i386_set_ldt(struct lwp *lp, char *args, int *res) { int error = 0; int largest_ld; - struct pcb *pcb = p->p_thread->td_pcb; + struct pcb *pcb = lp->lwp_thread->td_pcb; struct pcb_ldt *pcb_ldt = pcb->pcb_ldt; union descriptor *descs; int descs_size; diff --git a/sys/i386/i386/vm86.c b/sys/i386/i386/vm86.c index c9ca5daeb9..1582ef184e 100644 --- a/sys/i386/i386/vm86.c +++ b/sys/i386/i386/vm86.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/vm86.c,v 1.31.2.2 2001/10/05 06:18:55 peter Exp $ - * $DragonFly: src/sys/i386/i386/Attic/vm86.c,v 1.14 2005/07/19 19:08:03 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/vm86.c,v 1.15 2005/10/07 21:55:15 corecode Exp $ */ #include @@ -720,7 +720,7 @@ vm86_getptr(vmc, kva, sel, off) } int -vm86_sysarch(struct proc *p, char *args) +vm86_sysarch(struct lwp *lp, char *args) { int error = 0; struct i386_vm86_args ua; @@ -729,10 +729,10 @@ vm86_sysarch(struct proc *p, char *args) if ((error = copyin(args, &ua, sizeof(struct i386_vm86_args))) != 0) return (error); - if (p->p_thread->td_pcb->pcb_ext == 0) - if ((error = i386_extend_pcb(p)) != 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) + if ((error = i386_extend_pcb(lp)) != 0) return (error); - vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; switch (ua.sub_op) { case VM86_INIT: { @@ -778,7 +778,7 @@ vm86_sysarch(struct proc *p, char *args) case VM86_INTCALL: { struct vm86_intcall_args sa; - if ((error = suser_cred(p->p_ucred, 0))) + if ((error = suser_cred(lp->lwp_proc->p_ucred, 0))) return (error); if ((error = copyin(ua.sub_args, &sa, sizeof(sa)))) return (error); diff --git a/sys/i386/include/vm86.h b/sys/i386/include/vm86.h index 842661946e..5096f49760 100644 --- a/sys/i386/include/vm86.h +++ b/sys/i386/include/vm86.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/vm86.h,v 1.13 1999/09/02 20:59:50 luoqi Exp $ - * $DragonFly: src/sys/i386/include/Attic/vm86.h,v 1.4 2003/11/03 22:50:15 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/vm86.h,v 1.5 2005/10/07 21:55:15 corecode Exp $ */ #ifndef _MACHINE_VM86_H_ @@ -150,7 +150,7 @@ extern pt_entry_t *vm86paddr; struct proc; extern int vm86_emulate (struct vm86frame *); -extern int vm86_sysarch (struct proc *, char *); +extern int vm86_sysarch (struct lwp *, char *); extern void vm86_trap (struct vm86frame *); extern int vm86_intcall (int, struct vm86frame *); extern int vm86_datacall (int, struct vm86frame *, struct vm86context *); diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index d1b79a5510..d46175560d 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -36,7 +36,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.78 2005/10/05 21:53:41 corecode Exp $ + * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.79 2005/10/07 21:55:15 corecode Exp $ */ #include "use_apm.h" @@ -420,29 +420,31 @@ sendsig(catcher, sig, mask, code) sigset_t *mask; u_long code; { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; + struct proc *p = lp->lwp_proc; struct trapframe *regs; struct sigacts *psp = p->p_sigacts; struct sigframe sf, *sfp; int oonstack; - regs = p->p_md.md_regs; - oonstack = (p->p_sigstk.ss_flags & SS_ONSTACK) ? 1 : 0; + regs = lp->lwp_md.md_regs; + oonstack = (lp->lwp_sigstk.ss_flags & SS_ONSTACK) ? 1 : 0; /* save user context */ bzero(&sf, sizeof(struct sigframe)); sf.sf_uc.uc_sigmask = *mask; - sf.sf_uc.uc_stack = p->p_sigstk; + sf.sf_uc.uc_stack = lp->lwp_sigstk; sf.sf_uc.uc_mcontext.mc_onstack = oonstack; sf.sf_uc.uc_mcontext.mc_gs = rgs(); bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(struct trapframe)); /* Allocate and validate space for the signal handler context. */ + /* XXX lwp flags */ if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack && SIGISMEMBER(psp->ps_sigonstack, sig)) { - sfp = (struct sigframe *)(p->p_sigstk.ss_sp + - p->p_sigstk.ss_size - sizeof(struct sigframe)); - p->p_sigstk.ss_flags |= SS_ONSTACK; + sfp = (struct sigframe *)(lp->lwp_sigstk.ss_sp + + lp->lwp_sigstk.ss_size - sizeof(struct sigframe)); + lp->lwp_sigstk.ss_flags |= SS_ONSTACK; } else sfp = (struct sigframe *)regs->tf_esp - 1; @@ -456,7 +458,7 @@ sendsig(catcher, sig, mask, code) /* Build the argument list for the signal handler. */ sf.sf_signum = sig; sf.sf_ucontext = (register_t)&sfp->sf_uc; - if (SIGISMEMBER(p->p_sigacts->ps_siginfo, sig)) { + if (SIGISMEMBER(psp->ps_siginfo, sig)) { /* Signal handler installed with SA_SIGINFO. */ sf.sf_siginfo = (register_t)&sfp->sf_si; sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher; @@ -480,7 +482,7 @@ sendsig(catcher, sig, mask, code) */ if (regs->tf_eflags & PSL_VM) { struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs; - struct vm86_kernel *vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + struct vm86_kernel *vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs; sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs; @@ -540,7 +542,7 @@ sendsig(catcher, sig, mask, code) int sigreturn(struct sigreturn_args *uap) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; ucontext_t *ucp; int cs, eflags; @@ -550,7 +552,7 @@ sigreturn(struct sigreturn_args *uap) if (!useracc((caddr_t)ucp, sizeof(ucontext_t), VM_PROT_READ)) return (EFAULT); - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; eflags = ucp->uc_mcontext.mc_eflags; if (eflags & PSL_VM) { @@ -561,15 +563,15 @@ sigreturn(struct sigreturn_args *uap) * if pcb_ext == 0 or vm86_inited == 0, the user hasn't * set up the vm86 area, and we can't enter vm86 mode. */ - if (p->p_thread->td_pcb->pcb_ext == 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) return (EINVAL); - vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; if (vm86->vm86_inited == 0) return (EINVAL); /* go back to user mode if both flags are set */ if ((eflags & PSL_VIP) && (eflags & PSL_VIF)) - trapsignal(p, SIGBUS, 0); + trapsignal(lp->lwp_proc, SIGBUS, 0); if (vm86->vm86_has_vme) { eflags = (tf->tf_eflags & ~VME_USERCHANGE) | @@ -614,19 +616,19 @@ sigreturn(struct sigreturn_args *uap) cs = ucp->uc_mcontext.mc_cs; if (!CS_SECURE(cs)) { printf("sigreturn: cs = 0x%x\n", cs); - trapsignal(p, SIGBUS, T_PROTFLT); + trapsignal(lp->lwp_proc, SIGBUS, T_PROTFLT); return(EINVAL); } bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(struct trapframe)); } if (ucp->uc_mcontext.mc_onstack & 1) - p->p_sigstk.ss_flags |= SS_ONSTACK; + lp->lwp_sigstk.ss_flags |= SS_ONSTACK; else - p->p_sigstk.ss_flags &= ~SS_ONSTACK; + lp->lwp_sigstk.ss_flags &= ~SS_ONSTACK; - p->p_sigmask = ucp->uc_sigmask; - SIG_CANTMASK(p->p_sigmask); + lp->lwp_sigmask = ucp->uc_sigmask; + SIG_CANTMASK(lp->lwp_sigmask); return(EJUSTRETURN); } @@ -646,7 +648,7 @@ struct upc_frame { void sendupcall(struct vmupcall *vu, int morepending) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; struct upcall upcall; struct upc_frame upc_frame; @@ -655,7 +657,7 @@ sendupcall(struct vmupcall *vu, int morepending) /* * Get the upcall data structure */ - if (copyin(p->p_upcall, &upcall, sizeof(upcall)) || + if (copyin(lp->lwp_upcall, &upcall, sizeof(upcall)) || copyin((char *)upcall.upc_uthread + upcall.upc_critoff, &crit_count, sizeof(int)) ) { vu->vu_pending = 0; @@ -671,7 +673,7 @@ sendupcall(struct vmupcall *vu, int morepending) if (upcall.upc_pending || crit_count >= vu->vu_pending) { if (upcall.upc_pending < vu->vu_pending) { upcall.upc_pending = vu->vu_pending; - copyout(&upcall.upc_pending, &p->p_upcall->upc_pending, + copyout(&upcall.upc_pending, &lp->lwp_upcall->upc_pending, sizeof(upcall.upc_pending)); } return; @@ -688,7 +690,7 @@ sendupcall(struct vmupcall *vu, int morepending) vu->vu_pending = 0; upcall.upc_pending = morepending; crit_count += TDPRI_CRIT; - copyout(&upcall.upc_pending, &p->p_upcall->upc_pending, + copyout(&upcall.upc_pending, &lp->lwp_upcall->upc_pending, sizeof(upcall.upc_pending)); copyout(&crit_count, (char *)upcall.upc_uthread + upcall.upc_critoff, sizeof(int)); @@ -696,7 +698,7 @@ sendupcall(struct vmupcall *vu, int morepending) /* * Construct a stack frame and issue the upcall */ - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; upc_frame.eax = regs->tf_eax; upc_frame.ecx = regs->tf_ecx; upc_frame.edx = regs->tf_edx; @@ -708,7 +710,7 @@ sendupcall(struct vmupcall *vu, int morepending) } else { regs->tf_eax = (register_t)vu->vu_func; regs->tf_ecx = (register_t)vu->vu_data; - regs->tf_edx = (register_t)p->p_upcall; + regs->tf_edx = (register_t)lp->lwp_upcall; regs->tf_eip = (register_t)vu->vu_ctx; regs->tf_esp -= sizeof(upc_frame); } @@ -726,23 +728,22 @@ int fetchupcall (struct vmupcall *vu, int morepending, void *rsp) { struct upc_frame upc_frame; - struct proc *p; + struct lwp *lp = curthread->td_lwp; struct trapframe *regs; int error; struct upcall upcall; int crit_count; - p = curproc; - regs = p->p_md.md_regs; + regs = lp->lwp_md.md_regs; - error = copyout(&morepending, &p->p_upcall->upc_pending, sizeof(int)); + error = copyout(&morepending, &lp->lwp_upcall->upc_pending, sizeof(int)); if (error == 0) { if (vu) { /* * This jumps us to the next ready context. */ vu->vu_pending = 0; - error = copyin(p->p_upcall, &upcall, sizeof(upcall)); + error = copyin(lp->lwp_upcall, &upcall, sizeof(upcall)); crit_count = 0; if (error == 0) error = copyin((char *)upcall.upc_uthread + upcall.upc_critoff, &crit_count, sizeof(int)); @@ -751,7 +752,7 @@ fetchupcall (struct vmupcall *vu, int morepending, void *rsp) error = copyout(&crit_count, (char *)upcall.upc_uthread + upcall.upc_critoff, sizeof(int)); regs->tf_eax = (register_t)vu->vu_func; regs->tf_ecx = (register_t)vu->vu_data; - regs->tf_edx = (register_t)p->p_upcall; + regs->tf_edx = (register_t)lp->lwp_upcall; regs->tf_eip = (register_t)vu->vu_ctx; regs->tf_esp = (register_t)rsp; } else { @@ -1865,7 +1866,10 @@ init386(int first) lwkt_init_thread(&thread0, proc0paddr, LWKT_THREAD_STACK, 0, &gd->mi); lwkt_set_comm(&thread0, "thread0"); proc0.p_addr = (void *)thread0.td_kstack; - proc0.p_thread = &thread0; + LIST_INIT(&proc0.p_lwps); + LIST_INSERT_HEAD(&proc0.p_lwps, &proc0.p_lwp, lwp_list); + proc0.p_lwp.lwp_thread = &thread0; + proc0.p_lwp.lwp_proc = &proc0; proc0.p_usched = &usched_bsd4; varsymset_init(&proc0.p_varsymset, NULL); thread0.td_flags |= TDF_RUNNING; @@ -2015,7 +2019,7 @@ init386(int first) thread0.td_pcb->pcb_flags = 0; thread0.td_pcb->pcb_cr3 = (int)IdlePTD; /* should already be setup */ thread0.td_pcb->pcb_ext = 0; - proc0.p_md.md_regs = &proc0_tf; + proc0.p_lwp.lwp_md.md_regs = &proc0_tf; } /* diff --git a/sys/platform/pc32/i386/sys_machdep.c b/sys/platform/pc32/i386/sys_machdep.c index 641d1beb18..3fe80c5bc0 100644 --- a/sys/platform/pc32/i386/sys_machdep.c +++ b/sys/platform/pc32/i386/sys_machdep.c @@ -32,7 +32,7 @@ * * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91 * $FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.47.2.3 2002/10/07 17:20:00 jhb Exp $ - * $DragonFly: src/sys/platform/pc32/i386/sys_machdep.c,v 1.19 2005/08/29 21:08:02 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/sys_machdep.c,v 1.20 2005/10/07 21:55:15 corecode Exp $ * */ @@ -71,12 +71,12 @@ -static int i386_get_ldt (struct proc *, char *, int *); -static int i386_set_ldt (struct proc *, char *, int *); -static int i386_get_ioperm (struct proc *, char *); -static int i386_set_ioperm (struct proc *, char *); +static int i386_get_ldt(struct lwp *, char *, int *); +static int i386_set_ldt(struct lwp *, char *, int *); +static int i386_get_ioperm(struct lwp *, char *); +static int i386_set_ioperm(struct lwp *, char *); static int check_descs(union descriptor *, int); -int i386_extend_pcb (struct proc *); +int i386_extend_pcb(struct lwp *); /* * sysarch_args(int op, char *params) @@ -85,24 +85,24 @@ int i386_extend_pcb (struct proc *); int sysarch(struct sysarch_args *uap) { - struct proc *p = curproc; + struct lwp *lp = curthread->td_lwp; int error = 0; switch(uap->op) { case I386_GET_LDT: - error = i386_get_ldt(p, uap->parms, &uap->sysmsg_result); + error = i386_get_ldt(lp, uap->parms, &uap->sysmsg_result); break; case I386_SET_LDT: - error = i386_set_ldt(p, uap->parms, &uap->sysmsg_result); + error = i386_set_ldt(lp, uap->parms, &uap->sysmsg_result); break; case I386_GET_IOPERM: - error = i386_get_ioperm(p, uap->parms); + error = i386_get_ioperm(lp, uap->parms); break; case I386_SET_IOPERM: - error = i386_set_ioperm(p, uap->parms); + error = i386_set_ioperm(lp, uap->parms); break; case I386_VM86: - error = vm86_sysarch(p, uap->parms); + error = vm86_sysarch(lp, uap->parms); break; default: error = EOPNOTSUPP; @@ -112,7 +112,7 @@ sysarch(struct sysarch_args *uap) } int -i386_extend_pcb(struct proc *p) +i386_extend_pcb(struct lwp *lp) { int i, offset; u_long *addr; @@ -131,9 +131,9 @@ i386_extend_pcb(struct proc *p) ext = (struct pcb_ext *)kmem_alloc(kernel_map, ctob(IOPAGES+1)); if (ext == 0) return (ENOMEM); - p->p_thread->td_pcb->pcb_ext = ext; + lp->lwp_thread->td_pcb->pcb_ext = ext; bzero(ext, sizeof(struct pcb_ext)); - ext->ext_tss.tss_esp0 = (unsigned)((char *)p->p_thread->td_pcb - 16); + ext->ext_tss.tss_esp0 = (unsigned)((char *)lp->lwp_thread->td_pcb - 16); ext->ext_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); /* * The last byte of the i/o map must be followed by an 0xff byte. @@ -161,7 +161,7 @@ i386_extend_pcb(struct proc *p) } static int -i386_set_ioperm(struct proc *p, char *args) +i386_set_ioperm(struct lwp *lp, char *args) { int i, error; struct i386_ioperm_args ua; @@ -170,7 +170,7 @@ i386_set_ioperm(struct proc *p, char *args) if ((error = copyin(args, &ua, sizeof(struct i386_ioperm_args))) != 0) return (error); - if ((error = suser_cred(p->p_ucred, 0)) != 0) + if ((error = suser_cred(lp->lwp_proc->p_ucred, 0)) != 0) return (error); if (securelevel > 0) return (EPERM); @@ -181,10 +181,10 @@ i386_set_ioperm(struct proc *p, char *args) * cause confusion. This probably requires a global 'usage registry'. */ - if (p->p_thread->td_pcb->pcb_ext == 0) - if ((error = i386_extend_pcb(p)) != 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) + if ((error = i386_extend_pcb(lp)) != 0) return (error); - iomap = (char *)p->p_thread->td_pcb->pcb_ext->ext_iomap; + iomap = (char *)lp->lwp_thread->td_pcb->pcb_ext->ext_iomap; if (ua.start + ua.length > IOPAGES * PAGE_SIZE * NBBY) return (EINVAL); @@ -199,7 +199,7 @@ i386_set_ioperm(struct proc *p, char *args) } static int -i386_get_ioperm(struct proc *p, char *args) +i386_get_ioperm(struct lwp *lp, char *args) { int i, state, error; struct i386_ioperm_args ua; @@ -210,12 +210,12 @@ i386_get_ioperm(struct proc *p, char *args) if (ua.start >= IOPAGES * PAGE_SIZE * NBBY) return (EINVAL); - if (p->p_thread->td_pcb->pcb_ext == 0) { + if (lp->lwp_thread->td_pcb->pcb_ext == 0) { ua.length = 0; goto done; } - iomap = (char *)p->p_thread->td_pcb->pcb_ext->ext_iomap; + iomap = (char *)lp->lwp_thread->td_pcb->pcb_ext->ext_iomap; i = ua.start; state = (iomap[i >> 3] >> (i & 7)) & 1; @@ -344,10 +344,10 @@ user_ldt_free(struct pcb *pcb) } static int -i386_get_ldt(struct proc *p, char *args, int *res) +i386_get_ldt(struct lwp *lwp, char *args, int *res) { int error = 0; - struct pcb *pcb = p->p_thread->td_pcb; + struct pcb *pcb = lwp->lwp_thread->td_pcb; struct pcb_ldt *pcb_ldt = pcb->pcb_ldt; unsigned int nldt, num; union descriptor *lp; @@ -390,11 +390,11 @@ i386_get_ldt(struct proc *p, char *args, int *res) } static int -i386_set_ldt(struct proc *p, char *args, int *res) +i386_set_ldt(struct lwp *lp, char *args, int *res) { int error = 0; int largest_ld; - struct pcb *pcb = p->p_thread->td_pcb; + struct pcb *pcb = lp->lwp_thread->td_pcb; struct pcb_ldt *pcb_ldt = pcb->pcb_ldt; union descriptor *descs; int descs_size; diff --git a/sys/platform/pc32/i386/vm86.c b/sys/platform/pc32/i386/vm86.c index 28242fb638..fbf11e3729 100644 --- a/sys/platform/pc32/i386/vm86.c +++ b/sys/platform/pc32/i386/vm86.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/vm86.c,v 1.31.2.2 2001/10/05 06:18:55 peter Exp $ - * $DragonFly: src/sys/platform/pc32/i386/vm86.c,v 1.14 2005/07/19 19:08:03 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/vm86.c,v 1.15 2005/10/07 21:55:15 corecode Exp $ */ #include @@ -720,7 +720,7 @@ vm86_getptr(vmc, kva, sel, off) } int -vm86_sysarch(struct proc *p, char *args) +vm86_sysarch(struct lwp *lp, char *args) { int error = 0; struct i386_vm86_args ua; @@ -729,10 +729,10 @@ vm86_sysarch(struct proc *p, char *args) if ((error = copyin(args, &ua, sizeof(struct i386_vm86_args))) != 0) return (error); - if (p->p_thread->td_pcb->pcb_ext == 0) - if ((error = i386_extend_pcb(p)) != 0) + if (lp->lwp_thread->td_pcb->pcb_ext == 0) + if ((error = i386_extend_pcb(lp)) != 0) return (error); - vm86 = &p->p_thread->td_pcb->pcb_ext->ext_vm86; + vm86 = &lp->lwp_thread->td_pcb->pcb_ext->ext_vm86; switch (ua.sub_op) { case VM86_INIT: { @@ -778,7 +778,7 @@ vm86_sysarch(struct proc *p, char *args) case VM86_INTCALL: { struct vm86_intcall_args sa; - if ((error = suser_cred(p->p_ucred, 0))) + if ((error = suser_cred(lp->lwp_proc->p_ucred, 0))) return (error); if ((error = copyin(ua.sub_args, &sa, sizeof(sa)))) return (error); -- 2.41.0