Expose the per-thread errno variable

This commit is contained in:
Ali Mashtizadeh 2015-12-16 17:38:31 -08:00
parent 7bc8169ff2
commit 9219d330e9
2 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,11 @@
#ifndef __ERRNO_H__ #ifndef __ERRNO_H__
#define __ERRNO_H__ #define __ERRNO_H__
#ifndef _KERNEL
int *__error();
#define errno (* __error())
#endif
#define EIO 0x1BAD0001 #define EIO 0x1BAD0001
#define EBADF 0x1BAD0002 #define EBADF 0x1BAD0002
#define EINVAL 0x1BAD0003 #define EINVAL 0x1BAD0003

View File

@ -20,7 +20,7 @@ struct pthread_attr {
struct pthread { struct pthread {
uint64_t tid; uint64_t tid;
int errno; int error; // errno
TAILQ_ENTRY(pthread) threadTable; TAILQ_ENTRY(pthread) threadTable;
// Initialization // Initialization
@ -41,6 +41,14 @@ typedef TAILQ_HEAD(pthreadList, pthread) pthreadList;
static CoreMutex __threadTableLock; static CoreMutex __threadTableLock;
static pthreadList __threads[THREAD_HASH_SLOTS]; static pthreadList __threads[THREAD_HASH_SLOTS];
int *
__error(void)
{
struct pthread *pth = pthread_self();
return &(pth->error);
}
void void
__pthread_init(void) __pthread_init(void)
{ {
@ -56,6 +64,7 @@ __pthread_init(void)
} }
thr->tid = OSGetTID(); thr->tid = OSGetTID();
thr->error = 0;
thr->entry = NULL; thr->entry = NULL;
thr->arg = 0; thr->arg = 0;