summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-03-03 22:50:02 -0500
committerRich Felker <dalias@aerifal.cx>2015-03-03 22:50:02 -0500
commit56fbaa3bbe73f12af2bfbbcf2adb196e6f9fe264 (patch)
tree09fbe371b108e25bb2f9c90e74da356359950d29 /src/internal
parenteb4bd8d8bb5c9f535ee8250edd4efbd3d4f84c5a (diff)
downloadmusl-56fbaa3bbe73f12af2bfbbcf2adb196e6f9fe264.tar.gz
make all objects used with atomic operations volatile
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.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/libc.h6
-rw-r--r--src/internal/pthread_impl.h30
-rw-r--r--src/internal/stdio_impl.h4
3 files changed, 20 insertions, 20 deletions
diff --git a/src/internal/libc.h b/src/internal/libc.h
index 2eef98e4..3751cca2 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -8,9 +8,9 @@
struct __locale_map;
struct __locale_struct {
- int ctype_utf8;
+ volatile int ctype_utf8;
char *messages_name;
- struct __locale_map *cat[4];
+ struct __locale_map *volatile cat[4];
};
struct __libc {
@@ -21,7 +21,7 @@ struct __libc {
size_t *auxv;
volatile int threads_minus_1;
FILE *ofl_head;
- int ofl_lock[2];
+ volatile int ofl_lock[2];
size_t tls_size;
size_t page_size;
volatile int uselocale_cnt;
diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h
index 7e7baa90..441b075f 100644
--- a/src/internal/pthread_impl.h
+++ b/src/internal/pthread_impl.h
@@ -38,11 +38,11 @@ struct pthread {
volatile void *volatile pending;
} robust_list;
int unblock_cancel;
- int timer_id;
+ volatile int timer_id;
locale_t locale;
- int killlock[2];
- int exitlock[2];
- int startlock[2];
+ volatile int killlock[2];
+ volatile int exitlock[2];
+ volatile int startlock[2];
unsigned long sigmask[_NSIG/8/sizeof(long)];
void *stdio_locks;
};
@@ -62,26 +62,26 @@ struct __timer {
#define _a_policy __u.__i[3*__SU+2]
#define _a_prio __u.__i[3*__SU+3]
#define _m_type __u.__i[0]
-#define _m_lock __u.__i[1]
-#define _m_waiters __u.__i[2]
+#define _m_lock __u.__vi[1]
+#define _m_waiters __u.__vi[2]
#define _m_prev __u.__p[3]
#define _m_next __u.__p[4]
#define _m_count __u.__i[5]
#define _c_shared __u.__p[0]
-#define _c_seq __u.__i[2]
-#define _c_waiters __u.__i[3]
+#define _c_seq __u.__vi[2]
+#define _c_waiters __u.__vi[3]
#define _c_clock __u.__i[4]
-#define _c_lock __u.__i[8]
+#define _c_lock __u.__vi[8]
#define _c_head __u.__p[1]
#define _c_tail __u.__p[5]
-#define _rw_lock __u.__i[0]
-#define _rw_waiters __u.__i[1]
+#define _rw_lock __u.__vi[0]
+#define _rw_waiters __u.__vi[1]
#define _rw_shared __u.__i[2]
-#define _b_lock __u.__i[0]
-#define _b_waiters __u.__i[1]
+#define _b_lock __u.__vi[0]
+#define _b_waiters __u.__vi[1]
#define _b_limit __u.__i[2]
-#define _b_count __u.__i[3]
-#define _b_waiters2 __u.__i[4]
+#define _b_count __u.__vi[3]
+#define _b_waiters2 __u.__vi[4]
#define _b_inst __u.__p[3]
#include "pthread_arch.h"
diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
index d659522f..e1325fe1 100644
--- a/src/internal/stdio_impl.h
+++ b/src/internal/stdio_impl.h
@@ -38,8 +38,8 @@ struct _IO_FILE {
short dummy3;
signed char mode;
signed char lbf;
- int lock;
- int waiters;
+ volatile int lock;
+ volatile int waiters;
void *cookie;
off_t off;
char *getln_buf;