summaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorFrédéric Desbiens <[email protected]>2026-10-02 10:42:44 -0400
committerGitHub <[email protected]>2026-10-02 10:42:44 -0400
commit93387b0a60382a29579bbad5045c68328e3751df (patch)
tree42be790d602cb76f55090e5a7c418df7ea2b3428 /utility
parent44d7c95c582d415c4ad84527180b29c93c3bf664 (diff)
parent28281cd5647d4671236ca08d19bd18ed15b2265a (diff)
Merge pull request #783 from eclipse-threadx/devv6.5.2.202603_rel
Merged changes ahead of the v6.5.2.202603 release
Diffstat (limited to 'utility')
-rw-r--r--utility/benchmarks/thread_metric/tm_basic_processing_test.c24
-rw-r--r--utility/execution_profile_kit/smp_version/tx_execution_profile.c7
-rw-r--r--utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c20
-rw-r--r--utility/rtos_compatibility_layers/posix/CMakeLists.txt130
-rw-r--r--utility/rtos_compatibility_layers/posix/px_cond_broadcast.c3
-rw-r--r--utility/rtos_compatibility_layers/posix/px_cond_destroy.c3
-rw-r--r--utility/rtos_compatibility_layers/posix/px_cond_init.c3
-rw-r--r--utility/rtos_compatibility_layers/posix/px_cond_signal.c3
-rw-r--r--utility/rtos_compatibility_layers/posix/px_mq_send.c19
-rw-r--r--utility/rtos_compatibility_layers/posix/px_pth_init.c20
-rw-r--r--utility/rtos_compatibility_layers/posix/px_pth_self.c17
-rw-r--r--utility/rtos_compatibility_layers/posix/tx_posix.h15
12 files changed, 243 insertions, 21 deletions
diff --git a/utility/benchmarks/thread_metric/tm_basic_processing_test.c b/utility/benchmarks/thread_metric/tm_basic_processing_test.c
index f1c4fa22..40ad8f53 100644
--- a/utility/benchmarks/thread_metric/tm_basic_processing_test.c
+++ b/utility/benchmarks/thread_metric/tm_basic_processing_test.c
@@ -41,7 +41,13 @@
/* Define the counters used in the demo application... */
-unsigned long tm_basic_processing_counter;
+/* volatile because the reporting thread reads this while the processing thread
+ below increments it. The processing loop calls nothing, so without volatile
+ the compiler is free to keep the counter in a register for the lifetime of an
+ infinite loop and never write it back: at -O2 it does exactly that, and the
+ report reads 0 forever. */
+
+volatile unsigned long tm_basic_processing_counter;
/* Test array. We will just do a series of calculations on the
@@ -98,7 +104,8 @@ void tm_basic_processing_initialize(void)
void tm_basic_processing_thread_0_entry(void)
{
-int i;
+int i;
+unsigned long snapshot;
/* Initialize the test array. */
for (i = 0; i < 1024; i++)
@@ -111,6 +118,15 @@ int i;
while(1)
{
+ /* Read the counter once per pass and use the copy in the loop below.
+ Reading the volatile counter inside the loop instead would add a
+ memory access to every one of the 1024 iterations and so change the
+ amount of work this test performs. That matters more here than
+ elsewhere in the suite: this test is the baseline the other results
+ are scaled against, so its throughput has to stay comparable with
+ previously published figures and with other RTOSes. */
+ snapshot = tm_basic_processing_counter;
+
/* Loop through the basic processing array, add the previous
contents with the contents of the tm_basic_processing_counter
and xor the result with the previous value... just to eat
@@ -119,11 +135,11 @@ int i;
{
/* Update each array entry. */
- tm_basic_processing_array[i] = (tm_basic_processing_array[i] + tm_basic_processing_counter) ^ tm_basic_processing_array[i];
+ tm_basic_processing_array[i] = (tm_basic_processing_array[i] + snapshot) ^ tm_basic_processing_array[i];
}
/* Increment the basic processing counter. */
- tm_basic_processing_counter++;
+ tm_basic_processing_counter = snapshot + 1;
}
}
diff --git a/utility/execution_profile_kit/smp_version/tx_execution_profile.c b/utility/execution_profile_kit/smp_version/tx_execution_profile.c
index 735dbf14..44e2b161 100644
--- a/utility/execution_profile_kit/smp_version/tx_execution_profile.c
+++ b/utility/execution_profile_kit/smp_version/tx_execution_profile.c
@@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
/**************************************************************************/
/**************************************************************************/
@@ -962,7 +963,7 @@ UINT core;
for (core = 0; core < TX_THREAD_SMP_MAX_CORES; core++)
{
- *total_time = _tx_execution_thread_time_total[core];
+ total_time[core] = _tx_execution_thread_time_total[core];
}
/* Restore interrupts. */
@@ -1025,7 +1026,7 @@ UINT core;
{
/* Return the total time. */
- *total_time = _tx_execution_isr_time_total[core];
+ total_time[core] = _tx_execution_isr_time_total[core];
}
/* Restore interrupts. */
@@ -1088,7 +1089,7 @@ UINT core;
{
/* Return the total time. */
- *total_time = _tx_execution_idle_time_total[core];
+ total_time[core] = _tx_execution_idle_time_total[core];
}
/* Restore interrupts. */
diff --git a/utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c b/utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c
index acac53cc..3391bf8a 100644
--- a/utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c
+++ b/utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c
@@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
+
/**************************************************************************/
/**************************************************************************/
/** */
@@ -348,6 +350,7 @@ TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
ret = tx_thread_create(&pxTaskBuffer->thread, (CHAR *)pcName, txfr_thread_wrapper, (ULONG)pvParameters,
puxStackBuffer, stack_depth_bytes, prio, prio, 0u, TX_DONT_START);
if(ret != TX_SUCCESS) {
+ (void)tx_semaphore_delete(&pxTaskBuffer->notification_sem);
TX_FREERTOS_ASSERT_FAIL();
return NULL;
}
@@ -356,6 +359,12 @@ TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
ret = tx_thread_resume(&pxTaskBuffer->thread);
if(ret != TX_SUCCESS) {
+ /* The thread exists but was never started. It has to be terminated
+ before it can be deleted, which is the order the idle task uses when
+ it reaps a deleted task. */
+ (void)tx_thread_terminate(&pxTaskBuffer->thread);
+ (void)tx_thread_delete(&pxTaskBuffer->thread);
+ (void)tx_semaphore_delete(&pxTaskBuffer->notification_sem);
TX_FREERTOS_ASSERT_FAIL();
return NULL;
}
@@ -643,7 +652,7 @@ void vTaskPrioritySet(TaskHandle_t xTask,
char *pcTaskGetName(TaskHandle_t xTaskToQuery)
{
TX_THREAD *p_thread;
- char *p_task_name;
+ const char *p_task_name;
UINT ret;
if(xTaskToQuery == NULL) {
@@ -658,7 +667,8 @@ char *pcTaskGetName(TaskHandle_t xTaskToQuery)
return 0;
}
- return p_task_name;
+ /* FreeRTOS exposes task names through a writable pointer type. */
+ return (char *)p_task_name;
}
@@ -1487,6 +1497,7 @@ QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
ret = tx_semaphore_create(&pxQueueBuffer->write_sem, "", uxQueueLength);
if(ret != TX_SUCCESS) {
+ (void)tx_semaphore_delete(&pxQueueBuffer->read_sem);
return NULL;
}
@@ -1543,11 +1554,16 @@ QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize)
ret = tx_semaphore_create(&p_queue->read_sem, "", 0u);
if(ret != TX_SUCCESS) {
+ txfr_free(p_mem);
+ txfr_free(p_queue);
return NULL;
}
ret = tx_semaphore_create(&p_queue->write_sem, "", uxQueueLength);
if(ret != TX_SUCCESS) {
+ (void)tx_semaphore_delete(&p_queue->read_sem);
+ txfr_free(p_mem);
+ txfr_free(p_queue);
return NULL;
}
diff --git a/utility/rtos_compatibility_layers/posix/CMakeLists.txt b/utility/rtos_compatibility_layers/posix/CMakeLists.txt
new file mode 100644
index 00000000..8cf3ab9a
--- /dev/null
+++ b/utility/rtos_compatibility_layers/posix/CMakeLists.txt
@@ -0,0 +1,130 @@
+# POSIX compatibility layer for ThreadX.
+#
+# This target is EXCLUDE_FROM_ALL: it is not part of the default build and is
+# only produced when something asks for it, either by name or by linking it.
+#
+# The include directory is deliberately PUBLIC. The layer ships replacements for
+# errno.h, fcntl.h, pthread.h, sched.h, signal.h and time.h, and application code
+# has to see those rather than a toolchain's own copies. That is also why the
+# layer cannot be used on the hosted simulation ports, where the C library
+# already supplies them; the top-level CMakeLists.txt skips it there.
+
+add_library(posix-threadx EXCLUDE_FROM_ALL)
+
+target_include_directories(posix-threadx
+ SYSTEM
+ PUBLIC
+ ${CMAKE_CURRENT_LIST_DIR}
+)
+
+target_sources(posix-threadx
+ PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/px_abs_time_to_rel_ticks.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_clock_getres.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_clock_gettime.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_clock_settime.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_broadcast.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_destroy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_signal.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_timedwait.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_cond_wait.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_error.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_in_thread_context.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_internal_signal_dispatch.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_memory_allocate.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_memory_release.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_arrange_msg.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_attr_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_close.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_create.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_find_queue.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_get_new_queue.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_get_queue_desc.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_open.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_priority_search.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_putback_queue.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_queue_delete.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_queue_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_receive.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_reset_queue.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_send.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mq_unlink.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_destroy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_getprotocol.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_getpshared.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_gettype.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_initi.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_setprotocol.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_setpshared.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_attr_settype.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_destroy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_lock.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_set_default_mutexattr.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_timedlock.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_trylock.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_mx_unlock.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_nanosleep.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_destroy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getdetachstate.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getinheritsched.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getschedparam.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getschedpolicy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getstack.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getstackaddr.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_getstacksize.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setdetachstate.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setinheritsched.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setschedparam.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setschedpolicyl.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setstack.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setstackaddr.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_attr_setstacksize.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_cancel.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_create.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_detach.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_equal.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_exit.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_getcanceltype.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_getschedparam.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_join.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_kill.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_once.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_self.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_set_default_pthread_attr.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_setcancelstate.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_setcanceltype.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_setschedparam.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_sigmask.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_testcancel.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_pth_yield.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_px_initialize.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sched_get_prio.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sched_yield.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_close.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_destroy.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_find_sem.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_get_new_sem.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_getvalue.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_init.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_open.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_post.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_reset.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_set_sem_name.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_trywait.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_unlink.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sem_wait.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_addset.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_delset.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_emptyset.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_fillset.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_signal.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sig_wait.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_sleep.c
+ ${CMAKE_CURRENT_LIST_DIR}/px_system_manager.c
+)
+
+target_link_libraries(posix-threadx PUBLIC threadx)
diff --git a/utility/rtos_compatibility_layers/posix/px_cond_broadcast.c b/utility/rtos_compatibility_layers/posix/px_cond_broadcast.c
index f9c8f151..fe54532c 100644
--- a/utility/rtos_compatibility_layers/posix/px_cond_broadcast.c
+++ b/utility/rtos_compatibility_layers/posix/px_cond_broadcast.c
@@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
/**************************************************************************/
/**************************************************************************/
@@ -91,7 +92,7 @@ UINT old_threshold,dummy;
/* Get the condition variable's internal semaphore. */
- /* Simply convert the condition variable control block into a semaphore a cast */
+ /* Simply convert the condition variable control block into a semaphore using casting. */
semaphore_ptr = (&( cond->cond_semaphore ));
sem_count = semaphore_ptr->tx_semaphore_suspended_count;
diff --git a/utility/rtos_compatibility_layers/posix/px_cond_destroy.c b/utility/rtos_compatibility_layers/posix/px_cond_destroy.c
index efa99be1..5f9d8f8a 100644
--- a/utility/rtos_compatibility_layers/posix/px_cond_destroy.c
+++ b/utility/rtos_compatibility_layers/posix/px_cond_destroy.c
@@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
/**************************************************************************/
/**************************************************************************/
@@ -80,7 +81,7 @@ UINT status;
{
cond->in_use = TX_FALSE;
/* Get the condition variable's internal semaphore. */
- /* Simply convert the Condition variable control block into a semaphore a cast */
+ /* Simply convert the condition variable control block into a semaphore using casting. */
semaphore_ptr = (&( cond->cond_semaphore ));
status = tx_semaphore_delete(semaphore_ptr);
if (status != TX_SUCCESS)
diff --git a/utility/rtos_compatibility_layers/posix/px_cond_init.c b/utility/rtos_compatibility_layers/posix/px_cond_init.c
index b376132d..27bfd41d 100644
--- a/utility/rtos_compatibility_layers/posix/px_cond_init.c
+++ b/utility/rtos_compatibility_layers/posix/px_cond_init.c
@@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
/**************************************************************************/
/**************************************************************************/
@@ -72,7 +73,7 @@ UINT status;
cond->in_use = TX_TRUE;
/* Get the condition variable's internal semaphore. */
- /* Simply convert the COndition variable control block into a semaphore a cast */
+ /* Simply convert the condition variable control block into a semaphore using casting. */
semaphore_ptr = (&( cond->cond_semaphore ));
/* Now create the internal semaphore for this cond variable */
status = tx_semaphore_create(semaphore_ptr,"csem",0);
diff --git a/utility/rtos_compatibility_layers/posix/px_cond_signal.c b/utility/rtos_compatibility_layers/posix/px_cond_signal.c
index b1f4f285..611202ac 100644
--- a/utility/rtos_compatibility_layers/posix/px_cond_signal.c
+++ b/utility/rtos_compatibility_layers/posix/px_cond_signal.c
@@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
/**************************************************************************/
/**************************************************************************/
@@ -84,7 +85,7 @@ TX_SEMAPHORE *semaphore_ptr;
UINT status;
/* Get the condition variable's internal semaphore. */
- /* Simply convert the COndition variable control block into a semaphore a cast */
+ /* Simply convert the condition variable control block into a semaphore using casting. */
semaphore_ptr = (&( cond->cond_semaphore ));
if ( semaphore_ptr->tx_semaphore_suspended_count)
{
diff --git a/utility/rtos_compatibility_layers/posix/px_mq_send.c b/utility/rtos_compatibility_layers/posix/px_mq_send.c
index 464af01f..f641419a 100644
--- a/utility/rtos_compatibility_layers/posix/px_mq_send.c
+++ b/utility/rtos_compatibility_layers/posix/px_mq_send.c
@@ -60,6 +60,7 @@
/* */
/* tx_thread_identify returns currently running thread */
/* tx_byte_allocate allocate memory */
+/* tx_byte_release release memory */
/* tx_queue_send ThreadX queue send */
/* posix_priority_search search message for same priority */
/* */
@@ -166,7 +167,16 @@ ULONG msg[TX_POSIX_MESSAGE_SIZE];
if (temp1 != TX_SUCCESS)
{
- posix_internal_error(9999);
+ posix_internal_error(9999);
+
+ /* posix_internal_error() does not return today, but do not depend on
+ that: bp is indeterminate here, so falling through would copy
+ msg_len bytes through an unset pointer. */
+ posix_errno = ENOMEM;
+ posix_set_pthread_errno(ENOMEM);
+
+ /* Return ERROR. */
+ return(ERROR);
}
/* Got the memory , Setup source and destination pointers
Cast them in UCHAR as message length is in bytes. */
@@ -201,9 +211,14 @@ ULONG msg[TX_POSIX_MESSAGE_SIZE];
temp1 = tx_queue_send(Queue, msg, TX_WAIT_FOREVER);
if ( temp1 != TX_SUCCESS)
{
+ /* The message was never handed over to the queue, so this function
+ still owns the private buffer. Release it before returning,
+ otherwise it is leaked from the queue's byte pool. */
+ tx_byte_release(bp);
+
/* POSIX doesn't have error for this, hence give default. */
posix_errno = EINTR ;
- posix_set_pthread_errno(EINTR);
+ posix_set_pthread_errno(EINTR);
/* Return ERROR. */
return(ERROR);
diff --git a/utility/rtos_compatibility_layers/posix/px_pth_init.c b/utility/rtos_compatibility_layers/posix/px_pth_init.c
index 5d2f36ad..ff0a01a9 100644
--- a/utility/rtos_compatibility_layers/posix/px_pth_init.c
+++ b/utility/rtos_compatibility_layers/posix/px_pth_init.c
@@ -538,12 +538,30 @@ POSIX_TCB *p_tcb;
if (!thread_ptr)
{
/* Not called from a thread - error! */
- posix_internal_error(222);
+ posix_internal_error(222);
+
+ /* posix_internal_error() does not return today, but do not depend on
+ that: posix_thread2tcb() hands back NULL for this input and the read
+ below would dereference it. A pthread ID is the address of the TCB,
+ so zero is never a valid one. */
+ return((pthread_t) 0);
}
/* Get the TCB for this pthread */
p_tcb = posix_thread2tcb(thread_ptr);
+
+ /* A running ThreadX thread that was not created through pthread_create()
+ has no TCB in the pool, and posix_thread2tcb() returns NULL for it. It
+ has no pthread ID either, so report zero rather than reading through the
+ null pointer. Zero can never collide with a real ID, because
+ px_pth_create.c uses the address of the TCB as the ID. */
+ if (!p_tcb)
+ {
+
+ return((pthread_t) 0);
+ }
+
thread_ID = p_tcb->pthreadID;
/* All done. */
diff --git a/utility/rtos_compatibility_layers/posix/px_pth_self.c b/utility/rtos_compatibility_layers/posix/px_pth_self.c
index fd876459..2272fa31 100644
--- a/utility/rtos_compatibility_layers/posix/px_pth_self.c
+++ b/utility/rtos_compatibility_layers/posix/px_pth_self.c
@@ -74,12 +74,21 @@ pthread_t thread_ID;
thread_ID = posix_thread2tid(thread_ptr);
- /* Determine if this thread is actually the signal thread helper. */
- if (((POSIX_TCB *) thread_ptr) -> signals.signal_handler)
+ /* Only a pthread has the signal fields read below: they belong to the
+ POSIX_TCB that surrounds the thread, and reading them through anything
+ else runs off the end of a plain TX_THREAD. A zero ID means the caller
+ is not a pthread, either because it is a ThreadX thread created directly
+ or because there is no current thread at all, so leave it alone. */
+ if (thread_ID != (pthread_t) 0)
{
- /* Yes, override the thread_ID with the non-signal thread ID. */
- thread_ID = (pthread_t) ((POSIX_TCB *) thread_ptr) -> signals.base_thread_ptr;
+ /* Determine if this thread is actually the signal thread helper. */
+ if (((POSIX_TCB *) thread_ptr) -> signals.signal_handler)
+ {
+
+ /* Yes, override the thread_ID with the non-signal thread ID. */
+ thread_ID = (pthread_t) ((POSIX_TCB *) thread_ptr) -> signals.base_thread_ptr;
+ }
}
diff --git a/utility/rtos_compatibility_layers/posix/tx_posix.h b/utility/rtos_compatibility_layers/posix/tx_posix.h
index ce533dd8..3f235cb9 100644
--- a/utility/rtos_compatibility_layers/posix/tx_posix.h
+++ b/utility/rtos_compatibility_layers/posix/tx_posix.h
@@ -278,9 +278,22 @@ typedef struct pthread_attr_obj
} pthread_attr_t;
-typedef INT ssize_t ; /* this should be pulled in from sys\types.h */
+/* ssize_t and mode_t belong to <sys/types.h>. A C library that has already
+ declared them wins: it knows the target's real widths, and on an LP64 target
+ ssize_t is 64 bits while INT is not. newlib guards each type with its own
+ _*_DECLARED macro, so honour those and only define what is missing. A port
+ whose library uses different guards can predefine them to the same effect. */
+#ifndef _SSIZE_T_DECLARED
+typedef INT ssize_t ;
+#define _SSIZE_T_DECLARED
+#endif
+
typedef ALIGN_TYPE pthread_t;
+
+#ifndef _MODE_T_DECLARED
typedef ULONG mode_t;
+#define _MODE_T_DECLARED
+#endif