1*7adb4107Sriastradh /* $NetBSD: pthread_makelwp_netbsd.c,v 1.3 2022/02/12 14:59:32 riastradh 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*7adb4107Sriastradh __RCSID("$NetBSD: pthread_makelwp_netbsd.c,v 1.3 2022/02/12 14:59:32 riastradh Exp $");
34*7adb4107Sriastradh
35*7adb4107Sriastradh /* Need to use libc-private names for atomic operations. */
36*7adb4107Sriastradh #include "../../common/lib/libc/atomic/atomic_op_namespace.h"
37082d249aSpooka
38082d249aSpooka #include <sys/param.h>
39082d249aSpooka
40082d249aSpooka #include <lwp.h>
41082d249aSpooka #include <pthread.h>
42aa91aeb3Spooka #include <string.h>
43082d249aSpooka
44082d249aSpooka #include "pthread_int.h"
45082d249aSpooka #include "pthread_makelwp.h"
46082d249aSpooka
47082d249aSpooka int
pthread__makelwp(void (* start_routine)(void *),void * arg,void * priv,void * stack_base,size_t stack_size,unsigned long flag,lwpid_t * newlid)48082d249aSpooka pthread__makelwp(void (*start_routine)(void *), void *arg, void *priv,
49082d249aSpooka void *stack_base, size_t stack_size,
50082d249aSpooka unsigned long flag, lwpid_t *newlid)
51082d249aSpooka {
52082d249aSpooka ucontext_t uc;
53082d249aSpooka
54082d249aSpooka /*
55082d249aSpooka * XXX: most of the following chunk is these days
56082d249aSpooka * performed also by _lwp_makecontext(), but there may
57082d249aSpooka * be MD differences, so lug everything along for now.
58082d249aSpooka */
59082d249aSpooka memset(&uc, 0, sizeof(uc));
60082d249aSpooka _INITCONTEXT_U(&uc);
61082d249aSpooka uc.uc_stack.ss_sp = stack_base;
62082d249aSpooka uc.uc_stack.ss_size = stack_size;
63082d249aSpooka uc.uc_stack.ss_flags = 0;
64082d249aSpooka uc.uc_link = NULL;
65082d249aSpooka
66082d249aSpooka _lwp_makecontext(&uc, start_routine, arg, priv, stack_base, stack_size);
67082d249aSpooka return _lwp_create(&uc, flag, newlid);
68082d249aSpooka }
69