https://gcc.gnu.org/g:3af8760505bedeca17283ca9f7daca8e53b50eb9

commit r17-6027-g3af8760505bedeca17283ca9f7daca8e53b50eb9
Author: Alexandre Oliva <[email protected]>
Date:   Sat Dec 6 01:18:48 2025 -0300

    [vxworks] Straighten the VxWorks task_wrapper API for __gthread_create
    
    The gthread API has thread entry points receiving and returning void*.
    VxWorks' task creation uses different conventions, so gthr-vxworks-thread.c
    resorts to a __task_wrapper adaptor.
    
    __task_wrapper currently receives the gthread_create entry point argument
    directly as if it had the VxWorks signature, which is conceptually incorrect
    and causes real trouble with int/void* conversions on powerpc64.
    
    This patch corrects the internal declarations to use more accurate
    interface types and adjusts the wrapper implementation to perform explicit
    conversions as needed.
    
    libgcc/
    
            * config/gthr-vxworks-thread.c (ENTRYPTR): Rename to...
            (__gthread_entry_point_t): ... this.  Use gthread
            conventions.  Drop indirection.
            (__task_wrapper): Use VxWorks conventions for its formals,
            and convert to the gthread types.  Drop extraneous and risky
            double-underscore prefixes.  Add indirection to entry point
            pointer.
            (__gthread_create): Use __gthread_entry_point_t.

Diff:
---
 libgcc/config/gthr-vxworks-thread.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libgcc/config/gthr-vxworks-thread.c 
b/libgcc/config/gthr-vxworks-thread.c
index c8646eb523b6..f5fcfe218240 100644
--- a/libgcc/config/gthr-vxworks-thread.c
+++ b/libgcc/config/gthr-vxworks-thread.c
@@ -29,10 +29,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
 #include "gthr.h"
 
-typedef STATUS (* ENTRYPTR) (int);
-
 #if __GTHREADS_CXX0X
 
+typedef void *__gthread_entry_point_t (void *);
+
 #include <taskLib.h>
 #include <stdlib.h>
 #include <string.h>
@@ -258,9 +258,14 @@ __gthread_self (void)
   return __local_tcb;
 }
 
+/* VxWorks taskCreate adaptor to __gthread_create conventions.  */
 static int
-__task_wrapper (__gthread_t tcb, ENTRYPTR __func, _Vx_usr_arg_t __args)
+__task_wrapper (_Vx_usr_arg_t tcb_, _Vx_usr_arg_t func_, _Vx_usr_arg_t args_)
 {
+  __gthread_t tcb = (__gthread_t) tcb_;
+  __gthread_entry_point_t *func = (__gthread_entry_point_t *) func_;
+  void *args = (void *) args_;
+
   if (!tcb)
     return ERROR;
 
@@ -268,9 +273,9 @@ __task_wrapper (__gthread_t tcb, ENTRYPTR __func, 
_Vx_usr_arg_t __args)
 
   /* We use this variable to avoid memory leaks in the case where
      the underlying function throws an exception.  */
-  __attribute__ ((cleanup (__delete_gthread_tcb))) __gthread_t __tmp = tcb;
+  __attribute__ ((cleanup (__delete_gthread_tcb))) __gthread_t tmp = tcb;
 
-  void *return_value = (void *) __func (__args);
+  void *return_value = func (args);
   tcb->return_value = return_value;
 
   /* Call the destructors.  */
@@ -291,7 +296,7 @@ __task_wrapper (__gthread_t tcb, ENTRYPTR __func, 
_Vx_usr_arg_t __args)
 /* Proper gthreads API.  */
 
 int
-__gthread_create (__gthread_t * __threadid, void *(*__func) (void *),
+__gthread_create (__gthread_t * __threadid, __gthread_entry_point_t __func,
                  void *__args)
 {
   if (!__threadid)

Reply via email to