1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 /**************************************************************************/ 12 /**************************************************************************/ 13 /** */ 14 /** ThreadX Component */ 15 /** */ 16 /** POSIX Compliancy Wrapper (POSIX) */ 17 /** */ 18 /**************************************************************************/ 19 /**************************************************************************/ 20 21 /**************************************************************************/ 22 /* */ 23 /* EKP DEFINITIONS RELEASE */ 24 /* */ 25 /* px_int.h PORTABLE C */ 26 /* 6.2.0 */ 27 /* AUTHOR */ 28 /* */ 29 /* William E. Lamie, Microsoft Corporation */ 30 /* */ 31 /* DESCRIPTION */ 32 /* */ 33 /* This file defines the constants, structures, etc.needed to */ 34 /* implement the Evacuation Kit for POSIX Users (POSIX) */ 35 /* */ 36 /* */ 37 /* RELEASE HISTORY */ 38 /* */ 39 /* DATE NAME DESCRIPTION */ 40 /* */ 41 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 42 /* 10-31-2022 Scott Larson Remove unneeded values, */ 43 /* resulting in version 6.2.0 */ 44 /* */ 45 /**************************************************************************/ 46 47 #ifndef _TX_PX_INT_H 48 #define _TX_PX_INT_H 49 50 #include "string.h" 51 52 /* Define several ThreadX equates for use inside of POSIX. */ 53 #define TX_INITIALIZE_IN_PROGRESS 0xF0F0F0F0UL 54 #define TX_INITIALIZE_ALMOST_DONE 0xF0F0F0F1UL 55 56 /* Threadx min and max priority */ 57 #define TX_HIGHEST_PRIORITY 1 58 #define TX_LOWEST_PRIORITY 31 59 60 #define PX_HIGHEST_PRIORITY 31 61 #define PX_LOWEST_PRIORITY 1 62 63 /************ Extern Variables **************/ 64 extern TX_THREAD * _tx_thread_current_ptr; 65 extern TX_THREAD * _tx_thread_execute_ptr; 66 67 68 69 /* declares posix objects in the px_pth_init.c file */ 70 #ifdef PX_OBJECT_INIT 71 #define PX_OBJECT_DECLARE 72 #else 73 #define PX_OBJECT_DECLARE extern 74 #endif 75 /**************************************************************************/ 76 /* Global Definitions */ 77 /**************************************************************************/ 78 79 /* The ThreadX work queue for the POSIX System Manager. */ 80 PX_OBJECT_DECLARE TX_QUEUE posix_work_queue; 81 82 /* Define the thread for the System Manager functionality. */ 83 PX_OBJECT_DECLARE TX_THREAD posix_system_manager; 84 85 86 /**************************************************************************/ 87 /* Local definitions */ 88 /**************************************************************************/ 89 90 /* Define a byte pool control block for the heap memory used 91 by POSIX. */ 92 93 PX_OBJECT_DECLARE TX_BYTE_POOL posix_heap_byte_pool; 94 95 /* Define a static pool of pthread Control Blocks (TCB). If more pthreades are 96 required the constant PTHREAD_THREADS_MAX (in tx_posix.h) may be modified. */ 97 PX_OBJECT_DECLARE POSIX_TCB ptcb_pool[PTHREAD_THREADS_MAX]; 98 99 #if POSIX_MAX_QUEUES!= 0 100 /* Define a static pool of queues.If more pthread message queues are required 101 the constant POSIX_MAX_QUEUES (in tx_posix.h) may be modified. */ 102 PX_OBJECT_DECLARE POSIX_MSG_QUEUE posix_queue_pool[POSIX_MAX_QUEUES]; 103 /* Define a queue attribute. */ 104 PX_OBJECT_DECLARE struct mq_attr posix_qattr_default; 105 #endif 106 107 #if SEM_NSEMS_MAX != 0 108 /* Define a static pool of semaphores. If more pthread semaphores required the 109 constant SEM_NSEMS_MAX (in tx_posix.h) may be modified. */ 110 PX_OBJECT_DECLARE sem_t posix_sem_pool[SEM_NSEMS_MAX]; 111 112 #endif 113 114 /* Define a default pthread attribute. */ 115 PX_OBJECT_DECLARE pthread_attr_t posix_default_pthread_attr; 116 117 /* Define a default mutex attribute. */ 118 PX_OBJECT_DECLARE pthread_mutexattr_t posix_default_mutex_attr; 119 120 121 122 /* Define a temporary posix errno. */ 123 124 PX_OBJECT_DECLARE unsigned int posix_errno; 125 126 127 /**************************************************************************/ 128 /* Local prototypes */ 129 /**************************************************************************/ 130 /* Define Evacuation Kit for POSIX function prototypes. */ 131 132 INT posix_get_pthread_errno(pthread_t ptid); 133 134 POSIX_MSG_QUEUE *posix_mq_create ( const CHAR * mq_name, 135 struct mq_attr * msgq_attr); 136 137 POSIX_MSG_QUEUE *posix_find_queue(const CHAR * mq_name); 138 139 POSIX_MSG_QUEUE *posix_get_new_queue(ULONG maxnum); 140 141 ULONG posix_arrange_msg( TX_QUEUE * Queue, ULONG * pMsgPrio ); 142 143 ULONG posix_priority_search(mqd_t msgQId ,ULONG priority); 144 145 VOID posix_queue_init(VOID); 146 147 VOID posix_qattr_init(VOID); 148 149 VOID posix_pthread_init(VOID); 150 151 struct mq_des *posix_get_queue_des(POSIX_MSG_QUEUE * q_ptr); 152 153 VOID posix_reset_queue(POSIX_MSG_QUEUE * q_ptr); 154 155 VOID posix_memory_release(VOID * memory_ptr); 156 157 VOID posix_internal_error(ULONG error_code); 158 159 VOID posix_error_handler(ULONG error_code); 160 161 INT posix_memory_allocate(ULONG size, VOID **memory_ptr); 162 163 INT posix_queue_delete(POSIX_MSG_QUEUE * q_ptr); 164 165 VOID posix_putback_queue(TX_QUEUE * qid); 166 167 sem_t *posix_find_sem(const CHAR * name); 168 169 VOID posix_set_sem_name(sem_t * sem, CHAR *name); 170 171 TX_SEMAPHORE *posix_get_new_sem(VOID); 172 173 VOID posix_sem_reset(sem_t *sem); 174 175 ULONG posix_in_thread_context(VOID); 176 177 VOID posix_reset_pthread_t(POSIX_TCB *ptcb); 178 179 TX_THREAD *posix_tid2thread(pthread_t ptid); 180 181 POSIX_TCB *posix_tid2tcb(pthread_t ptid); 182 183 pthread_t posix_thread2tid(TX_THREAD *thread_ptr); 184 185 POSIX_TCB *posix_thread2tcb(TX_THREAD *thread_ptr); 186 187 TX_THREAD *posix_tcb2thread (POSIX_TCB *pthread_ptr); 188 189 VOID posix_thread_wrapper(ULONG pthr_ptr); 190 191 VOID set_default_pthread_attr(pthread_attr_t *attr); 192 193 VOID set_default_mutexattr(pthread_mutexattr_t *attr); 194 195 INT posix_allocate_pthread_t(POSIX_TCB **ptcb_ptr); 196 197 VOID posix_copy_pthread_attr(POSIX_TCB *pthread_ptr,pthread_attr_t *attr); 198 199 VOID posix_destroy_pthread(POSIX_TCB *pthread_ptr, VOID *value_ptr); 200 201 VOID posix_do_pthread_delete(POSIX_TCB *pthread_ptr, VOID *value_ptr); 202 203 VOID posix_system_manager_entry(ULONG input); 204 205 INT posix_set_pthread_errno(ULONG errno_set); 206 207 ULONG posix_abs_time_to_rel_ticks(struct timespec *abs_timeout); 208 209 #endif 210