From 9219d330e9b25573d0ce897407e259f684a7c5d0 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Wed, 16 Dec 2015 17:38:31 -0800 Subject: [PATCH] Expose the per-thread errno variable --- include/errno.h | 5 +++++ lib/libc/posix/pthread.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/errno.h b/include/errno.h index 691236a..e603073 100644 --- a/include/errno.h +++ b/include/errno.h @@ -2,6 +2,11 @@ #ifndef __ERRNO_H__ #define __ERRNO_H__ +#ifndef _KERNEL +int *__error(); +#define errno (* __error()) +#endif + #define EIO 0x1BAD0001 #define EBADF 0x1BAD0002 #define EINVAL 0x1BAD0003 diff --git a/lib/libc/posix/pthread.c b/lib/libc/posix/pthread.c index 3aa0c57..9b73058 100644 --- a/lib/libc/posix/pthread.c +++ b/lib/libc/posix/pthread.c @@ -20,7 +20,7 @@ struct pthread_attr { struct pthread { uint64_t tid; - int errno; + int error; // errno TAILQ_ENTRY(pthread) threadTable; // Initialization @@ -41,6 +41,14 @@ typedef TAILQ_HEAD(pthreadList, pthread) pthreadList; static CoreMutex __threadTableLock; static pthreadList __threads[THREAD_HASH_SLOTS]; +int * +__error(void) +{ + struct pthread *pth = pthread_self(); + + return &(pth->error); +} + void __pthread_init(void) { @@ -56,6 +64,7 @@ __pthread_init(void) } thr->tid = OSGetTID(); + thr->error = 0; thr->entry = NULL; thr->arg = 0;