Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
107cfed
Wrong Printf version requirement printing
afxgroup Jan 28, 2025
5b66b34
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Apr 15, 2025
c7de956
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 11, 2025
183789d
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 18, 2025
8eb5426
Small profile fixes
afxgroup Jun 20, 2025
275ac3f
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 22, 2025
e4eee2e
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 28, 2025
838afc6
Fixed crash when debug is enabled
afxgroup Jun 29, 2025
065856b
Merge branch 'development' of github.com:AmigaLabs/clib4 into mutexes
afxgroup Jun 29, 2025
4d264b8
Semaphores are replaced by Mutexes when possible
afxgroup Jun 29, 2025
27e537e
Reworked ctype implementation using newlib one
afxgroup Jul 1, 2025
100e8f2
don't call check_abort in stdio functions that are calling it already…
afxgroup Jul 2, 2025
427448d
ctype functions was using wrong _P define (while ctype inline #define…
afxgroup Jul 2, 2025
f470c36
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Jul 3, 2025
d737595
More optimizations on I/O functions that avoid useless check abort calls
afxgroup Jul 5, 2025
74744ce
More optimizations to I/O operations. Now stdout and stderr are fully…
afxgroup Jul 5, 2025
9a83362
Some more optimizations
afxgroup Jul 18, 2025
0909757
more read fixes
afxgroup Jul 27, 2025
91fb653
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Jul 27, 2025
7c565c2
Fixed an error on pthreds was causing DSI in some occasions. Small fixes
afxgroup Jul 29, 2025
376d5eb
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Jul 29, 2025
9ff4fe2
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Aug 1, 2025
43a9caf
Fixed a problem cased by wrong Input/Output/Error streams created bef…
afxgroup Aug 5, 2025
5907b1b
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Aug 6, 2025
33d5b28
Merge branch 'development' of github.com:AmigaLabs/clib4 into ctype
afxgroup Aug 7, 2025
a3468f7
Speedup lookup_name function was loading and parsing resolv conf file…
afxgroup Aug 12, 2025
d53f21a
Fixed fopen was slowing down due a mistake on file buffer.
afxgroup Aug 14, 2025
e1d0855
Replaced Semaphores with Mutexes in pthread library
afxgroup Aug 16, 2025
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
1 change: 0 additions & 1 deletion library/crtbegin.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ clib4_start(char *args, const int32 arglen, struct Library *sysbase) {
struct MsgPort *mp = &me->pr_MsgPort;
iexec->WaitPort(mp);
sms = (struct WBStartup *) iexec->GetMsg(mp);
iexec->DebugPrintF("<crtbegin> : NumArgs == %ld\n", sms->sm_NumArgs);
}

IExec = iexec;
Expand Down
5 changes: 2 additions & 3 deletions library/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ struct _clib4 {
BOOL __current_directory_changed;
BOOL __unlock_current_directory;

/* Memalign memory list */
void *unused2;
void *unused3;
APTR __environment_lock;
void *resolv_conf; //struct resolvconf

/*
* This variable can be set up to contain the minimum stack size the program
Expand Down
4 changes: 2 additions & 2 deletions library/fcntl/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ __open_r(struct _clib4 *__clib4, const char *path_name, int open_flag, ... /* mo
SET_FLAG(fd->fd_Flags, FDF_CREATED);
}
if (FLAG_IS_SET(open_flag, O_LITTLE_ENDIAN)) {
DebugPrintF("open() called with Little Endian mode\n");
DebugPrintF("%ld\n", fd_slot_number);
SHOWMSG("open() called with Little Endian mode\n");
D(("%ld\n", fd_slot_number));
SET_FLAG(fd->fd_Flags, FDF_LITTLE_ENDIAN);
}

Expand Down
2 changes: 1 addition & 1 deletion library/fcntl/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ read(int file_descriptor, void *buffer, size_t num_bytes) {

struct fd *fd = __get_file_descriptor(__clib4, file_descriptor);
if (!FLAG_IS_SET(fd->fd_Flags, FDF_IS_SOCKET) && FLAG_IS_SET(fd->fd_Flags, FDF_LITTLE_ENDIAN)) {
DebugPrintF("[read] Reading in Little endian mode\n");
SHOWMSG("[read] Reading in Little endian mode\n");
if (num_bytes == 2) {
byteswap16(buffer);
} else if (num_bytes == 4) {
Expand Down
4 changes: 3 additions & 1 deletion library/include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <sys/time.h>
#endif /* _SYS_TIME_H */

#include <fcntl.h>

#include <features.h>

__BEGIN_DECLS
Expand Down Expand Up @@ -49,7 +51,7 @@ typedef unsigned char sa_family_t;

#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0 /* for now set bot to 0 */
#define SOCK_NONBLOCK 0
#define SOCK_NONBLOCK O_NONBLOCK
#endif

/*
Expand Down
26 changes: 19 additions & 7 deletions library/libc_init_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <proto/elf.h>
#include <fenv.h>

#include "resolv/lookup.h"

extern struct ElfIFace *__IElf;
extern struct Library *__ElfBase;

Expand Down Expand Up @@ -150,28 +152,35 @@ reent_init(struct _clib4 *__clib4, const BOOL fallback) {
._iob_pool = NULL,
.isTZSet = 0,
.__IDebug = NULL,
.resolv_conf = NULL,
};

if (!__clib4->__random_lock || !__clib4->__pipe_semaphore) {
goto out;
}

SHOWMSG("Allocating file IO pool");
__clib4->_iob_pool = AllocSysObjectTags(ASOT_MEMPOOL,
ASOPOOL_Puddle, BUFSIZ + 32,
ASOPOOL_Threshold, BUFSIZ + 32,
__clib4->_iob_pool = AllocSysObjectTags(ASOT_ITEMPOOL,
ASOITEM_MFlags, MEMF_ANY | MEMF_CLEAR,
ASOITEM_ItemSize, BUFSIZ + 32,
TAG_DONE);
if (!__clib4->_iob_pool) {
goto out;
}
DebugPrintF("Allocated file IO pool. _iob_pool : 0x%lx\n", __clib4->_iob_pool);
D(("Allocated file IO pool. _iob_pool : 0x%lx\n", __clib4->_iob_pool));

SHOWMSG("Allocating wide_status");
/* Initialize wchar stuff */
__clib4->wide_status = AllocVecTags(sizeof(struct _wchar), AVT_Type, MEMF_SHARED, TAG_DONE);
if (!__clib4->wide_status) {
goto out;
}

__clib4->resolv_conf = AllocVecTags(sizeof(struct resolvconf), AVT_Type, MEMF_SHARED, AVT_ClearWithValue, 0, TAG_DONE);
if (!__clib4->resolv_conf) {
goto out;
}

__clib4->wide_status->_strtok_last = NULL;
__clib4->wide_status->_mblen_state.__count = 0;
__clib4->wide_status->_mblen_state.__value.__wch = 0;
Expand Down Expand Up @@ -270,11 +279,14 @@ void
reent_exit(struct _clib4 *__clib4) {
/* Free global clib structure */
if (__clib4) {
if (__clib4->resolv_conf != NULL) {
FreeVec(__clib4->resolv_conf);
__clib4->resolv_conf = NULL;
}
/* Free IO memory pool */
if (__clib4->_iob_pool != NULL) {
SHOWMSG("Freeing _iob_pool and all unfreed memory");
DebugPrintF("Freeing _iob_pool and all unfreed memory. _iob_pool : 0x%lx\n", __clib4->_iob_pool);
FreeSysObject(ASOT_MEMPOOL, __clib4->_iob_pool);
D(("Freeing _iob_pool and all unfreed memory. _iob_pool : 0x%lx\n", __clib4->_iob_pool));
FreeSysObject(ASOT_ITEMPOOL, __clib4->_iob_pool);
}

/* Free wchar stuff */
Expand Down
4 changes: 2 additions & 2 deletions library/pthread/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ typedef struct {
extern struct Library *_DOSBase;
extern struct DOSIFace *_IDOS;

extern struct SignalSemaphore thread_sem;
extern APTR thread_sem;
extern ThreadInfo threads[PTHREAD_THREADS_MAX];
extern struct SignalSemaphore tls_sem;
extern APTR tls_sem;
extern TLSKey tlskeys[PTHREAD_KEYS_MAX];
extern APTR timerMutex;
extern struct TimeRequest *timedTimerIO;
Expand Down
21 changes: 16 additions & 5 deletions library/pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void __attribute__((constructor, used)) __pthread_init();
void __attribute__((destructor, used)) __pthread_exit();

ThreadInfo threads[PTHREAD_THREADS_MAX];
struct SignalSemaphore thread_sem;
APTR thread_sem = NULL;
TLSKey tlskeys[PTHREAD_KEYS_MAX];
struct SignalSemaphore tls_sem;
APTR tls_sem = NULL;
APTR timerMutex = NULL;
struct TimeRequest *timedTimerIO = NULL;
struct MsgPort *timedTimerPort = NULL;
Expand Down Expand Up @@ -269,10 +269,11 @@ static void set_tls_register(ThreadInfo *ti) {

int __pthread_init_func(void) {
pthread_t i;
SHOWMSG("[__pthread_init_func :] Pthread __pthread_init_func called.\n");

memset(&threads, 0, sizeof(threads));
InitSemaphore(&thread_sem);
InitSemaphore(&tls_sem);
thread_sem = AllocSysObjectTags(ASOT_MUTEX, ASOMUTEX_Recursive, TRUE, TAG_DONE);
tls_sem = AllocSysObjectTags(ASOT_MUTEX, ASOMUTEX_Recursive, TRUE, TAG_DONE);

// reserve ID 0 for the main thread
ThreadInfo *inf = &threads[0];
Expand Down Expand Up @@ -306,7 +307,16 @@ void __pthread_exit_func(void) {
pthread_t i;
ThreadInfo *inf;
struct DOSIFace *IDOS = _IDOS;
SHOWMSG("[__pthread_exit_func :] Pthread __pthread_exit_func called.\n");

if (thread_sem) {
FreeSysObject(ASOT_MUTEX, thread_sem);
thread_sem = NULL;
}
if (tls_sem) {
FreeSysObject(ASOT_MUTEX, tls_sem);
tls_sem = NULL;
}
if (timerMutex) {
FreeSysObject(ASOT_MUTEX, timerMutex);
timerMutex = NULL;
Expand Down Expand Up @@ -340,7 +350,7 @@ void __pthread_exit_func(void) {

PTHREAD_CONSTRUCTOR(__pthread_init) {
ENTER();
DebugPrintF("[__pthread_init :] Pthread constructor called.\n");
SHOWMSG("[__pthread_init :] Pthread constructor called.\n");
_DOSBase = OpenLibrary("dos.library", MIN_OS_VERSION);
if (_DOSBase) {
_IDOS = (struct DOSIFace *) GetInterface((struct Library *) _DOSBase, "main", 1, NULL);
Expand All @@ -356,6 +366,7 @@ PTHREAD_CONSTRUCTOR(__pthread_init) {

PTHREAD_DESTRUCTOR(__pthread_exit) {
ENTER();
SHOWMSG("[__pthread_exit :] Pthread destructor called.\n");
if (_DOSBase != NULL) {
CloseLibrary(_DOSBase);
_DOSBase = NULL;
Expand Down
2 changes: 2 additions & 0 deletions library/pthread/pthread_cleanup_push.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pthread_cleanup_push(void (*routine)(void *), void *arg) {
return;

inf = GetCurrentThreadInfo();
if (!inf)
return;

handler->routine = routine;
handler->arg = arg;
Expand Down
16 changes: 8 additions & 8 deletions library/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

extern struct DOSIFace *_IDOS;

static inline void set_tls_register(ThreadInfo *ti) {
static void set_tls_register(ThreadInfo *ti) {
__asm__ volatile("mr r2, %0" :: "r"(ti));
}

Expand Down Expand Up @@ -80,7 +80,7 @@ StarterFunc() {

// destroy all non-NULL TLS key values
// since the destructors can set the keys themselves, we have to do multiple iterations
ObtainSemaphoreShared(&tls_sem);
MutexObtain(tls_sem);
for (int j = 0; keyFound && j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) {
keyFound = FALSE;
for (int i = 0; i < PTHREAD_KEYS_MAX; i++) {
Expand All @@ -92,7 +92,7 @@ StarterFunc() {
}
}
}
ReleaseSemaphore(&tls_sem);
MutexRelease(tls_sem);

if (stackSwapped)
StackSwap(&stack);
Expand All @@ -104,9 +104,9 @@ StarterFunc() {
Signal((struct Task *) inf->parent, SIGF_PARENT);
} else {
// no one is waiting for us, do the clean up
ObtainSemaphore(&thread_sem);
MutexObtain(thread_sem);
_pthread_clear_threadinfo(inf);
ReleaseSemaphore(&thread_sem);
MutexRelease(thread_sem);
}

return RETURN_OK;
Expand All @@ -125,12 +125,12 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(voi
return EINVAL;

// grab an empty thread slot
ObtainSemaphore(&thread_sem);
MutexObtain(thread_sem);
threadnew = GetThreadId(NULL);
ReleaseSemaphore(&thread_sem);
MutexRelease(thread_sem);

if (threadnew == PTHREAD_THREADS_MAX) {
ReleaseSemaphore(&thread_sem);
MutexRelease(thread_sem);
return EAGAIN;
}

Expand Down
4 changes: 2 additions & 2 deletions library/pthread/pthread_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ pthread_join(pthread_t thread, void **value_ptr) {
if (value_ptr)
*value_ptr = inf->ret;

ObtainSemaphore(&thread_sem);
MutexObtain(thread_sem);
_pthread_clear_threadinfo(inf);
ReleaseSemaphore(&thread_sem);
MutexRelease(thread_sem);

return 0;
}
6 changes: 3 additions & 3 deletions library/pthread/pthread_key_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) {
if (key == NULL)
return EINVAL;

ObtainSemaphore(&tls_sem);
MutexObtain(tls_sem);

for (i = 0; i < PTHREAD_KEYS_MAX; i++) {
if (tlskeys[i].used == FALSE)
break;
}

if (i == PTHREAD_KEYS_MAX) {
ReleaseSemaphore(&tls_sem);
MutexRelease(tls_sem);
return EAGAIN;
}

tls = &tlskeys[i];
tls->used = TRUE;
tls->destructor = destructor;

ReleaseSemaphore(&tls_sem);
MutexRelease(tls_sem);

*key = i;

Expand Down
6 changes: 3 additions & 3 deletions library/pthread/pthread_key_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ pthread_key_delete(pthread_key_t key) {

tls = &tlskeys[key];

ObtainSemaphore(&tls_sem);
MutexObtain(tls_sem);

if (tls->used == FALSE) {
ReleaseSemaphore(&tls_sem);
MutexRelease(tls_sem);
return EINVAL;
}

tls->used = FALSE;
tls->destructor = NULL;

ReleaseSemaphore(&tls_sem);
MutexRelease(tls_sem);

return 0;
}
1 change: 1 addition & 0 deletions library/resolv/lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct resolvconf {
struct address ns[MAXNS];
unsigned nns, attempts, ndots;
unsigned timeout;
int loaded;
};

/* The limit of 48 results is a non-sharp bound on the number of addresses
Expand Down
16 changes: 10 additions & 6 deletions library/resolv/lookup_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,20 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
static int
name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) {
char search[256];
struct resolvconf conf;
size_t l, dots;
char *p, *z;
if (__get_resolv_conf(&conf, search, sizeof search) < 0)
return -1;
struct _clib4 *__clib4 = __CLIB4;

if (((struct resolvconf *) __clib4->resolv_conf)->loaded == 0) {
if (__get_resolv_conf(__clib4->resolv_conf, search, sizeof search) < 0)
return -1;
((struct resolvconf *) __clib4->resolv_conf)->loaded = 1;
}

/* Count dots, suppress search when >=ndots or name ends in
* a dot, which is an explicit request for global scope. */
for (dots = l = 0; name[l]; l++) if (name[l] == '.') dots++;
if (dots >= conf.ndots || name[l - 1] == '.') *search = 0;
if (dots >= ((struct resolvconf *) __clib4->resolv_conf)->ndots || name[l - 1] == '.') *search = 0;

/* Strip final dot for canon, fail if multiple trailing dots. */
if (name[l - 1] == '.') l--;
Expand All @@ -219,13 +223,13 @@ name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256]
if ((size_t) (z - p) < 256 - l - 1) {
memcpy(canon + l + 1, p, z - p);
canon[z - p + 1 + l] = 0;
int cnt = name_from_dns(buf, canon, canon, family, &conf);
int cnt = name_from_dns(buf, canon, canon, family, __clib4->resolv_conf);
if (cnt) return cnt;
}
}

canon[l] = 0;
return name_from_dns(buf, canon, name, family, &conf);
return name_from_dns(buf, canon, name, family, __clib4->resolv_conf);
}

static const struct policy {
Expand Down
13 changes: 9 additions & 4 deletions library/resolv/res_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@

static int
__res_msend(int nqueries, const unsigned char *const *queries, const int *qlens, unsigned char *const *answers, int *alens, int asize) {
struct resolvconf conf;
if (__get_resolv_conf(&conf, 0, 0) < 0)
return -1;
return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf);
struct _clib4 *__clib4 = __CLIB4;

if (((struct resolvconf *) __clib4->resolv_conf)->loaded == 0) {
if (__get_resolv_conf(__clib4->resolv_conf, 0, 0) < 0)
return -1;
((struct resolvconf *) __clib4->resolv_conf)->loaded = 1;
}

return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, __clib4->resolv_conf);
}

int
Expand Down
Loading