lwp_create.c revision 2c5124a1a74b6e8fcb1cf8eb9a8d46b5a583086f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
#include <sys/sysmacros.h>
#include <sys/processor.h>
#include <sys/ucontext.h>
/*
* System call to create an lwp.
*
* Notes on the LWP_DETACHED and LWP_DAEMON flags:
*
* A detached lwp (LWP_DETACHED) cannot be the specific target of
* lwp_wait() (it is not joinable), but lwp_wait(0, ...) is required
* to sleep until all non-daemon detached lwps have terminated before
* returning EDEADLK because a detached lwp might create a non-detached lwp
* that could then be returned by lwp_wait(0, ...). See also lwp_detach().
*
* A daemon lwp (LWP_DAEMON) is a detached lwp that has the additional
* property that it does not affect the termination condition of the
* process: The last non-daemon lwp to call lwp_exit() causes the process
* to exit and lwp_wait(0, ...) does not sleep waiting for daemon lwps
* to terminate. See the block comment before lwp_wait().
*/
int
{
kthread_t *t;
#ifdef _SYSCALL32_IMPL
#endif /* _SYSCALL32_IMPL */
int tid;
/*
* lwp_create() is disallowed for the /proc agent lwp.
*/
if (model == DATAMODEL_NATIVE) {
#if defined(__i386)
/*
* libc stashed thrptr into unused kernel %sp.
* See setup_context() in libc.
*/
#endif
}
#ifdef _SYSCALL32_IMPL
else {
#if defined(__sparc)
#else /* __amd64 */
/*
* libc stashed thrptr into unused kernel %sp.
* See setup_context() in libc.
*/
#endif
}
#endif /* _SYSCALL32_IMPL */
/*
* Tell machine specific code that we are creating a new lwp
*/
(void) save_syscall_args(); /* save args for tracing first */
/*
* Copy the new lwp's lwpid into the caller's specified buffer.
*/
/*
* caller's buffer is not writable, return
* EFAULT, and terminate new lwp.
*/
mutex_enter(&p->p_lock);
t->t_proc_flag |= TP_EXITLWP;
t->t_sig_check = 1;
t->t_sysnum = 0;
t->t_proc_flag &= ~TP_HOLDLWP;
lwp_create_done(t);
mutex_exit(&p->p_lock);
}
/*
* clone callers context, if any. must be invoked
* while -not- holding p_lock.
*/
lwp_createctx(curthread, t);
/*
* copy current contract templates
*/
mutex_enter(&p->p_lock);
/*
* Copy the syscall arguments to the new lwp's arg area
* for the benefit of debuggers.
*/
t->t_sysnum = SYS_lwp_create;
t->t_proc_flag |= TP_TWAIT;
if (flags & LWP_DAEMON) {
t->t_proc_flag |= TP_DAEMON;
p->p_lwpdaemon++;
}
/*
* We now set the newly-created lwp running.
* If it is being created as LWP_SUSPENDED, we leave its
* TP_HOLDLWP flag set so it will stop in system call exit.
*/
if (!(flags & LWP_SUSPENDED))
t->t_proc_flag &= ~TP_HOLDLWP;
lwp_create_done(t);
mutex_exit(&p->p_lock);
return (tid);
}
/*
* Exit the calling lwp
*/
void
{
mutex_enter(&p->p_lock);
lwp_exit();
/* NOTREACHED */
}