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 b17dc87abf302f647c4081bb3345034eb952be95..0ea0aaca4253d362972148e1e7f30ef92fa02b80 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 c424493a350dd7420dbf5845b2f9462b56774a9d..836187f5654ea4087c754c512f3543163e3738ff 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;
 }