1*7adb4107Sriastradh /* $NetBSD: pthread_compat.c,v 1.7 2022/02/12 14:59:32 riastradh Exp $ */
2844fcfc9Sad
3844fcfc9Sad /*-
4844fcfc9Sad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5844fcfc9Sad * All rights reserved.
6844fcfc9Sad *
7844fcfc9Sad * This code is derived from software developed for The NetBSD Foundation
8844fcfc9Sad * by Andrew Doran.
9844fcfc9Sad *
10844fcfc9Sad * Redistribution and use in source and binary forms, with or without
11844fcfc9Sad * modification, are permitted provided that the following conditions
12844fcfc9Sad * are met:
13844fcfc9Sad * 1. Redistributions of source code must retain the above copyright
14844fcfc9Sad * notice, this list of conditions and the following disclaimer.
15844fcfc9Sad * 2. Redistributions in binary form must reproduce the above copyright
16844fcfc9Sad * notice, this list of conditions and the following disclaimer in the
17844fcfc9Sad * documentation and/or other materials provided with the distribution.
18844fcfc9Sad *
19844fcfc9Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20844fcfc9Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21844fcfc9Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22844fcfc9Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23844fcfc9Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24844fcfc9Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25844fcfc9Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26844fcfc9Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27844fcfc9Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28844fcfc9Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29844fcfc9Sad * POSSIBILITY OF SUCH DAMAGE.
30844fcfc9Sad */
31844fcfc9Sad
32fdc51b51Sad /*
33fdc51b51Sad * libc symbols that are not present before NetBSD 5.0.
34fdc51b51Sad */
35fdc51b51Sad
36844fcfc9Sad #include <sys/cdefs.h>
37*7adb4107Sriastradh __RCSID("$NetBSD: pthread_compat.c,v 1.7 2022/02/12 14:59:32 riastradh Exp $");
38*7adb4107Sriastradh
39*7adb4107Sriastradh /* Need to use libc-private names for atomic operations. */
40*7adb4107Sriastradh #include "../../common/lib/libc/atomic/atomic_op_namespace.h"
41844fcfc9Sad
42844fcfc9Sad #include <sys/param.h>
43844fcfc9Sad #include <sys/syscall.h>
44fdc51b51Sad #include <sys/aio.h>
45844fcfc9Sad
46844fcfc9Sad #include <lwp.h>
47844fcfc9Sad #include <unistd.h>
48844fcfc9Sad #include <sched.h>
49844fcfc9Sad
50844fcfc9Sad #include "pthread.h"
51844fcfc9Sad #include "pthread_int.h"
52844fcfc9Sad
53844fcfc9Sad static void __pthread_init(void) __attribute__((__constructor__, __used__));
54844fcfc9Sad
55844fcfc9Sad void __libc_thr_init(void);
56844fcfc9Sad void __libc_atomic_init(void);
57fdc51b51Sad
58844fcfc9Sad int _sys_sched_yield(void);
59fdc51b51Sad int _sys_aio_suspend(const struct aiocb * const[], int,
60fdc51b51Sad const struct timespec *);
61fdc51b51Sad int _sys_mq_send(mqd_t, const char *, size_t, unsigned);
62fdc51b51Sad ssize_t _sys_mq_receive(mqd_t, char *, size_t, unsigned *);
63fdc51b51Sad int _sys_mq_timedsend(mqd_t, const char *, size_t, unsigned,
64fdc51b51Sad const struct timespec *);
65fdc51b51Sad ssize_t _sys_mq_timedreceive(mqd_t, char *, size_t, unsigned *,
66fdc51b51Sad const struct timespec *);
67844fcfc9Sad
68844fcfc9Sad static void
__pthread_init(void)69844fcfc9Sad __pthread_init(void)
70844fcfc9Sad {
71844fcfc9Sad
72844fcfc9Sad __libc_atomic_init();
73fdc51b51Sad __libc_thr_init();
74844fcfc9Sad }
75844fcfc9Sad
76844fcfc9Sad int
_lwp_kill(lwpid_t a,int b)77844fcfc9Sad _lwp_kill(lwpid_t a, int b)
78844fcfc9Sad {
79844fcfc9Sad
80844fcfc9Sad return syscall(SYS__lwp_kill, a, b);
81844fcfc9Sad }
82844fcfc9Sad
83844fcfc9Sad int
_lwp_detach(lwpid_t a)84844fcfc9Sad _lwp_detach(lwpid_t a)
85844fcfc9Sad {
86844fcfc9Sad
87844fcfc9Sad return syscall(SYS__lwp_detach, a);
88844fcfc9Sad }
89844fcfc9Sad
90844fcfc9Sad int
_lwp_park(clockid_t a,int b,const struct timespec * c,lwpid_t d,const void * e,const void * f)91cdce479aSchristos _lwp_park(clockid_t a, int b, const struct timespec *c, lwpid_t d,
92cdce479aSchristos const void *e, const void *f)
93844fcfc9Sad {
94844fcfc9Sad
9593e0a207Skre return syscall(SYS____lwp_park60, a, b, c, d, e, f);
96844fcfc9Sad }
97844fcfc9Sad
98844fcfc9Sad int
_lwp_unpark(lwpid_t a,const void * b)99844fcfc9Sad _lwp_unpark(lwpid_t a, const void *b)
100844fcfc9Sad {
101844fcfc9Sad
102844fcfc9Sad return syscall(SYS__lwp_unpark, a, b);
103844fcfc9Sad }
104844fcfc9Sad
105844fcfc9Sad ssize_t
_lwp_unpark_all(const lwpid_t * a,size_t b,const void * c)106844fcfc9Sad _lwp_unpark_all(const lwpid_t *a, size_t b, const void *c)
107844fcfc9Sad {
108844fcfc9Sad
109fdc51b51Sad return (ssize_t)syscall(SYS__lwp_unpark_all, a, b, c);
110844fcfc9Sad }
111844fcfc9Sad
112844fcfc9Sad int
_lwp_setname(lwpid_t a,const char * b)113844fcfc9Sad _lwp_setname(lwpid_t a, const char *b)
114844fcfc9Sad {
115844fcfc9Sad
116844fcfc9Sad return syscall(SYS__lwp_setname, a, b);
117844fcfc9Sad }
118844fcfc9Sad
119844fcfc9Sad int
_lwp_getname(lwpid_t a,char * b,size_t c)120844fcfc9Sad _lwp_getname(lwpid_t a, char *b, size_t c)
121844fcfc9Sad {
122844fcfc9Sad
123844fcfc9Sad return syscall(SYS__lwp_getname, a, b, c);
124844fcfc9Sad }
125844fcfc9Sad
126844fcfc9Sad int
_lwp_ctl(int a,struct lwpctl ** b)127844fcfc9Sad _lwp_ctl(int a, struct lwpctl **b)
128844fcfc9Sad {
129844fcfc9Sad
130844fcfc9Sad return syscall(SYS__lwp_ctl, a, b);
131844fcfc9Sad }
132844fcfc9Sad
133844fcfc9Sad int
_sys_sched_yield(void)134844fcfc9Sad _sys_sched_yield(void)
135844fcfc9Sad {
136844fcfc9Sad
137844fcfc9Sad return syscall(SYS_sched_yield);
138844fcfc9Sad }
139844fcfc9Sad
140844fcfc9Sad int
sched_yield(void)141844fcfc9Sad sched_yield(void)
142844fcfc9Sad {
143844fcfc9Sad
144844fcfc9Sad return syscall(SYS_sched_yield);
145844fcfc9Sad }
146844fcfc9Sad
147844fcfc9Sad int
_sched_setaffinity(pid_t a,lwpid_t b,size_t c,const cpuset_t * d)148844fcfc9Sad _sched_setaffinity(pid_t a, lwpid_t b, size_t c, const cpuset_t *d)
149844fcfc9Sad {
150844fcfc9Sad
151844fcfc9Sad return syscall(SYS__sched_setaffinity, a, b, c, d);
152844fcfc9Sad }
153844fcfc9Sad
154844fcfc9Sad int
_sched_getaffinity(pid_t a,lwpid_t b,size_t c,cpuset_t * d)155844fcfc9Sad _sched_getaffinity(pid_t a, lwpid_t b, size_t c, cpuset_t *d)
156844fcfc9Sad {
157844fcfc9Sad
158844fcfc9Sad return syscall(SYS__sched_getaffinity, a, b, c, d);
159844fcfc9Sad }
160844fcfc9Sad
161844fcfc9Sad int
_sched_setparam(pid_t a,lwpid_t b,int c,const struct sched_param * d)162844fcfc9Sad _sched_setparam(pid_t a, lwpid_t b, int c, const struct sched_param *d)
163844fcfc9Sad {
164844fcfc9Sad
165844fcfc9Sad return syscall(SYS__sched_setparam, a, b, c, d);
166844fcfc9Sad }
167844fcfc9Sad
168844fcfc9Sad int
_sched_getparam(pid_t a,lwpid_t b,int * c,struct sched_param * d)169844fcfc9Sad _sched_getparam(pid_t a, lwpid_t b, int *c, struct sched_param *d)
170844fcfc9Sad {
171844fcfc9Sad
172844fcfc9Sad return syscall(SYS__sched_getparam, a, b, c, d);
173844fcfc9Sad }
174fdc51b51Sad
175fdc51b51Sad int
_sys_aio_suspend(const struct aiocb * const a[],int b,const struct timespec * c)176fdc51b51Sad _sys_aio_suspend(const struct aiocb * const a[], int b,
177fdc51b51Sad const struct timespec *c)
178fdc51b51Sad {
179fdc51b51Sad
180fdc51b51Sad return syscall(SYS_aio_suspend, a, b, c);
181fdc51b51Sad }
182fdc51b51Sad
183fdc51b51Sad int
_sys_mq_send(mqd_t a,const char * b,size_t c,unsigned d)184fdc51b51Sad _sys_mq_send(mqd_t a, const char *b, size_t c, unsigned d)
185fdc51b51Sad {
186fdc51b51Sad
187fdc51b51Sad return syscall(SYS_mq_send, a, b, c, d);
188fdc51b51Sad }
189fdc51b51Sad
190fdc51b51Sad ssize_t
_sys_mq_receive(mqd_t a,char * b,size_t c,unsigned * d)191fdc51b51Sad _sys_mq_receive(mqd_t a, char *b, size_t c, unsigned *d)
192fdc51b51Sad {
193fdc51b51Sad
194fdc51b51Sad return (ssize_t)syscall(SYS_mq_receive, a, b, c, d);
195fdc51b51Sad }
196fdc51b51Sad
197fdc51b51Sad int
_sys_mq_timedsend(mqd_t a,const char * b,size_t c,unsigned d,const struct timespec * e)198fdc51b51Sad _sys_mq_timedsend(mqd_t a, const char *b, size_t c, unsigned d,
199fdc51b51Sad const struct timespec *e)
200fdc51b51Sad {
201fdc51b51Sad
202fdc51b51Sad return syscall(SYS_mq_timedsend, a, b,c ,d, e);
203fdc51b51Sad }
204fdc51b51Sad
205fdc51b51Sad ssize_t
_sys_mq_timedreceive(mqd_t a,char * b,size_t c,unsigned * d,const struct timespec * e)206fdc51b51Sad _sys_mq_timedreceive(mqd_t a, char *b, size_t c, unsigned *d,
207fdc51b51Sad const struct timespec *e)
208fdc51b51Sad {
209fdc51b51Sad
210fdc51b51Sad return (ssize_t)syscall(SYS_mq_timedreceive, a, b, c, d, e);
211fdc51b51Sad }
212