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