2012-09-28 00:43:15 +04:00
|
|
|
/* $NetBSD: sys_lwp.c,v 1.55 2012/09/27 20:43:15 rmind Exp $ */
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*-
|
2008-03-12 14:05:01 +03:00
|
|
|
* Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
2007-02-10 00:55:00 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Nathan J. Williams, and Andrew Doran.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lightweight process (LWP) system calls. See kern_lwp.c for a description
|
|
|
|
* of LWPs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2012-09-28 00:43:15 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.55 2012/09/27 20:43:15 rmind Exp $");
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/pool.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
#include <sys/kauth.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/sleepq.h>
|
2007-11-13 02:11:58 +03:00
|
|
|
#include <sys/lwpctl.h>
|
2009-03-29 13:24:52 +04:00
|
|
|
#include <sys/cpu.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
|
|
|
#define LWP_UNPARK_MAX 1024
|
|
|
|
|
2009-10-22 17:12:47 +04:00
|
|
|
static syncobj_t lwp_park_sobj = {
|
2007-09-07 03:58:56 +04:00
|
|
|
SOBJ_SLEEPQ_LIFO,
|
2007-02-10 00:55:00 +03:00
|
|
|
sleepq_unsleep,
|
2007-02-26 12:20:52 +03:00
|
|
|
sleepq_changepri,
|
|
|
|
sleepq_lendpri,
|
|
|
|
syncobj_noowner,
|
2007-02-10 00:55:00 +03:00
|
|
|
};
|
|
|
|
|
2009-10-22 17:12:47 +04:00
|
|
|
static sleeptab_t lwp_park_tab;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
lwp_sys_init(void)
|
|
|
|
{
|
|
|
|
sleeptab_init(&lwp_park_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-05-21 18:15:16 +04:00
|
|
|
do_lwp_create(lwp_t *l, void *arg, u_long flags, lwpid_t *new_lwp)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct lwp *l2;
|
2010-06-06 11:46:17 +04:00
|
|
|
struct schedstate_percpu *spc;
|
2007-02-10 00:55:00 +03:00
|
|
|
vaddr_t uaddr;
|
2012-05-21 18:15:16 +04:00
|
|
|
int error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/* XXX check against resource limits */
|
|
|
|
|
2009-10-22 01:11:57 +04:00
|
|
|
uaddr = uvm_uarea_alloc();
|
2012-05-21 18:15:16 +04:00
|
|
|
if (__predict_false(uaddr == 0))
|
2007-02-10 00:55:00 +03:00
|
|
|
return ENOMEM;
|
|
|
|
|
2012-05-21 18:15:16 +04:00
|
|
|
error = lwp_create(l, p, uaddr, flags & LWP_DETACHED,
|
|
|
|
NULL, 0, p->p_emul->e_startlwp, arg, &l2, l->l_class);
|
2009-10-22 01:11:57 +04:00
|
|
|
if (__predict_false(error)) {
|
|
|
|
uvm_uarea_free(uaddr);
|
2007-03-24 19:43:56 +03:00
|
|
|
return error;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2012-05-21 18:15:16 +04:00
|
|
|
*new_lwp = l2->l_lid;
|
2007-07-11 04:17:23 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Set the new LWP running, unless the caller has requested that
|
|
|
|
* it be created in suspended state. If the process is stopping,
|
|
|
|
* then the LWP is created stopped.
|
|
|
|
*/
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_lock(l2);
|
2010-06-06 11:46:17 +04:00
|
|
|
spc = &l2->l_cpu->ci_schedstate;
|
2012-05-21 18:15:16 +04:00
|
|
|
if ((flags & LWP_SUSPENDED) == 0 &&
|
2007-02-18 01:31:36 +03:00
|
|
|
(l->l_flag & (LW_WREBOOT | LW_WSUSPEND | LW_WEXIT)) == 0) {
|
2010-06-06 11:46:17 +04:00
|
|
|
if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
|
|
|
|
KASSERT(l2->l_wchan == NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
l2->l_stat = LSSTOP;
|
2010-06-13 08:13:31 +04:00
|
|
|
p->p_nrlwps--;
|
2010-06-06 11:46:17 +04:00
|
|
|
lwp_unlock_to(l2, spc->spc_lwplock);
|
|
|
|
} else {
|
|
|
|
KASSERT(lwp_locked(l2, spc->spc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
l2->l_stat = LSRUN;
|
2007-05-17 18:51:11 +04:00
|
|
|
sched_enqueue(l2, false);
|
2010-06-06 11:46:17 +04:00
|
|
|
lwp_unlock(l2);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2007-12-02 18:49:38 +03:00
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
l2->l_stat = LSSUSPENDED;
|
2010-06-13 08:13:31 +04:00
|
|
|
p->p_nrlwps--;
|
2010-06-06 11:46:17 +04:00
|
|
|
lwp_unlock_to(l2, spc->spc_lwplock);
|
2007-12-02 18:49:38 +03:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-21 18:15:16 +04:00
|
|
|
int
|
|
|
|
sys__lwp_create(struct lwp *l, const struct sys__lwp_create_args *uap,
|
|
|
|
register_t *retval)
|
|
|
|
{
|
|
|
|
/* {
|
|
|
|
syscallarg(const ucontext_t *) ucp;
|
|
|
|
syscallarg(u_long) flags;
|
|
|
|
syscallarg(lwpid_t *) new_lwp;
|
|
|
|
} */
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
ucontext_t *newuc = NULL;
|
|
|
|
lwpid_t lid;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
newuc = kmem_alloc(sizeof(ucontext_t), KM_SLEEP);
|
|
|
|
error = copyin(SCARG(uap, ucp), newuc, p->p_emul->e_ucsize);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* validate the ucontext */
|
|
|
|
if ((newuc->uc_flags & _UC_CPU) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = cpu_mcontext_validate(l, &newuc->uc_mcontext);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do not free ucontext in case of an error here,
|
|
|
|
* the lwp will actually run and access it
|
|
|
|
*/
|
|
|
|
return copyout(&lid, SCARG(uap, new_lwp), sizeof(lid));
|
|
|
|
|
|
|
|
fail:
|
|
|
|
kmem_free(newuc, sizeof(ucontext_t));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys__lwp_exit(struct lwp *l, const void *v, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
lwp_exit(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys__lwp_self(struct lwp *l, const void *v, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
*retval = l->l_lid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys__lwp_getprivate(struct lwp *l, const void *v, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
*retval = (uintptr_t)l->l_private;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_setprivate(struct lwp *l, const struct sys__lwp_setprivate_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(void *) ptr;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2010-07-07 05:30:32 +04:00
|
|
|
return lwp_setprivate(l, SCARG(uap, ptr));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_suspend(struct lwp *l, const struct sys__lwp_suspend_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct lwp *t;
|
|
|
|
int error;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((t = lwp_find(p, SCARG(uap, target))) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for deadlock, which is only possible when we're suspending
|
|
|
|
* ourself. XXX There is a short race here, as p_nrlwps is only
|
|
|
|
* incremented when an LWP suspends itself on the kernel/user
|
|
|
|
* boundary. It's still possible to kill -9 the process so we
|
|
|
|
* don't bother checking further.
|
|
|
|
*/
|
|
|
|
lwp_lock(t);
|
|
|
|
if ((t == l && p->p_nrlwps == 1) ||
|
2007-02-18 01:31:36 +03:00
|
|
|
(l->l_flag & (LW_WCORE | LW_WEXIT)) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(t);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
return EDEADLK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend the LWP. XXX If it's on a different CPU, we should wait
|
|
|
|
* for it to be preempted, where it will put itself to sleep.
|
|
|
|
*
|
|
|
|
* Suspension of the current LWP will happen on return to userspace.
|
|
|
|
*/
|
|
|
|
error = lwp_suspend(l, t);
|
2007-08-02 05:48:44 +04:00
|
|
|
if (error) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-08-02 05:48:44 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for:
|
|
|
|
* o process exiting
|
|
|
|
* o target LWP suspended
|
|
|
|
* o target LWP not suspended and L_WSUSPEND clear
|
|
|
|
* o target LWP exited
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2008-04-24 22:39:20 +04:00
|
|
|
error = cv_wait_sig(&p->p_lwpcv, p->p_lock);
|
2007-08-02 05:48:44 +04:00
|
|
|
if (error) {
|
|
|
|
error = ERESTART;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-15 06:50:40 +04:00
|
|
|
if (lwp_find(p, SCARG(uap, target)) == NULL) {
|
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-02 05:48:44 +04:00
|
|
|
if ((l->l_flag | t->l_flag) & (LW_WCORE | LW_WEXIT)) {
|
|
|
|
error = ERESTART;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (t->l_stat == LSSUSPENDED ||
|
|
|
|
(t->l_flag & LW_WSUSPEND) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_continue(struct lwp *l, const struct sys__lwp_continue_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
int error;
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct lwp *t;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((t = lwp_find(p, SCARG(uap, target))) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
lwp_lock(t);
|
|
|
|
lwp_continue(t);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_wakeup(struct lwp *l, const struct sys__lwp_wakeup_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *t;
|
|
|
|
struct proc *p;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
p = l->l_proc;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if ((t = lwp_find(p, SCARG(uap, target))) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
lwp_lock(t);
|
2007-03-15 02:58:24 +03:00
|
|
|
t->l_flag |= (LW_CANCELLED | LW_UNPARKED);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (t->l_stat != LSSLEEP) {
|
2007-03-21 02:25:17 +03:00
|
|
|
lwp_unlock(t);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ENODEV;
|
2007-03-21 02:25:17 +03:00
|
|
|
} else if ((t->l_flag & LW_SINTR) == 0) {
|
|
|
|
lwp_unlock(t);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EBUSY;
|
2007-03-21 02:25:17 +03:00
|
|
|
} else {
|
|
|
|
/* Wake it up. lwp_unsleep() will release the LWP lock. */
|
2009-10-22 01:11:57 +04:00
|
|
|
lwp_unsleep(t, true);
|
2007-03-21 02:25:17 +03:00
|
|
|
error = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_wait(struct lwp *l, const struct sys__lwp_wait_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) wait_for;
|
|
|
|
syscallarg(lwpid_t *) departed;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
int error;
|
|
|
|
lwpid_t dep;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2012-09-28 00:43:15 +04:00
|
|
|
error = lwp_wait(l, SCARG(uap, wait_for), &dep, false);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2012-09-28 00:43:15 +04:00
|
|
|
if (!error && SCARG(uap, departed)) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = copyout(&dep, SCARG(uap, departed), sizeof(dep));
|
|
|
|
}
|
|
|
|
|
2012-09-28 00:43:15 +04:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_kill(struct lwp *l, const struct sys__lwp_kill_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
|
|
|
syscallarg(int) signo;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct lwp *t;
|
|
|
|
ksiginfo_t ksi;
|
|
|
|
int signo = SCARG(uap, signo);
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if ((u_int)signo >= NSIG)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
KSI_INIT(&ksi);
|
|
|
|
ksi.ksi_signo = signo;
|
2008-10-16 12:47:07 +04:00
|
|
|
ksi.ksi_code = SI_LWP;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi.ksi_pid = p->p_pid;
|
|
|
|
ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
|
|
|
|
ksi.ksi_lid = SCARG(uap, target);
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((t = lwp_find(p, ksi.ksi_lid)) == NULL)
|
|
|
|
error = ESRCH;
|
|
|
|
else if (signo != 0)
|
|
|
|
kpsignal2(p, &ksi);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_detach(struct lwp *l, const struct sys__lwp_detach_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct lwp *t;
|
|
|
|
lwpid_t target;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
target = SCARG(uap, target);
|
|
|
|
p = l->l_proc;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (l->l_lid == target)
|
|
|
|
t = l;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We can't use lwp_find() here because the target might
|
|
|
|
* be a zombie.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(t, &p->p_lwps, l_sibling)
|
|
|
|
if (t->l_lid == target)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the LWP is already detached, there's nothing to do.
|
|
|
|
* If it's a zombie, we need to clean up after it. LSZOMB
|
|
|
|
* is visible with the proc mutex held.
|
|
|
|
*
|
|
|
|
* After we have detached or released the LWP, kick any
|
|
|
|
* other LWPs that may be sitting in _lwp_wait(), waiting
|
|
|
|
* for the target LWP to exit.
|
|
|
|
*/
|
|
|
|
if (t != NULL && t->l_stat != LSIDL) {
|
|
|
|
if ((t->l_prflag & LPR_DETACHED) == 0) {
|
|
|
|
p->p_ndlwps++;
|
|
|
|
t->l_prflag |= LPR_DETACHED;
|
|
|
|
if (t->l_stat == LSZOMB) {
|
2007-03-21 21:25:59 +03:00
|
|
|
/* Releases proc mutex. */
|
|
|
|
lwp_free(t, false, false);
|
2007-02-10 00:55:00 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
error = 0;
|
2007-03-21 21:25:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Have any LWPs sleeping in lwp_wait() recheck
|
|
|
|
* for deadlock.
|
|
|
|
*/
|
|
|
|
cv_broadcast(&p->p_lwpcv);
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
} else
|
|
|
|
error = ESRCH;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline wchan_t
|
|
|
|
lwp_park_wchan(struct proc *p, const void *hint)
|
|
|
|
{
|
2007-08-02 03:24:26 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return (wchan_t)((uintptr_t)p ^ (uintptr_t)hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-07 23:00:42 +04:00
|
|
|
lwp_unpark(lwpid_t target, const void *hint)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-08-07 23:00:42 +04:00
|
|
|
sleepq_t *sq;
|
|
|
|
wchan_t wchan;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2007-08-07 23:00:42 +04:00
|
|
|
proc_t *p;
|
|
|
|
lwp_t *t;
|
2007-06-03 13:50:12 +04:00
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
/*
|
|
|
|
* Easy case: search for the LWP on the sleep queue. If
|
|
|
|
* it's parked, remove it from the queue and set running.
|
|
|
|
*/
|
|
|
|
p = curproc;
|
|
|
|
wchan = lwp_park_wchan(p, hint);
|
2008-05-26 16:08:38 +04:00
|
|
|
sq = sleeptab_lookup(&lwp_park_tab, wchan, &mp);
|
2007-06-03 13:50:12 +04:00
|
|
|
|
2008-05-26 16:08:38 +04:00
|
|
|
TAILQ_FOREACH(t, sq, l_sleepchain)
|
2007-08-07 23:00:42 +04:00
|
|
|
if (t->l_proc == p && t->l_lid == target)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (__predict_true(t != NULL)) {
|
2009-10-22 01:11:57 +04:00
|
|
|
sleepq_remove(sq, t);
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_exit(mp);
|
2007-08-07 23:00:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The LWP hasn't parked yet. Take the hit and mark the
|
|
|
|
* operation as pending.
|
|
|
|
*/
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_exit(mp);
|
2007-08-07 23:00:42 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-08-07 23:00:42 +04:00
|
|
|
if ((t = lwp_find(p, target)) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-08-07 23:00:42 +04:00
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It may not have parked yet, we may have raced, or it
|
|
|
|
* is parked on a different user sync object.
|
|
|
|
*/
|
|
|
|
lwp_lock(t);
|
|
|
|
if (t->l_syncobj == &lwp_park_sobj) {
|
|
|
|
/* Releases the LWP lock. */
|
2009-10-22 01:11:57 +04:00
|
|
|
lwp_unsleep(t, true);
|
2007-08-07 23:00:42 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set the operation pending. The next call to _lwp_park
|
|
|
|
* will return early.
|
|
|
|
*/
|
|
|
|
t->l_flag |= LW_UNPARKED;
|
|
|
|
lwp_unlock(t);
|
|
|
|
}
|
2007-06-03 13:50:12 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-08-07 23:00:42 +04:00
|
|
|
return 0;
|
2007-06-03 13:50:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-07 23:00:42 +04:00
|
|
|
lwp_park(struct timespec *ts, const void *hint)
|
2007-06-03 13:50:12 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
sleepq_t *sq;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2007-02-10 00:55:00 +03:00
|
|
|
wchan_t wchan;
|
|
|
|
int timo, error;
|
2007-08-07 23:00:42 +04:00
|
|
|
lwp_t *l;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/* Fix up the given timeout value. */
|
2007-06-03 13:50:12 +04:00
|
|
|
if (ts != NULL) {
|
2009-11-02 00:46:09 +03:00
|
|
|
error = abstimeout2timo(ts, &timo);
|
|
|
|
if (error) {
|
2007-02-10 00:55:00 +03:00
|
|
|
return error;
|
2009-11-02 00:46:09 +03:00
|
|
|
}
|
2007-08-07 23:00:42 +04:00
|
|
|
KASSERT(timo != 0);
|
2009-11-02 00:46:09 +03:00
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
timo = 0;
|
2009-11-02 00:46:09 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/* Find and lock the sleep queue. */
|
2007-08-07 23:00:42 +04:00
|
|
|
l = curlwp;
|
2007-06-03 13:50:12 +04:00
|
|
|
wchan = lwp_park_wchan(l->l_proc, hint);
|
2008-05-26 16:08:38 +04:00
|
|
|
sq = sleeptab_lookup(&lwp_park_tab, wchan, &mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Before going the full route and blocking, check to see if an
|
|
|
|
* unpark op is pending.
|
|
|
|
*/
|
2007-05-17 18:51:11 +04:00
|
|
|
lwp_lock(l);
|
2007-03-01 17:55:06 +03:00
|
|
|
if ((l->l_flag & (LW_CANCELLED | LW_UNPARKED)) != 0) {
|
|
|
|
l->l_flag &= ~(LW_CANCELLED | LW_UNPARKED);
|
2007-05-17 18:51:11 +04:00
|
|
|
lwp_unlock(l);
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_exit(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
return EALREADY;
|
|
|
|
}
|
2008-05-26 16:08:38 +04:00
|
|
|
lwp_unlock_to(l, mp);
|
2007-08-07 23:00:42 +04:00
|
|
|
l->l_biglocks = 0;
|
2007-11-06 03:42:39 +03:00
|
|
|
sleepq_enqueue(sq, wchan, "parked", &lwp_park_sobj);
|
2007-05-17 18:51:11 +04:00
|
|
|
error = sleepq_block(timo, true);
|
2007-03-15 02:00:32 +03:00
|
|
|
switch (error) {
|
2007-03-15 02:07:27 +03:00
|
|
|
case EWOULDBLOCK:
|
|
|
|
error = ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
case ERESTART:
|
|
|
|
error = EINTR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* nothing */
|
|
|
|
break;
|
2007-03-15 02:00:32 +03:00
|
|
|
}
|
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
/*
|
|
|
|
* 'park' an LWP waiting on a user-level synchronisation object. The LWP
|
|
|
|
* will remain parked until another LWP in the same process calls in and
|
|
|
|
* requests that it be unparked.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
int
|
2009-01-11 05:45:45 +03:00
|
|
|
sys____lwp_park50(struct lwp *l, const struct sys____lwp_park50_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-08-07 23:00:42 +04:00
|
|
|
syscallarg(const struct timespec *) ts;
|
|
|
|
syscallarg(lwpid_t) unpark;
|
|
|
|
syscallarg(const void *) hint;
|
|
|
|
syscallarg(const void *) unparkhint;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-08-07 23:00:42 +04:00
|
|
|
struct timespec ts, *tsp;
|
|
|
|
int error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
if (SCARG(uap, ts) == NULL)
|
|
|
|
tsp = NULL;
|
|
|
|
else {
|
|
|
|
error = copyin(SCARG(uap, ts), &ts, sizeof(ts));
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
tsp = &ts;
|
2007-03-15 02:58:24 +03:00
|
|
|
}
|
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
if (SCARG(uap, unpark) != 0) {
|
|
|
|
error = lwp_unpark(SCARG(uap, unpark), SCARG(uap, unparkhint));
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
2007-03-15 02:58:24 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
return lwp_park(tsp, SCARG(uap, hint));
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-08-07 23:00:42 +04:00
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_unpark(struct lwp *l, const struct sys__lwp_unpark_args *uap,
|
|
|
|
register_t *retval)
|
2007-08-07 23:00:42 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-08-07 23:00:42 +04:00
|
|
|
syscallarg(lwpid_t) target;
|
|
|
|
syscallarg(const void *) hint;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-08-07 23:00:42 +04:00
|
|
|
|
|
|
|
return lwp_unpark(SCARG(uap, target), SCARG(uap, hint));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_unpark_all(struct lwp *l, const struct sys__lwp_unpark_all_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(const lwpid_t *) targets;
|
|
|
|
syscallarg(size_t) ntargets;
|
|
|
|
syscallarg(const void *) hint;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct lwp *t;
|
|
|
|
sleepq_t *sq;
|
|
|
|
wchan_t wchan;
|
|
|
|
lwpid_t targets[32], *tp, *tpp, *tmax, target;
|
2009-10-22 01:11:57 +04:00
|
|
|
int error;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2007-03-15 02:58:24 +03:00
|
|
|
u_int ntargets;
|
2007-02-10 00:55:00 +03:00
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
p = l->l_proc;
|
|
|
|
ntargets = SCARG(uap, ntargets);
|
|
|
|
|
|
|
|
if (SCARG(uap, targets) == NULL) {
|
|
|
|
/*
|
|
|
|
* Let the caller know how much we are willing to do, and
|
|
|
|
* let it unpark the LWPs in blocks.
|
|
|
|
*/
|
|
|
|
*retval = LWP_UNPARK_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ntargets > LWP_UNPARK_MAX || ntargets == 0)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy in the target array. If it's a small number of LWPs, then
|
|
|
|
* place the numbers on the stack.
|
|
|
|
*/
|
|
|
|
sz = sizeof(target) * ntargets;
|
|
|
|
if (sz <= sizeof(targets))
|
|
|
|
tp = targets;
|
|
|
|
else {
|
|
|
|
tp = kmem_alloc(sz, KM_SLEEP);
|
|
|
|
if (tp == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
error = copyin(SCARG(uap, targets), tp, sz);
|
|
|
|
if (error != 0) {
|
|
|
|
if (tp != targets) {
|
|
|
|
kmem_free(tp, sz);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
wchan = lwp_park_wchan(p, SCARG(uap, hint));
|
2008-05-26 16:08:38 +04:00
|
|
|
sq = sleeptab_lookup(&lwp_park_tab, wchan, &mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
for (tmax = tp + ntargets, tpp = tp; tpp < tmax; tpp++) {
|
|
|
|
target = *tpp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Easy case: search for the LWP on the sleep queue. If
|
|
|
|
* it's parked, remove it from the queue and set running.
|
|
|
|
*/
|
2008-05-26 16:08:38 +04:00
|
|
|
TAILQ_FOREACH(t, sq, l_sleepchain)
|
2007-02-10 00:55:00 +03:00
|
|
|
if (t->l_proc == p && t->l_lid == target)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (t != NULL) {
|
2009-10-22 01:11:57 +04:00
|
|
|
sleepq_remove(sq, t);
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The LWP hasn't parked yet. Take the hit and
|
|
|
|
* mark the operation as pending.
|
|
|
|
*/
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_exit(mp);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((t = lwp_find(p, target)) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_enter(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lwp_lock(t);
|
|
|
|
|
2007-03-15 02:58:24 +03:00
|
|
|
/*
|
|
|
|
* It may not have parked yet, we may have raced, or
|
|
|
|
* it is parked on a different user sync object.
|
|
|
|
*/
|
|
|
|
if (t->l_syncobj == &lwp_park_sobj) {
|
|
|
|
/* Releases the LWP lock. */
|
2009-10-22 01:11:57 +04:00
|
|
|
lwp_unsleep(t, true);
|
2007-02-10 00:55:00 +03:00
|
|
|
} else {
|
|
|
|
/*
|
2007-03-15 02:58:24 +03:00
|
|
|
* Set the operation pending. The next call to
|
|
|
|
* _lwp_park will return early.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2007-03-01 17:55:06 +03:00
|
|
|
t->l_flag |= LW_UNPARKED;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(t);
|
|
|
|
}
|
2007-03-15 02:58:24 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_enter(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2008-05-26 16:08:38 +04:00
|
|
|
mutex_spin_exit(mp);
|
2008-01-02 14:48:20 +03:00
|
|
|
if (tp != targets)
|
2007-02-10 00:55:00 +03:00
|
|
|
kmem_free(tp, sz);
|
2007-03-15 02:58:24 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2007-11-07 03:37:21 +03:00
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_setname(struct lwp *l, const struct sys__lwp_setname_args *uap,
|
|
|
|
register_t *retval)
|
2007-11-07 03:37:21 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-11-07 03:37:21 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
|
|
|
syscallarg(const char *) name;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-11-07 03:37:21 +03:00
|
|
|
char *name, *oname;
|
2007-11-13 02:11:58 +03:00
|
|
|
lwpid_t target;
|
2007-11-07 03:37:21 +03:00
|
|
|
proc_t *p;
|
|
|
|
lwp_t *t;
|
|
|
|
int error;
|
|
|
|
|
2007-11-13 02:11:58 +03:00
|
|
|
if ((target = SCARG(uap, target)) == 0)
|
|
|
|
target = l->l_lid;
|
|
|
|
|
2007-11-07 03:37:21 +03:00
|
|
|
name = kmem_alloc(MAXCOMLEN, KM_SLEEP);
|
|
|
|
if (name == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
error = copyinstr(SCARG(uap, name), name, MAXCOMLEN, NULL);
|
|
|
|
switch (error) {
|
|
|
|
case ENAMETOOLONG:
|
|
|
|
case 0:
|
|
|
|
name[MAXCOMLEN - 1] = '\0';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
kmem_free(name, MAXCOMLEN);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = curproc;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-11-13 02:11:58 +03:00
|
|
|
if ((t = lwp_find(p, target)) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-11-07 03:37:21 +03:00
|
|
|
kmem_free(name, MAXCOMLEN);
|
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
lwp_lock(t);
|
|
|
|
oname = t->l_name;
|
|
|
|
t->l_name = name;
|
|
|
|
lwp_unlock(t);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-11-07 03:37:21 +03:00
|
|
|
|
|
|
|
if (oname != NULL)
|
|
|
|
kmem_free(oname, MAXCOMLEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_getname(struct lwp *l, const struct sys__lwp_getname_args *uap,
|
|
|
|
register_t *retval)
|
2007-11-07 03:37:21 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-11-07 03:37:21 +03:00
|
|
|
syscallarg(lwpid_t) target;
|
|
|
|
syscallarg(char *) name;
|
|
|
|
syscallarg(size_t) len;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-11-07 03:37:21 +03:00
|
|
|
char name[MAXCOMLEN];
|
2007-11-13 02:11:58 +03:00
|
|
|
lwpid_t target;
|
2007-11-07 03:37:21 +03:00
|
|
|
proc_t *p;
|
|
|
|
lwp_t *t;
|
|
|
|
|
2007-11-13 02:11:58 +03:00
|
|
|
if ((target = SCARG(uap, target)) == 0)
|
|
|
|
target = l->l_lid;
|
|
|
|
|
2007-11-07 03:37:21 +03:00
|
|
|
p = curproc;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-11-13 02:11:58 +03:00
|
|
|
if ((t = lwp_find(p, target)) == NULL) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-11-07 03:37:21 +03:00
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
lwp_lock(t);
|
|
|
|
if (t->l_name == NULL)
|
|
|
|
name[0] = '\0';
|
|
|
|
else
|
|
|
|
strcpy(name, t->l_name);
|
|
|
|
lwp_unlock(t);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-11-07 03:37:21 +03:00
|
|
|
|
|
|
|
return copyoutstr(name, SCARG(uap, name), SCARG(uap, len), NULL);
|
|
|
|
}
|
2007-11-13 02:11:58 +03:00
|
|
|
|
|
|
|
int
|
2009-10-22 17:12:47 +04:00
|
|
|
sys__lwp_ctl(struct lwp *l, const struct sys__lwp_ctl_args *uap,
|
|
|
|
register_t *retval)
|
2007-11-13 02:11:58 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-11-13 02:11:58 +03:00
|
|
|
syscallarg(int) features;
|
|
|
|
syscallarg(struct lwpctl **) address;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-11-13 02:11:58 +03:00
|
|
|
int error, features;
|
|
|
|
vaddr_t vaddr;
|
|
|
|
|
|
|
|
features = SCARG(uap, features);
|
2008-03-12 14:00:43 +03:00
|
|
|
features &= ~(LWPCTL_FEATURE_CURCPU | LWPCTL_FEATURE_PCTR);
|
|
|
|
if (features != 0)
|
2007-11-13 02:11:58 +03:00
|
|
|
return ENODEV;
|
|
|
|
if ((error = lwp_ctl_alloc(&vaddr)) != 0)
|
|
|
|
return error;
|
|
|
|
return copyout(&vaddr, SCARG(uap, address), sizeof(void *));
|
|
|
|
}
|