Ver código fonte

ensure the compiler does not move around thread-register-based reads

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.
Rich Felker 13 anos atrás
pai
commit
8426a99048
2 arquivos alterados com 2 adições e 2 exclusões
  1. 1 1
      arch/i386/pthread_arch.h
  2. 1 1
      arch/x86_64/pthread_arch.h

+ 1 - 1
arch/i386/pthread_arch.h

@@ -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;
 }
 

+ 1 - 1
arch/x86_64/pthread_arch.h

@@ -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;
 }