Index: lib/libpthread/thrd.c =================================================================== RCS file: /cvsroot/src/lib/libpthread/thrd.c,v retrieving revision 1.2 diff -u -r1.2 thrd.c --- lib/libpthread/thrd.c 24 Apr 2019 18:47:54 -0000 1.2 +++ lib/libpthread/thrd.c 29 Apr 2019 16:49:57 -0000 @@ -36,24 +36,61 @@ #include #include #include +#include #include #include +struct __thrd_tramp_data { + thrd_start_t func; + void *arg; +}; + +static void * +__thrd_create_tramp(void *arg) +{ + struct __thrd_tramp_data *cookie; + int ret; + + _DIAGASSERT(arg != NULL); + + cookie = (struct __thrd_tramp_data *)arg; + + ret = (cookie->func)(cookie->arg); + + free(cookie); + + return (void *)(intptr_t)ret; +} + int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { + struct __thrd_tramp_data *cookie; + int error; _DIAGASSERT(thr != NULL); _DIAGASSERT(func != NULL); - switch(pthread_create(thr, NULL, (void *(*)(void *))func, arg)) { + cookie = malloc(sizeof(*cookie)); + if (cookie != NULL) + return thrd_nomem; + + cookie->func = func; + cookie->arg = arg; + + switch(pthread_create(thr, NULL, __thrd_create_tramp, cookie)) { case 0: return thrd_success; - case EAGAIN: - return thrd_nomem; + case ENOMEM: + error = thrd_nomem; + break; default: - return thrd_error; + error = thrd_error; } + + free(cookie); + + return error; } thrd_t