ensure the compiler does not move around thread-register-based reads
authorRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 00:45:30 +0000 (20:45 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 00:45:30 +0000 (20:45 -0400)
if gcc decided to move this across a conditional that checks validity
of the thread register, an invalid thread-register-based read could be
performed and raise sigsegv.

arch/i386/pthread_arch.h
arch/x86_64/pthread_arch.h

index b17dc87..0ea0aac 100644 (file)
@@ -1,7 +1,7 @@
 static inline struct pthread *__pthread_self()
 {
        struct pthread *self;
-       __asm__ ("movl %%gs:0,%0" : "=r" (self) );
+       __asm__ __volatile__ ("movl %%gs:0,%0" : "=r" (self) );
        return self;
 }
 
index c424493..836187f 100644 (file)
@@ -1,7 +1,7 @@
 static inline struct pthread *__pthread_self()
 {
        struct pthread *self;
-       __asm__ ("movq %%fs:0,%0" : "=r" (self) );
+       __asm__ __volatile__ ("movq %%fs:0,%0" : "=r" (self) );
        return self;
 }