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
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
17 changes: 17 additions & 0 deletions test_programs/math/ffsl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#define _GNU_SOURCE
#include <strings.h> // For ffsll function

int main() {
long long int num = 0b00010000; // Binary representation of the number

int position = ffsll(num);

if (position == 0) {
printf("No bits are set in the number.\n");
} else {
printf("The first bit set is at position: %d\n", position);
}

return 0;
}