1 /* 2 * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef __USR_LIBC_OPS_H 32 #define __USR_LIBC_OPS_H 33 34 #define _GNU_SOURCE 35 #include "pthread.h" 36 #include "string.h" 37 #include "semaphore.h" 38 39 typedef struct { 40 int (*pthread_attr_init)(pthread_attr_t *attr); 41 int (*pthread_attr_destroy)(pthread_attr_t *attr); 42 int (*pthread_attr_setdetachstate)(pthread_attr_t *attr, int detachState); 43 int (*pthread_attr_getdetachstate)(const pthread_attr_t *attr, int *detachState); 44 int (*pthread_attr_setscope)(pthread_attr_t *attr, int scope); 45 int (*pthread_attr_getscope)(const pthread_attr_t *attr, int *scope); 46 int (*pthread_attr_setinheritsched)(pthread_attr_t *attr, int inherit); 47 int (*pthread_attr_getinheritsched)(const pthread_attr_t *attr, int *inherit); 48 int (*pthread_attr_setschedpolicy)(pthread_attr_t *attr, int policy); 49 int (*pthread_attr_getschedpolicy)(const pthread_attr_t *attr, int *policy); 50 int (*pthread_attr_setschedparam)(pthread_attr_t *attr, const struct sched_param *param); 51 int (*pthread_attr_getschedparam)(const pthread_attr_t *attr, struct sched_param *param); 52 int (*pthread_attr_setstack)(pthread_attr_t *a, void *addr, size_t size); 53 int (*pthread_attr_getstack)(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size); 54 int (*pthread_attr_setstacksize)(pthread_attr_t *attr, size_t stackSize); 55 int (*pthread_attr_getstacksize)(const pthread_attr_t *attr, size_t *stackSize); 56 int (*sched_get_priority_min)(int policy); 57 int (*sched_get_priority_max)(int policy); 58 int (*pthread_create)(pthread_t *thread, const pthread_attr_t *attr, void *(*startRoutine)(void *), void *arg); 59 int (*pthread_setschedparam)(pthread_t thread, int policy, const struct sched_param *param); 60 int (*pthread_getschedparam)(pthread_t thread, int *policy, struct sched_param *param); 61 pthread_t (*pthread_self)(void); 62 int (*pthread_cancel)(pthread_t thread); 63 int (*pthread_join)(pthread_t thread, void **retval); 64 int (*pthread_detach)(pthread_t thread); 65 void (*pthread_exit)(void *retVal); 66 int (*pthread_setname_np)(pthread_t thread, const char *name); 67 int (*pthread_getname_np)(pthread_t thread, char *buf, size_t buflen); 68 int (*pthread_mutexattr_init)(pthread_mutexattr_t *mutexAttr); 69 int (*pthread_mutexattr_settype)(pthread_mutexattr_t *mutexAttr, int type); 70 int (*pthread_mutexattr_destroy)(pthread_mutexattr_t *mutexAttr); 71 int (*pthread_mutex_init)(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexAttr); 72 int (*pthread_mutex_destroy)(pthread_mutex_t *mutex); 73 int (*pthread_mutex_timedlock)(pthread_mutex_t *mutex, const struct timespec *absTimeout); 74 int (*pthread_mutex_lock)(pthread_mutex_t *mutex); 75 int (*pthread_mutex_trylock)(pthread_mutex_t *mutex); 76 int (*pthread_mutex_unlock)(pthread_mutex_t *mutex); 77 int (*pthread_condattr_init)(pthread_condattr_t *attr); 78 int (*pthread_condattr_destroy)(pthread_condattr_t *attr); 79 int (*pthread_condattr_setclock)(pthread_condattr_t *attr, clockid_t clk); 80 int (*pthread_cond_init)(pthread_cond_t *cond, const pthread_condattr_t *attr); 81 int (*pthread_cond_destroy)(pthread_cond_t *cond); 82 int (*pthread_cond_broadcast)(pthread_cond_t *cond); 83 int (*pthread_cond_signal)(pthread_cond_t *cond); 84 int (*pthread_cond_timedwait)(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *ts); 85 int (*pthread_cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex); 86 int (*sem_init)(sem_t *sem, int shared, unsigned int value); 87 int (*sem_destroy)(sem_t *sem); 88 int (*sem_wait)(sem_t *sem); 89 int (*sem_post)(sem_t *sem); 90 int (*sem_timedwait)(sem_t *sem, const struct timespec *timeout); 91 int (*sem_getvalue)(sem_t *sem, int *currVal); 92 int (*nanosleep)(const struct timespec *rqtp, struct timespec *rmtp); 93 int (*timer_create)(clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID); 94 int (*timer_delete)(timer_t timerID); 95 int (*timer_settime)(timer_t timerID, int flags, const struct itimerspec *restrict value, struct itimerspec *restrict oldValue); 96 int (*timer_gettime)(timer_t timerID, struct itimerspec *value); 97 int (*timer_getoverrun)(timer_t timerID); 98 int (*clock_settime)(clockid_t clockID, const struct timespec *tp); 99 int (*clock_gettime)(clockid_t clockID, struct timespec *tp); 100 int (*clock_getres)(clockid_t clockID, struct timespec *tp); 101 int (*clock_nanosleep)(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem); 102 clock_t (*clock)(void); 103 time_t (*time)(time_t *timer); 104 struct tm *(*gmtime_r)(const time_t *timep, struct tm *result); 105 struct tm *(*localtime_r)(const time_t *timep, struct tm *result); 106 time_t (*mktime)(struct tm *tmptr); 107 int (*gettimeofday)(struct timeval *tv, void *ptz); 108 int (*settimeofday)(const struct timeval *tv, const struct timezone *tz); 109 void (*free)(void *ptr); 110 void *(*malloc)(size_t size); 111 void *(*memcpy)(void *restrict dest, const void *restrict src, size_t n); 112 int (*memcmp)(const void *vl, const void *vr, size_t n); 113 void *(*memset)(void *dest, int c, size_t n); 114 size_t (*strlen)(const char *s); 115 int (*strcmp)(const char *l, const char *r); 116 } UsrLibcOps; 117 118 #endif 119