1*aa91aeb3Spooka /* $NetBSD: pthread_makelwp_netbsd.c,v 1.2 2014/12/17 01:49:08 pooka Exp $ */ 2082d249aSpooka 3082d249aSpooka /*- 4082d249aSpooka * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. 5082d249aSpooka * All rights reserved. 6082d249aSpooka * 7082d249aSpooka * This code is derived from software contributed to The NetBSD Foundation 8082d249aSpooka * by Nathan J. Williams and Andrew Doran. 9082d249aSpooka * 10082d249aSpooka * Redistribution and use in source and binary forms, with or without 11082d249aSpooka * modification, are permitted provided that the following conditions 12082d249aSpooka * are met: 13082d249aSpooka * 1. Redistributions of source code must retain the above copyright 14082d249aSpooka * notice, this list of conditions and the following disclaimer. 15082d249aSpooka * 2. Redistributions in binary form must reproduce the above copyright 16082d249aSpooka * notice, this list of conditions and the following disclaimer in the 17082d249aSpooka * documentation and/or other materials provided with the distribution. 18082d249aSpooka * 19082d249aSpooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20082d249aSpooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21082d249aSpooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22082d249aSpooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23082d249aSpooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24082d249aSpooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25082d249aSpooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26082d249aSpooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27082d249aSpooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28082d249aSpooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29082d249aSpooka * POSSIBILITY OF SUCH DAMAGE. 30082d249aSpooka */ 31082d249aSpooka 32082d249aSpooka #include <sys/cdefs.h> 33*aa91aeb3Spooka __RCSID("$NetBSD: pthread_makelwp_netbsd.c,v 1.2 2014/12/17 01:49:08 pooka Exp $"); 34082d249aSpooka 35082d249aSpooka #include <sys/param.h> 36082d249aSpooka 37082d249aSpooka #include <lwp.h> 38082d249aSpooka #include <pthread.h> 39*aa91aeb3Spooka #include <string.h> 40082d249aSpooka 41082d249aSpooka #include "pthread_int.h" 42082d249aSpooka #include "pthread_makelwp.h" 43082d249aSpooka 44082d249aSpooka int 45082d249aSpooka pthread__makelwp(void (*start_routine)(void *), void *arg, void *priv, 46082d249aSpooka void *stack_base, size_t stack_size, 47082d249aSpooka unsigned long flag, lwpid_t *newlid) 48082d249aSpooka { 49082d249aSpooka ucontext_t uc; 50082d249aSpooka 51082d249aSpooka /* 52082d249aSpooka * XXX: most of the following chunk is these days 53082d249aSpooka * performed also by _lwp_makecontext(), but there may 54082d249aSpooka * be MD differences, so lug everything along for now. 55082d249aSpooka */ 56082d249aSpooka memset(&uc, 0, sizeof(uc)); 57082d249aSpooka _INITCONTEXT_U(&uc); 58082d249aSpooka uc.uc_stack.ss_sp = stack_base; 59082d249aSpooka uc.uc_stack.ss_size = stack_size; 60082d249aSpooka uc.uc_stack.ss_flags = 0; 61082d249aSpooka uc.uc_link = NULL; 62082d249aSpooka 63082d249aSpooka _lwp_makecontext(&uc, start_routine, arg, priv, stack_base, stack_size); 64082d249aSpooka return _lwp_create(&uc, flag, newlid); 65082d249aSpooka } 66