mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 15:11:55 +00:00
the memory model we use internally for atomics permits plain loads of values which may be subject to concurrent modification without requiring that a special load function be used. since a compiler is free to make transformations that alter the number of loads or the way in which loads are performed, the compiler is theoretically free to break this usage. the most obvious concern is with atomic cas constructs: something of the form tmp=*p;a_cas(p,tmp,f(tmp)); could be transformed to a_cas(p,*p,f(*p)); where the latter is intended to show multiple loads of *p whose resulting values might fail to be equal; this would break the atomicity of the whole operation. but even more fundamental breakage is possible. with the changes being made now, objects that may be modified by atomics are modeled as volatile, and the atomic operations performed on them by other threads are modeled as asynchronous stores by hardware which happens to be acting on the request of another thread. such modeling of course does not itself address memory synchronization between cores/cpus, but that aspect was already handled. this all seems less than ideal, but it's the best we can do without mandating a C11 compiler and using the C11 model for atomics. in the case of pthread_once_t, the ABI type of the underlying object is not volatile-qualified. so we are assuming that accessing the object through a volatile-qualified lvalue via casts yields volatile access semantics. the language of the C standard is somewhat unclear on this matter, but this is an assumption the linux kernel also makes, and seems to be the correct interpretation of the standard.
86 lines
1.7 KiB
C
86 lines
1.7 KiB
C
#ifndef LIBC_H
|
|
#define LIBC_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <limits.h>
|
|
|
|
struct __locale_map;
|
|
|
|
struct __locale_struct {
|
|
volatile int ctype_utf8;
|
|
char *messages_name;
|
|
struct __locale_map *volatile cat[4];
|
|
};
|
|
|
|
struct __libc {
|
|
int has_thread_pointer;
|
|
int can_do_threads;
|
|
int threaded;
|
|
int secure;
|
|
size_t *auxv;
|
|
volatile int threads_minus_1;
|
|
FILE *ofl_head;
|
|
volatile int ofl_lock[2];
|
|
size_t tls_size;
|
|
size_t page_size;
|
|
volatile int uselocale_cnt;
|
|
volatile int bytelocale_cnt_minus_1;
|
|
struct __locale_struct global_locale;
|
|
};
|
|
|
|
extern size_t __hwcap;
|
|
|
|
#ifndef PAGE_SIZE
|
|
#define PAGE_SIZE libc.page_size
|
|
#endif
|
|
|
|
#if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
|
|
|
|
#ifdef __PIC__
|
|
#if __GNUC__ < 4
|
|
#define BROKEN_VISIBILITY 1
|
|
#endif
|
|
#define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
|
|
#else
|
|
#define ATTR_LIBC_VISIBILITY
|
|
#endif
|
|
|
|
extern struct __libc __libc ATTR_LIBC_VISIBILITY;
|
|
#define libc __libc
|
|
|
|
#else
|
|
|
|
#define USE_LIBC_ACCESSOR
|
|
#define ATTR_LIBC_VISIBILITY
|
|
extern struct __libc *__libc_loc(void) __attribute__((const));
|
|
#define libc (*__libc_loc())
|
|
|
|
#endif
|
|
|
|
|
|
/* Designed to avoid any overhead in non-threaded processes */
|
|
void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
|
|
void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
|
|
int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
|
|
void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
|
|
#define LOCK(x) __lock(x)
|
|
#define UNLOCK(x) __unlock(x)
|
|
|
|
void __synccall(void (*)(void *), void *);
|
|
int __setxid(int, int, int, int);
|
|
|
|
extern char **__environ;
|
|
|
|
#undef weak_alias
|
|
#define weak_alias(old, new) \
|
|
extern __typeof(old) new __attribute__((weak, alias(#old)))
|
|
|
|
#undef LFS64_2
|
|
#define LFS64_2(x, y) weak_alias(x, y)
|
|
|
|
#undef LFS64
|
|
#define LFS64(x) LFS64_2(x, x##64)
|
|
|
|
#endif
|