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
2 changes: 1 addition & 1 deletion library/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ struct _clib4 {
struct SignalSemaphore *gettext_lock;
struct mofile_s *g_mofile;
char gettext_domain[NAME_MAX];
void *bindings;
void *volatile bindings;

/* getrandom */
int randfd[2];
Expand Down
9 changes: 9 additions & 0 deletions library/iconv/codepages.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,12 @@
"\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14"
"\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47"

"amiga1251\0"
"\0\51"
"\44\227\142\312\51\321\245\142\362\52\254\264\342\312\53\260\304\42\313\54"
"\264\324\142\313\55\37\346\242\313\56\274\364\342\313\57\337\201\27\236\170"
"\343\221\127\236\171\347\241\227\236\172\353\261\327\236\173"
"\357\301\27\237\174\363\321\127\237\175\367\341\227\237\176"
"\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201\7\42\230\240\202"
"\13\62\330\240\203\17\102\30\241\204\23\122\130\241\205\27\142\230\241\206"
"\33\162\330\241\207"
2 changes: 1 addition & 1 deletion library/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static unsigned
legacy_map(const unsigned char *map, unsigned char type, unsigned c) {
if (c < 4 * type) return c;
unsigned x = c - 4 * type;
x = map[x * 5 / 4] >> 2 * x % 8 | map[x * 5 / 4 + 1] << 8 - 2 * x % 8 & 1023;
x = map[x * 5 / 4] >> 2 * x % 8 | map[x * 5 / 4 + 1] << (8 - 2 * x % 8) & 1023;
return x < 256 ? x : legacy_chars[x - 256];
}

Expand Down
1 change: 0 additions & 1 deletion library/iconv/iconv_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ iconv_t
iconv_open(const char *to, const char *from) {
size_t f, t;
struct stateful_cd *scd;

if ((t = find_charmap(to)) == -1
|| (f = find_charmap(from)) == -1
|| (charmaps[t] >= 0330)) {
Expand Down
13 changes: 9 additions & 4 deletions library/locale/dcngettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,18 +712,23 @@ char *bindtextdomain(const char *domainname, const char *dirname) {
}

if (!p) {
p = calloc(1, sizeof *p + domlen + dirlen + 2);
p = __calloc_r(__clib4, 1, sizeof *p + domlen + dirlen + 2);
if (!p) {
ReleaseSemaphore(__clib4->gettext_lock);
return NULL;
}

p->next = __clib4->bindings;
p->dirlen = dirlen;
p->domainname = p->buf;
p->dirname = p->buf + domlen + 1;
memcpy(p->domainname, domainname, domlen+1);
memcpy(p->dirname, dirname, dirlen+1);
a_cas_p(&__clib4->bindings, __clib4->bindings, p);
__clib4->bindings = p;
/* For some reason using atomic operations here is causing a DSI but
* sice clib4 is reentrant should not be a problem using the assignment
* WAS: a_cas_p(&__clib4->bindings, __clib4->bindings, p);
*/
}

a_store(&p->active, 1);
Expand Down Expand Up @@ -781,14 +786,14 @@ CLIB_DESTRUCTOR(dcngettext_exit) {
while (mofile) {
struct mofile_s *next = mofile->next;
if (mofile)
FreeVec(mofile);
free(mofile);
mofile = next;
}
}
struct binding *p = __clib4->bindings;
while (p) {
struct binding *q = p->next;
FreeVec(p);
free(p);
p = q;
}
}
3 changes: 3 additions & 0 deletions library/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "common.h"
#include "pthread.h"

extern struct DOSIFace *_IDOS;

static uint32
StarterFunc() {
volatile int keyFound = TRUE;
Expand Down Expand Up @@ -110,6 +112,7 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(voi
size_t oldlen;
pthread_t threadnew;
struct Task *thisTask = FindTask(NULL);
struct DOSIFace *IDOS = _IDOS;

if (thread == NULL || start == NULL)
return EINVAL;
Expand Down
6 changes: 3 additions & 3 deletions library/rt/lio_listio.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ lio_listio_internal(int mode, struct aiocb *const list[], int nent, struct sigev

/* If any of the I/O requests failed, return -1 and set errno. */
if (result != 0) {
__set_errno(result == EINTR ? EINTR : EIO);
//__set_errno(result == EINTR ? EINTR : EIO);
result = -1;
}
} else {
Expand All @@ -127,7 +127,7 @@ lio_listio_internal(int mode, struct aiocb *const list[], int nent, struct sigev
+ (nent * sizeof(struct waitlist)));

if (waitlist == NULL) {
__set_errno(EAGAIN);
//__set_errno(EAGAIN);
result = -1;
} else {
total = 0;
Expand Down Expand Up @@ -164,7 +164,7 @@ int
lio_listio(int mode, struct aiocb *const list[], int nent, struct sigevent *sig) {
/* Check arguments. */
if (mode != LIO_WAIT && mode != LIO_NOWAIT) {
__set_errno(EINVAL);
//__set_errno(EINVAL);
return -1;
}

Expand Down
25 changes: 25 additions & 0 deletions library/stdio/vfprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ static const char xdigits[16] = {
"0123456789ABCDEF"
};

static const char bdigits[2] = {
"01"
};

static char *fmt_x(uintmax_t x, char *s, int lower) {
for (; x; x >>= 4) {
*--s = (char) (xdigits[(x & 15)] | lower);
}
return s;
}

static char *fmt_b(uintmax_t x, char *s, int lower) {
for (; x; x >>= 1) {
*--s = (char) (bdigits[(x & 1)] | lower);
}
return s;
}

static char *fmt_o(uintmax_t x, char *s) {
for (; x; x >>= 3) {
*--s = (char) ('0' + (x & 7));
Expand Down Expand Up @@ -593,6 +604,20 @@ static int printf_core(struct _clib4 *__clib4, Out *f, const char *fmt, va_list
fl &= ~ZERO_PAD;

switch (t) {
case 'b':
a = fmt_b(arg.i, z, t & 32);
if (arg.i && (fl & ALT_FORM))
prefix += (t >> 4), pl = 2;
if (xp && p < 0)
goto overflow;
if (xp)
fl &= ~ZERO_PAD;
if (!arg.i && !p) {
a = z;
break;
}
p = MAX(p, z - a + !arg.i);
break;
case 'n':
switch (ps) {
case _BARE:
Expand Down
113 changes: 21 additions & 92 deletions library/string/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,53 @@
#endif

#ifndef a_cas
#define a_cas a_cas

static inline int a_cas(volatile int *p, int t, int s) {
int old;
a_pre_llsc();
do old = a_ll(p);
while (old == t && !a_sc(p, s));
a_post_llsc();
return old;
}

#define a_cas(ptr, expected, desired) \
__atomic_compare_exchange(ptr, expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#endif

#ifndef a_swap
#define a_swap a_swap

static inline int a_swap(volatile int *p, int v) {
int old;
a_pre_llsc();
do old = a_ll(p);
while (!a_sc(p, v));
a_post_llsc();
return old;
}

#define a_swap(ptr, new_value) \
__atomic_exchange_n(ptr, new_value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_add
#define a_fetch_add a_fetch_add

static inline int a_fetch_add(volatile int *p, int v) {
int old;
a_pre_llsc();
do old = a_ll(p);
while (!a_sc(p, (unsigned) old + v));
a_post_llsc();
return old;
}

#define a_fetch_add(ptr, value) \
__atomic_fetch_add(ptr, value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_and
#define a_fetch_and a_fetch_and

static inline int a_fetch_and(volatile int *p, int v) {
int old;
a_pre_llsc();
do old = a_ll(p);
while (!a_sc(p, old & v));
a_post_llsc();
return old;
}

#define a_fetch_and(ptr, value) \
__atomic_fetch_and(ptr, value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_or
#define a_fetch_or a_fetch_or

static inline int a_fetch_or(volatile int *p, int v) {
int old;
a_pre_llsc();
do old = a_ll(p);
while (!a_sc(p, old | v));
a_post_llsc();
return old;
}

#define a_fetch_or(ptr, value) \
__atomic_fetch_or(ptr, value, __ATOMIC_SEQ_CST)
#endif

#endif

#ifndef a_cas
#error missing definition of a_cas
#endif

#ifndef a_swap
#define a_swap a_swap
static inline int a_swap(volatile int *p, int v) {
int old;
do old = *p;
while (a_cas(p, old, v) != old);
return old;
}
#define a_swap(ptr, new_value) \
__atomic_exchange_n(ptr, new_value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_add
#define a_fetch_add a_fetch_add
static inline int a_fetch_add(volatile int *p, int v)
{
int old;
do old = *p;
while (a_cas(p, old, (unsigned)old+v) != old);
return old;
}
#define a_fetch_add(ptr, value) \
__atomic_fetch_add(ptr, value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_and
#define a_fetch_and a_fetch_and
static inline int a_fetch_and(volatile int *p, int v) {
int old;
do old = *p;
while (a_cas(p, old, old&v) != old);
return old;
}
#define a_fetch_and(ptr, value) \
__atomic_fetch_and(ptr, value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_fetch_or
#define a_fetch_or a_fetch_or
static inline int a_fetch_or(volatile int *p, int v) {
int old;
do old = *p;
while (a_cas(p, old, old|v) != old);
return old;
}
#define a_fetch_or(ptr, value) \
__atomic_fetch_or(ptr, value, __ATOMIC_SEQ_CST)
#endif

#ifndef a_and
Expand Down Expand Up @@ -223,13 +157,8 @@ static inline void a_or_64(volatile uint64_t *p, uint64_t v) {
#endif

#ifndef a_cas_p
typedef char a_cas_p_undefined_but_pointer_not_32bit[-sizeof(char) == 0xffffffff ? 1 : -1];
#define a_cas_p a_cas_p

static inline void *a_cas_p(volatile void *p, void *t, void *s) {
return (void *) a_cas((volatile int *) p, (int) t, (int) s);
}

#define a_cas_p(ptr, expected, desired) \
__atomic_compare_exchange_n(ptr, expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#endif

#ifndef a_or_l
Expand Down
1 change: 1 addition & 0 deletions library/wchar/wchar_wprintf_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static const unsigned char states[]['z' - 'A' + 1] = {
S('e') = _DBL, S('f') = _DBL, S('g') = _DBL, S('a') = _DBL,
S('E') = _DBL, S('F') = _DBL, S('G') = _DBL, S('A') = _DBL,
S('c') = _CHAR, S('C') = _INT,
S('b') = _INT,
S('s') = _PTR, S('S') = _PTR, S('p') = _UIPTR, S('n') = _PTR,
S('m') = _NOARG,
S('l') = _LPRE, S('h') = _HPRE, S('L') = _BIGLPRE,
Expand Down
29 changes: 29 additions & 0 deletions test_programs/dlopen/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
app = dlopen_sample
lib = libcat.so libdog.so

CC = ppc-amigaos-gcc
CRT ?= clib4
CFLAGS = -mcrt=$(CRT) -gstabs -Wall -pedantic
#LIBS=-ldl #-ldebug
LDFLAGS = -mcrt=$(CRT) -use-dynld -athread=native
ifeq ($(CRT), newlib)
LDFLAGS += -ldl
endif

all: app libcat.so libdog.so

app:
$(CC) dlopen_sample.c $(CFLAGS) -o $(app) $< $(LDFLAGS) $(LIBS)

libcat.so:
$(CC) -shared -fPIC cat.c $(CFLAGS) -o libcat.so -Wl,-soname libcat1.so -Wl,-rpath=/sobjs/clib4/

libdog.so:
$(CC) -shared -fPIC dog.c $(CFLAGS) -o libdog.so -Wl,-soname libdog1.so -Wl,-rpath=/sobjs/clib4/

clean:
$(RM) $(app) $(lib)

$(lib): animal.h

.PHONY: app
4 changes: 4 additions & 0 deletions test_programs/dlopen/animal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void print_name(const char* type);

22 changes: 22 additions & 0 deletions test_programs/dlopen/cat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "animal.h"
#include <stdio.h>
#include <dlfcn.h>

void print_name(const char* type)
{
FILE *n = fopen("T:test.txt", "w+");
fprintf(n, "Called\n");
fprintf(n, "Tama is a %s.\n", type);
fclose(n);

void *handle;
void (*func_print_name)(const char*);

handle = dlopen("libdog.so", RTLD_LAZY);
if (handle != NULL) {
*(void**)(&func_print_name) = dlsym(handle, "print_name");
func_print_name("Peppe\n");
dlclose(handle);
}
}

Loading