pthread_compat.c revision 1.5 1 /* $NetBSD: pthread_compat.c,v 1.5 2017/12/08 09:41:16 kre 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.5 2017/12/08 09:41:16 kre Exp $");
38
39 #include <sys/param.h>
40 #include <sys/syscall.h>
41 #include <sys/aio.h>
42
43 #include <lwp.h>
44 #include <unistd.h>
45 #include <sched.h>
46
47 #include "pthread.h"
48 #include "pthread_int.h"
49
50 static void __pthread_init(void) __attribute__((__constructor__, __used__));
51
52 void __libc_thr_init(void);
53 void __libc_atomic_init(void);
54
55 int _sys_sched_yield(void);
56 int _sys_aio_suspend(const struct aiocb * const[], int,
57 const struct timespec *);
58 int _sys_mq_send(mqd_t, const char *, size_t, unsigned);
59 ssize_t _sys_mq_receive(mqd_t, char *, size_t, unsigned *);
60 int _sys_mq_timedsend(mqd_t, const char *, size_t, unsigned,
61 const struct timespec *);
62 ssize_t _sys_mq_timedreceive(mqd_t, char *, size_t, unsigned *,
63 const struct timespec *);
64
65 static void
66 __pthread_init(void)
67 {
68
69 __libc_atomic_init();
70 __libc_thr_init();
71 }
72
73 int
74 _lwp_kill(lwpid_t a, int b)
75 {
76
77 return syscall(SYS__lwp_kill, a, b);
78 }
79
80 int
81 _lwp_detach(lwpid_t a)
82 {
83
84 return syscall(SYS__lwp_detach, a);
85 }
86
87 int
88 _lwp_park(clockid_t a, int b, const struct timespec *c, lwpid_t d,
89 const void *e, const void *f)
90 {
91
92 if (c != NULL) {
93 struct timespec t = *c;
94
95 return syscall(SYS____lwp_park60, a, b, &t, d, e, f);
96 } else
97 return syscall(SYS____lwp_park60, a, b, NULL, d, e, f);
98 }
99
100 int
101 _lwp_unpark(lwpid_t a, const void *b)
102 {
103
104 return syscall(SYS__lwp_unpark, a, b);
105 }
106
107 ssize_t
108 _lwp_unpark_all(const lwpid_t *a, size_t b, const void *c)
109 {
110
111 return (ssize_t)syscall(SYS__lwp_unpark_all, a, b, c);
112 }
113
114 int
115 _lwp_setname(lwpid_t a, const char *b)
116 {
117
118 return syscall(SYS__lwp_setname, a, b);
119 }
120
121 int
122 _lwp_getname(lwpid_t a, char *b, size_t c)
123 {
124
125 return syscall(SYS__lwp_getname, a, b, c);
126 }
127
128 int
129 _lwp_ctl(int a, struct lwpctl **b)
130 {
131
132 return syscall(SYS__lwp_ctl, a, b);
133 }
134
135 int
136 _sys_sched_yield(void)
137 {
138
139 return syscall(SYS_sched_yield);
140 }
141
142 int
143 sched_yield(void)
144 {
145
146 return syscall(SYS_sched_yield);
147 }
148
149 int
150 _sched_setaffinity(pid_t a, lwpid_t b, size_t c, const cpuset_t *d)
151 {
152
153 return syscall(SYS__sched_setaffinity, a, b, c, d);
154 }
155
156 int
157 _sched_getaffinity(pid_t a, lwpid_t b, size_t c, cpuset_t *d)
158 {
159
160 return syscall(SYS__sched_getaffinity, a, b, c, d);
161 }
162
163 int
164 _sched_setparam(pid_t a, lwpid_t b, int c, const struct sched_param *d)
165 {
166
167 return syscall(SYS__sched_setparam, a, b, c, d);
168 }
169
170 int
171 _sched_getparam(pid_t a, lwpid_t b, int *c, struct sched_param *d)
172 {
173
174 return syscall(SYS__sched_getparam, a, b, c, d);
175 }
176
177 int
178 _sys_aio_suspend(const struct aiocb * const a[], int b,
179 const struct timespec *c)
180 {
181
182 return syscall(SYS_aio_suspend, a, b, c);
183 }
184
185 int
186 _sys_mq_send(mqd_t a, const char *b, size_t c, unsigned d)
187 {
188
189 return syscall(SYS_mq_send, a, b, c, d);
190 }
191
192 ssize_t
193 _sys_mq_receive(mqd_t a, char *b, size_t c, unsigned *d)
194 {
195
196 return (ssize_t)syscall(SYS_mq_receive, a, b, c, d);
197 }
198
199 int
200 _sys_mq_timedsend(mqd_t a, const char *b, size_t c, unsigned d,
201 const struct timespec *e)
202 {
203
204 return syscall(SYS_mq_timedsend, a, b,c ,d, e);
205 }
206
207 ssize_t
208 _sys_mq_timedreceive(mqd_t a, char *b, size_t c, unsigned *d,
209 const struct timespec *e)
210 {
211
212 return (ssize_t)syscall(SYS_mq_timedreceive, a, b, c, d, e);
213 }
214