1/*	$NetBSD: pthread_compat.c,v 1.7 2022/02/12 14:59:32 riastradh Exp $	*/
2
3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software developed for The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * libc symbols that are not present before NetBSD 5.0.
34 */
35
36#include <sys/cdefs.h>
37__RCSID("$NetBSD: pthread_compat.c,v 1.7 2022/02/12 14:59:32 riastradh Exp $");
38
39/* Need to use libc-private names for atomic operations. */
40#include "../../common/lib/libc/atomic/atomic_op_namespace.h"
41
42#include <sys/param.h>
43#include <sys/syscall.h>
44#include <sys/aio.h>
45
46#include <lwp.h>
47#include <unistd.h>
48#include <sched.h>
49
50#include "pthread.h"
51#include "pthread_int.h"
52
53static void     __pthread_init(void) __attribute__((__constructor__, __used__));
54
55void	__libc_thr_init(void);
56void	__libc_atomic_init(void);
57
58int	_sys_sched_yield(void);
59int	_sys_aio_suspend(const struct aiocb * const[], int,
60			 const struct timespec *);
61int	_sys_mq_send(mqd_t, const char *, size_t, unsigned);
62ssize_t	_sys_mq_receive(mqd_t, char *, size_t, unsigned *);
63int	_sys_mq_timedsend(mqd_t, const char *, size_t, unsigned,
64			  const struct timespec *);
65ssize_t	_sys_mq_timedreceive(mqd_t, char *, size_t, unsigned *,
66			     const struct timespec *);
67
68static void
69__pthread_init(void)
70{
71
72	__libc_atomic_init();
73	__libc_thr_init();
74}
75
76int
77_lwp_kill(lwpid_t a, int b)
78{
79
80	return syscall(SYS__lwp_kill, a, b);
81}
82
83int
84_lwp_detach(lwpid_t a)
85{
86
87	return syscall(SYS__lwp_detach, a);
88}
89
90int
91_lwp_park(clockid_t a, int b, const struct timespec *c, lwpid_t d,
92    const void *e, const void *f)
93{
94
95	return syscall(SYS____lwp_park60, a, b, c, d, e, f);
96}
97
98int
99_lwp_unpark(lwpid_t a, const void *b)
100{
101
102	return syscall(SYS__lwp_unpark, a, b);
103}
104
105ssize_t
106_lwp_unpark_all(const lwpid_t *a, size_t b, const void *c)
107{
108
109	return (ssize_t)syscall(SYS__lwp_unpark_all, a, b, c);
110}
111
112int
113_lwp_setname(lwpid_t a, const char *b)
114{
115
116	return syscall(SYS__lwp_setname, a, b);
117}
118
119int
120_lwp_getname(lwpid_t a, char *b, size_t c)
121{
122
123	return syscall(SYS__lwp_getname, a, b, c);
124}
125
126int
127_lwp_ctl(int a, struct lwpctl **b)
128{
129
130	return syscall(SYS__lwp_ctl, a, b);
131}
132
133int
134_sys_sched_yield(void)
135{
136
137	return syscall(SYS_sched_yield);
138}
139
140int
141sched_yield(void)
142{
143
144	return syscall(SYS_sched_yield);
145}
146
147int
148_sched_setaffinity(pid_t a, lwpid_t b, size_t c, const cpuset_t *d)
149{
150
151	return syscall(SYS__sched_setaffinity, a, b, c, d);
152}
153
154int
155_sched_getaffinity(pid_t a, lwpid_t b, size_t c, cpuset_t *d)
156{
157
158	return syscall(SYS__sched_getaffinity, a, b, c, d);
159}
160
161int
162_sched_setparam(pid_t a, lwpid_t b, int c, const struct sched_param *d)
163{
164
165	return syscall(SYS__sched_setparam, a, b, c, d);
166}
167
168int
169_sched_getparam(pid_t a, lwpid_t b, int *c, struct sched_param *d)
170{
171
172	return syscall(SYS__sched_getparam, a, b, c, d);
173}
174
175int
176_sys_aio_suspend(const struct aiocb * const a[], int b,
177		 const struct timespec *c)
178{
179
180	return syscall(SYS_aio_suspend, a, b, c);
181}
182
183int
184_sys_mq_send(mqd_t a, const char *b, size_t c, unsigned d)
185{
186
187	return syscall(SYS_mq_send, a, b, c, d);
188}
189
190ssize_t
191_sys_mq_receive(mqd_t a, char *b, size_t c, unsigned *d)
192{
193
194	return (ssize_t)syscall(SYS_mq_receive, a, b, c, d);
195}
196
197int
198_sys_mq_timedsend(mqd_t a, const char *b, size_t c, unsigned d,
199		  const struct timespec *e)
200{
201
202	return syscall(SYS_mq_timedsend, a, b,c ,d, e);
203}
204
205ssize_t
206_sys_mq_timedreceive(mqd_t a, char *b, size_t c, unsigned *d,
207		     const struct timespec *e)
208{
209
210	return (ssize_t)syscall(SYS_mq_timedreceive, a, b, c, d, e);
211}
212