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