1 | /*- |
---|
2 | * SPDX-License-Identifier: BSD-3-Clause |
---|
3 | * |
---|
4 | * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * 3. Neither the name of the author nor the names of any co-contributors |
---|
16 | * may be used to endorse or promote products derived from this software |
---|
17 | * without specific prior written permission. |
---|
18 | * |
---|
19 | * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND |
---|
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
29 | * SUCH DAMAGE. |
---|
30 | * |
---|
31 | * $FreeBSD$ |
---|
32 | * |
---|
33 | * Private definitions for libc, libc_r and libpthread. |
---|
34 | * |
---|
35 | */ |
---|
36 | |
---|
37 | #ifndef _LIBC_PRIVATE_H_ |
---|
38 | #define _LIBC_PRIVATE_H_ |
---|
39 | #ifndef __rtems__ |
---|
40 | #include <sys/_types.h> |
---|
41 | #include <sys/_pthreadtypes.h> |
---|
42 | #else /* __rtems__ */ |
---|
43 | #include <sys/types.h> |
---|
44 | #endif /* __rtems__ */ |
---|
45 | |
---|
46 | /* |
---|
47 | * This global flag is non-zero when a process has created one |
---|
48 | * or more threads. It is used to avoid calling locking functions |
---|
49 | * when they are not required. |
---|
50 | */ |
---|
51 | #ifdef __rtems__ |
---|
52 | #define __isthreaded 1 |
---|
53 | #else /* __rtems__ */ |
---|
54 | #ifndef __LIBC_ISTHREADED_DECLARED |
---|
55 | #define __LIBC_ISTHREADED_DECLARED |
---|
56 | extern int __isthreaded; |
---|
57 | #endif |
---|
58 | #endif /* __rtems__ */ |
---|
59 | |
---|
60 | /* |
---|
61 | * Elf_Auxinfo *__elf_aux_vector, the pointer to the ELF aux vector |
---|
62 | * provided by kernel. Either set for us by rtld, or found at runtime |
---|
63 | * on stack for static binaries. |
---|
64 | * |
---|
65 | * Type is void to avoid polluting whole libc with ELF types. |
---|
66 | */ |
---|
67 | extern void *__elf_aux_vector; |
---|
68 | |
---|
69 | /* |
---|
70 | * libc should use libc_dlopen internally, which respects a global |
---|
71 | * flag where loading of new shared objects can be restricted. |
---|
72 | */ |
---|
73 | void *libc_dlopen(const char *, int); |
---|
74 | |
---|
75 | /* |
---|
76 | * For dynamic linker. |
---|
77 | */ |
---|
78 | void _rtld_error(const char *fmt, ...); |
---|
79 | |
---|
80 | /* |
---|
81 | * File lock contention is difficult to diagnose without knowing |
---|
82 | * where locks were set. Allow a debug library to be built which |
---|
83 | * records the source file and line number of each lock call. |
---|
84 | */ |
---|
85 | #ifdef _FLOCK_DEBUG |
---|
86 | #define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) |
---|
87 | #else |
---|
88 | #define _FLOCKFILE(x) _flockfile(x) |
---|
89 | #endif |
---|
90 | |
---|
91 | /* |
---|
92 | * Macros for locking and unlocking FILEs. These test if the |
---|
93 | * process is threaded to avoid locking when not required. |
---|
94 | */ |
---|
95 | #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) |
---|
96 | #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) |
---|
97 | |
---|
98 | struct _spinlock; |
---|
99 | extern struct _spinlock __stdio_thread_lock __hidden; |
---|
100 | #define STDIO_THREAD_LOCK() \ |
---|
101 | do { \ |
---|
102 | if (__isthreaded) \ |
---|
103 | _SPINLOCK(&__stdio_thread_lock); \ |
---|
104 | } while (0) |
---|
105 | #define STDIO_THREAD_UNLOCK() \ |
---|
106 | do { \ |
---|
107 | if (__isthreaded) \ |
---|
108 | _SPINUNLOCK(&__stdio_thread_lock); \ |
---|
109 | } while (0) |
---|
110 | |
---|
111 | void __libc_spinlock_stub(struct _spinlock *); |
---|
112 | void __libc_spinunlock_stub(struct _spinlock *); |
---|
113 | |
---|
114 | /* |
---|
115 | * Indexes into the pthread jump table. |
---|
116 | * |
---|
117 | * Warning! If you change this type, you must also change the threads |
---|
118 | * libraries that reference it (libc_r, libpthread). |
---|
119 | */ |
---|
120 | typedef enum { |
---|
121 | PJT_ATFORK, |
---|
122 | PJT_ATTR_DESTROY, |
---|
123 | PJT_ATTR_GETDETACHSTATE, |
---|
124 | PJT_ATTR_GETGUARDSIZE, |
---|
125 | PJT_ATTR_GETINHERITSCHED, |
---|
126 | PJT_ATTR_GETSCHEDPARAM, |
---|
127 | PJT_ATTR_GETSCHEDPOLICY, |
---|
128 | PJT_ATTR_GETSCOPE, |
---|
129 | PJT_ATTR_GETSTACKADDR, |
---|
130 | PJT_ATTR_GETSTACKSIZE, |
---|
131 | PJT_ATTR_INIT, |
---|
132 | PJT_ATTR_SETDETACHSTATE, |
---|
133 | PJT_ATTR_SETGUARDSIZE, |
---|
134 | PJT_ATTR_SETINHERITSCHED, |
---|
135 | PJT_ATTR_SETSCHEDPARAM, |
---|
136 | PJT_ATTR_SETSCHEDPOLICY, |
---|
137 | PJT_ATTR_SETSCOPE, |
---|
138 | PJT_ATTR_SETSTACKADDR, |
---|
139 | PJT_ATTR_SETSTACKSIZE, |
---|
140 | PJT_CANCEL, |
---|
141 | PJT_CLEANUP_POP, |
---|
142 | PJT_CLEANUP_PUSH, |
---|
143 | PJT_COND_BROADCAST, |
---|
144 | PJT_COND_DESTROY, |
---|
145 | PJT_COND_INIT, |
---|
146 | PJT_COND_SIGNAL, |
---|
147 | PJT_COND_TIMEDWAIT, |
---|
148 | PJT_COND_WAIT, |
---|
149 | PJT_DETACH, |
---|
150 | PJT_EQUAL, |
---|
151 | PJT_EXIT, |
---|
152 | PJT_GETSPECIFIC, |
---|
153 | PJT_JOIN, |
---|
154 | PJT_KEY_CREATE, |
---|
155 | PJT_KEY_DELETE, |
---|
156 | PJT_KILL, |
---|
157 | PJT_MAIN_NP, |
---|
158 | PJT_MUTEXATTR_DESTROY, |
---|
159 | PJT_MUTEXATTR_INIT, |
---|
160 | PJT_MUTEXATTR_SETTYPE, |
---|
161 | PJT_MUTEX_DESTROY, |
---|
162 | PJT_MUTEX_INIT, |
---|
163 | PJT_MUTEX_LOCK, |
---|
164 | PJT_MUTEX_TRYLOCK, |
---|
165 | PJT_MUTEX_UNLOCK, |
---|
166 | PJT_ONCE, |
---|
167 | PJT_RWLOCK_DESTROY, |
---|
168 | PJT_RWLOCK_INIT, |
---|
169 | PJT_RWLOCK_RDLOCK, |
---|
170 | PJT_RWLOCK_TRYRDLOCK, |
---|
171 | PJT_RWLOCK_TRYWRLOCK, |
---|
172 | PJT_RWLOCK_UNLOCK, |
---|
173 | PJT_RWLOCK_WRLOCK, |
---|
174 | PJT_SELF, |
---|
175 | PJT_SETCANCELSTATE, |
---|
176 | PJT_SETCANCELTYPE, |
---|
177 | PJT_SETSPECIFIC, |
---|
178 | PJT_SIGMASK, |
---|
179 | PJT_TESTCANCEL, |
---|
180 | PJT_CLEANUP_POP_IMP, |
---|
181 | PJT_CLEANUP_PUSH_IMP, |
---|
182 | PJT_CANCEL_ENTER, |
---|
183 | PJT_CANCEL_LEAVE, |
---|
184 | PJT_MUTEX_CONSISTENT, |
---|
185 | PJT_MUTEXATTR_GETROBUST, |
---|
186 | PJT_MUTEXATTR_SETROBUST, |
---|
187 | PJT_GETTHREADID_NP, |
---|
188 | PJT_MAX |
---|
189 | } pjt_index_t; |
---|
190 | |
---|
191 | typedef int (*pthread_func_t)(void); |
---|
192 | typedef pthread_func_t pthread_func_entry_t[2]; |
---|
193 | |
---|
194 | extern pthread_func_entry_t __thr_jtable[]; |
---|
195 | |
---|
196 | void __set_error_selector(int *(*arg)(void)); |
---|
197 | int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, |
---|
198 | void *(calloc_cb)(__size_t, __size_t)); |
---|
199 | |
---|
200 | typedef int (*interpos_func_t)(void); |
---|
201 | interpos_func_t *__libc_interposing_slot(int interposno); |
---|
202 | extern interpos_func_t __libc_interposing[] __hidden; |
---|
203 | |
---|
204 | enum { |
---|
205 | INTERPOS_accept, |
---|
206 | INTERPOS_accept4, |
---|
207 | INTERPOS_aio_suspend, |
---|
208 | INTERPOS_close, |
---|
209 | INTERPOS_connect, |
---|
210 | INTERPOS_fcntl, |
---|
211 | INTERPOS_fsync, |
---|
212 | INTERPOS_fork, |
---|
213 | INTERPOS_msync, |
---|
214 | INTERPOS_nanosleep, |
---|
215 | INTERPOS_openat, |
---|
216 | INTERPOS_poll, |
---|
217 | INTERPOS_pselect, |
---|
218 | INTERPOS_recvfrom, |
---|
219 | INTERPOS_recvmsg, |
---|
220 | INTERPOS_select, |
---|
221 | INTERPOS_sendmsg, |
---|
222 | INTERPOS_sendto, |
---|
223 | INTERPOS_setcontext, |
---|
224 | INTERPOS_sigaction, |
---|
225 | INTERPOS_sigprocmask, |
---|
226 | INTERPOS_sigsuspend, |
---|
227 | INTERPOS_sigwait, |
---|
228 | INTERPOS_sigtimedwait, |
---|
229 | INTERPOS_sigwaitinfo, |
---|
230 | INTERPOS_swapcontext, |
---|
231 | INTERPOS_system, |
---|
232 | INTERPOS_tcdrain, |
---|
233 | INTERPOS_read, |
---|
234 | INTERPOS_readv, |
---|
235 | INTERPOS_wait4, |
---|
236 | INTERPOS_write, |
---|
237 | INTERPOS_writev, |
---|
238 | INTERPOS__pthread_mutex_init_calloc_cb, |
---|
239 | INTERPOS_spinlock, |
---|
240 | INTERPOS_spinunlock, |
---|
241 | INTERPOS_kevent, |
---|
242 | INTERPOS_wait6, |
---|
243 | INTERPOS_ppoll, |
---|
244 | INTERPOS_map_stacks_exec, |
---|
245 | INTERPOS_fdatasync, |
---|
246 | INTERPOS_clock_nanosleep, |
---|
247 | INTERPOS_distribute_static_tls, |
---|
248 | INTERPOS_MAX |
---|
249 | }; |
---|
250 | |
---|
251 | /* |
---|
252 | * yplib internal interfaces |
---|
253 | */ |
---|
254 | #ifdef YP |
---|
255 | int _yp_check(char **); |
---|
256 | #endif |
---|
257 | |
---|
258 | /* |
---|
259 | * Initialise TLS for static programs |
---|
260 | */ |
---|
261 | void _init_tls(void); |
---|
262 | |
---|
263 | /* |
---|
264 | * Provides pthread_once()-like functionality for both single-threaded |
---|
265 | * and multi-threaded applications. |
---|
266 | */ |
---|
267 | int _once(pthread_once_t *, void (*)(void)); |
---|
268 | |
---|
269 | /* |
---|
270 | * Set the TLS thread pointer |
---|
271 | */ |
---|
272 | void _set_tp(void *tp); |
---|
273 | |
---|
274 | /* |
---|
275 | * This is a pointer in the C run-time startup code. It is used |
---|
276 | * by getprogname() and setprogname(). |
---|
277 | */ |
---|
278 | extern const char *__progname; |
---|
279 | |
---|
280 | /* |
---|
281 | * This function is used by the threading libraries to notify malloc that a |
---|
282 | * thread is exiting. |
---|
283 | */ |
---|
284 | void _malloc_thread_cleanup(void); |
---|
285 | |
---|
286 | /* |
---|
287 | * This function is used by the threading libraries to notify libc that a |
---|
288 | * thread is exiting, so its thread-local dtors should be called. |
---|
289 | */ |
---|
290 | void __cxa_thread_call_dtors(void); |
---|
291 | int __cxa_thread_atexit_hidden(void (*dtor_func)(void *), void *obj, |
---|
292 | void *dso_symbol) __hidden; |
---|
293 | |
---|
294 | /* |
---|
295 | * These functions are used by the threading libraries in order to protect |
---|
296 | * malloc across fork(). |
---|
297 | */ |
---|
298 | void _malloc_prefork(void); |
---|
299 | void _malloc_postfork(void); |
---|
300 | |
---|
301 | void _malloc_first_thread(void); |
---|
302 | |
---|
303 | /* |
---|
304 | * Function to clean up streams, called from abort() and exit(). |
---|
305 | */ |
---|
306 | extern void (*__cleanup)(void) __hidden; |
---|
307 | |
---|
308 | /* |
---|
309 | * Get kern.osreldate to detect ABI revisions. Explicitly |
---|
310 | * ignores value of $OSVERSION and caches result. |
---|
311 | */ |
---|
312 | int __getosreldate(void); |
---|
313 | #include <sys/_types.h> |
---|
314 | #include <sys/_sigset.h> |
---|
315 | |
---|
316 | struct aiocb; |
---|
317 | struct fd_set; |
---|
318 | struct iovec; |
---|
319 | struct kevent; |
---|
320 | struct msghdr; |
---|
321 | struct pollfd; |
---|
322 | struct rusage; |
---|
323 | struct sigaction; |
---|
324 | struct sockaddr; |
---|
325 | struct stat; |
---|
326 | struct statfs; |
---|
327 | struct timespec; |
---|
328 | struct timeval; |
---|
329 | struct timezone; |
---|
330 | struct __siginfo; |
---|
331 | struct __ucontext; |
---|
332 | struct __wrusage; |
---|
333 | enum idtype; |
---|
334 | int __sys_aio_suspend(const struct aiocb * const[], int, |
---|
335 | const struct timespec *); |
---|
336 | int __sys_accept(int, struct sockaddr *, __socklen_t *); |
---|
337 | int __sys_accept4(int, struct sockaddr *, __socklen_t *, int); |
---|
338 | int __sys_clock_gettime(__clockid_t, struct timespec *ts); |
---|
339 | int __sys_clock_nanosleep(__clockid_t, int, |
---|
340 | const struct timespec *, struct timespec *); |
---|
341 | int __sys_close(int); |
---|
342 | int __sys_connect(int, const struct sockaddr *, __socklen_t); |
---|
343 | int __sys_fcntl(int, int, ...); |
---|
344 | int __sys_fdatasync(int); |
---|
345 | int __sys_fstat(int fd, struct stat *); |
---|
346 | int __sys_fstatfs(int fd, struct statfs *); |
---|
347 | int __sys_fstatat(int, const char *, struct stat *, int); |
---|
348 | int __sys_fsync(int); |
---|
349 | __pid_t __sys_fork(void); |
---|
350 | int __sys_ftruncate(int, __off_t); |
---|
351 | __ssize_t __sys_getdirentries(int, char *, __size_t, __off_t *); |
---|
352 | int __sys_getfsstat(struct statfs *, long, int); |
---|
353 | int __sys_gettimeofday(struct timeval *, struct timezone *); |
---|
354 | int __sys_kevent(int, const struct kevent *, int, struct kevent *, |
---|
355 | int, const struct timespec *); |
---|
356 | __off_t __sys_lseek(int, __off_t, int); |
---|
357 | void *__sys_mmap(void *, __size_t, int, int, int, __off_t); |
---|
358 | int __sys_msync(void *, __size_t, int); |
---|
359 | int __sys_nanosleep(const struct timespec *, struct timespec *); |
---|
360 | int __sys_open(const char *, int, ...); |
---|
361 | int __sys_openat(int, const char *, int, ...); |
---|
362 | int __sys_pselect(int, struct fd_set *, struct fd_set *, |
---|
363 | struct fd_set *, const struct timespec *, |
---|
364 | const __sigset_t *); |
---|
365 | int __sys_ptrace(int, __pid_t, char *, int); |
---|
366 | int __sys_poll(struct pollfd *, unsigned, int); |
---|
367 | int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *, |
---|
368 | const __sigset_t *); |
---|
369 | __ssize_t __sys_pread(int, void *, __size_t, __off_t); |
---|
370 | __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); |
---|
371 | __ssize_t __sys_read(int, void *, __size_t); |
---|
372 | __ssize_t __sys_readv(int, const struct iovec *, int); |
---|
373 | __ssize_t __sys_recv(int, void *, __size_t, int); |
---|
374 | __ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *, |
---|
375 | __socklen_t *); |
---|
376 | __ssize_t __sys_recvmsg(int, struct msghdr *, int); |
---|
377 | int __sys_select(int, struct fd_set *, struct fd_set *, |
---|
378 | struct fd_set *, struct timeval *); |
---|
379 | __ssize_t __sys_sendmsg(int, const struct msghdr *, int); |
---|
380 | __ssize_t __sys_sendto(int, const void *, __size_t, int, |
---|
381 | const struct sockaddr *, __socklen_t); |
---|
382 | int __sys_setcontext(const struct __ucontext *); |
---|
383 | int __sys_sigaction(int, const struct sigaction *, |
---|
384 | struct sigaction *); |
---|
385 | int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *); |
---|
386 | int __sys_sigsuspend(const __sigset_t *); |
---|
387 | int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *, |
---|
388 | const struct timespec *); |
---|
389 | int __sys_sigwait(const __sigset_t *, int *); |
---|
390 | int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *); |
---|
391 | int __sys_statfs(const char *, struct statfs *); |
---|
392 | int __sys_swapcontext(struct __ucontext *, |
---|
393 | const struct __ucontext *); |
---|
394 | int __sys_thr_kill(long, int); |
---|
395 | int __sys_thr_self(long *); |
---|
396 | int __sys_truncate(const char *, __off_t); |
---|
397 | __pid_t __sys_wait4(__pid_t, int *, int, struct rusage *); |
---|
398 | __pid_t __sys_wait6(enum idtype, __id_t, int *, int, |
---|
399 | struct __wrusage *, struct __siginfo *); |
---|
400 | __ssize_t __sys_write(int, const void *, __size_t); |
---|
401 | __ssize_t __sys_writev(int, const struct iovec *, int); |
---|
402 | |
---|
403 | int __libc_sigaction(int, const struct sigaction *, |
---|
404 | struct sigaction *) __hidden; |
---|
405 | int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *) |
---|
406 | __hidden; |
---|
407 | int __libc_sigsuspend(const __sigset_t *) __hidden; |
---|
408 | int __libc_sigwait(const __sigset_t * __restrict, |
---|
409 | int * restrict sig); |
---|
410 | int __libc_system(const char *); |
---|
411 | int __libc_tcdrain(int); |
---|
412 | int __fcntl_compat(int fd, int cmd, ...); |
---|
413 | |
---|
414 | int __sys_futimens(int fd, const struct timespec *times) __hidden; |
---|
415 | int __sys_utimensat(int fd, const char *path, |
---|
416 | const struct timespec *times, int flag) __hidden; |
---|
417 | |
---|
418 | /* execve() with PATH processing to implement posix_spawnp() */ |
---|
419 | int _execvpe(const char *, char * const *, char * const *); |
---|
420 | |
---|
421 | int _elf_aux_info(int aux, void *buf, int buflen); |
---|
422 | struct dl_phdr_info; |
---|
423 | int __elf_phdr_match_addr(struct dl_phdr_info *, void *); |
---|
424 | void __init_elf_aux_vector(void); |
---|
425 | void __libc_map_stacks_exec(void); |
---|
426 | void __libc_distribute_static_tls(__size_t, void *, __size_t, __size_t); |
---|
427 | __uintptr_t __libc_static_tls_base(__size_t); |
---|
428 | |
---|
429 | void _pthread_cancel_enter(int); |
---|
430 | void _pthread_cancel_leave(int); |
---|
431 | |
---|
432 | struct _pthread_cleanup_info; |
---|
433 | void ___pthread_cleanup_push_imp(void (*)(void *), void *, |
---|
434 | struct _pthread_cleanup_info *); |
---|
435 | void ___pthread_cleanup_pop_imp(int); |
---|
436 | |
---|
437 | void __throw_constraint_handler_s(const char * restrict msg, int error); |
---|
438 | |
---|
439 | #endif /* _LIBC_PRIVATE_H_ */ |
---|