Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions library/include/uchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define _UCHAR_H

#include <features.h>
#include <stddef.h>
#include <wchar.h>

__BEGIN_DECLS

Expand All @@ -10,9 +12,6 @@ typedef unsigned short char16_t;
typedef unsigned char32_t;
#endif

#define __NEED_mbstate_t
#define __NEED_size_t

extern size_t c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict);
extern size_t mbrtoc16(char16_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict);

Expand Down
18 changes: 12 additions & 6 deletions library/pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,13 @@ int __pthread_init_func(void) {
// reserve ID 0 for the main thread
ThreadInfo *inf = &threads[0];

set_tls_register(inf);

inf->task = (struct Process *) FindTask(NULL);
inf->status = THREAD_STATE_RUNNING;
NewMinList(&inf->cleanup);

timerMutex = AllocSysObjectTags(ASOT_MUTEX, ASOMUTEX_Recursive, TRUE, TAG_DONE);

timedTimerPort = AllocSysObject(ASOT_PORT, NULL);
timedTimerPort = AllocSysObjectTags(ASOT_PORT, TAG_DONE);
timedTimerIO = AllocSysObjectTags(ASOT_IOREQUEST,
ASOIOR_ReplyPort, timedTimerPort,
ASOIOR_Size, sizeof(struct TimeRequest),
Expand All @@ -299,6 +297,8 @@ int __pthread_init_func(void) {
inf->status = THREAD_STATE_IDLE;
}

set_tls_register(inf);

return TRUE;
}

Expand All @@ -307,15 +307,21 @@ void __pthread_exit_func(void) {
ThreadInfo *inf;
struct DOSIFace *IDOS = _IDOS;

if (timerMutex)
if (timerMutex) {
FreeSysObject(ASOT_MUTEX, timerMutex);
timerMutex = NULL;
}

if (timedTimerIO)
CloseDevice((struct IORequest *) timedTimerIO);
if (timedTimerIO)
if (timedTimerIO) {
FreeSysObject(ASOT_IOREQUEST, timedTimerIO);
if (timedTimerPort)
timedTimerIO = NULL;
}
if (timedTimerPort) {
FreeSysObject(ASOT_PORT, timedTimerPort);
timedTimerPort = NULL;
}

// if we don't do this we can easily end up with unloaded code being executed
for (i = PTHREAD_FIRST_THREAD_ID; i < PTHREAD_THREADS_MAX; i++) {
Expand Down
2 changes: 1 addition & 1 deletion library/pthread/pthread_getspecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pthread_getspecific(pthread_key_t key) {
ThreadInfo *inf;
void *value = NULL;

if (key >= PTHREAD_KEYS_MAX)
if (key >= PTHREAD_KEYS_MAX || key < 0)
return NULL;

inf = GetCurrentThreadInfo();
Expand Down
2 changes: 1 addition & 1 deletion library/pthread/pthread_key_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int
pthread_key_delete(pthread_key_t key) {
TLSKey *tls;

if (key >= PTHREAD_KEYS_MAX)
if (key >= PTHREAD_KEYS_MAX || key < 0)
return EINVAL;

tls = &tlskeys[key];
Expand Down
2 changes: 1 addition & 1 deletion library/pthread/pthread_setspecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int
pthread_setspecific(pthread_key_t key, const void *value) {
ThreadInfo *inf;

if (key >= PTHREAD_KEYS_MAX)
if (key >= PTHREAD_KEYS_MAX || key < 0)
return EINVAL;

inf = GetCurrentThreadInfo();
Expand Down
Loading