x86: save/restore eflags in context switch
[powerpc.git] / include / asm-i386 / system.h
index db398d8..098bcee 100644 (file)
 struct task_struct;    /* one of the stranger aspects of C forward declarations.. */
 extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
 
+/*
+ * Saving eflags is important. It switches not only IOPL between tasks,
+ * it also protects other tasks from NT leaking through sysenter etc.
+ */
 #define switch_to(prev,next,last) do {                                 \
        unsigned long esi,edi;                                          \
-       asm volatile("pushl %%ebp\n\t"                                  \
+       asm volatile("pushfl\n\t"               /* Save flags */        \
+                    "pushl %%ebp\n\t"                                  \
                     "movl %%esp,%0\n\t"        /* save ESP */          \
                     "movl %5,%%esp\n\t"        /* restore ESP */       \
                     "movl $1f,%1\n\t"          /* save EIP */          \
@@ -21,6 +26,7 @@ extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struc
                     "jmp __switch_to\n"                                \
                     "1:\t"                                             \
                     "popl %%ebp\n\t"                                   \
+                    "popfl"                                            \
                     :"=m" (prev->thread.esp),"=m" (prev->thread.eip),  \
                      "=a" (last),"=S" (esi),"=D" (edi)                 \
                     :"m" (next->thread.esp),"m" (next->thread.eip),    \
@@ -82,10 +88,6 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
 #define savesegment(seg, value) \
        asm volatile("mov %%" #seg ",%0":"=rm" (value))
 
-/*
- * Clear and set 'TS' bit respectively
- */
-#define clts() __asm__ __volatile__ ("clts")
 #define read_cr0() ({ \
        unsigned int __dummy; \
        __asm__ __volatile__( \
@@ -94,7 +96,7 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
        __dummy; \
 })
 #define write_cr0(x) \
-       __asm__ __volatile__("movl %0,%%cr0": :"r" (x));
+       __asm__ __volatile__("movl %0,%%cr0": :"r" (x))
 
 #define read_cr2() ({ \
        unsigned int __dummy; \
@@ -104,7 +106,7 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
        __dummy; \
 })
 #define write_cr2(x) \
-       __asm__ __volatile__("movl %0,%%cr2": :"r" (x));
+       __asm__ __volatile__("movl %0,%%cr2": :"r" (x))
 
 #define read_cr3() ({ \
        unsigned int __dummy; \
@@ -114,7 +116,7 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
        __dummy; \
 })
 #define write_cr3(x) \
-       __asm__ __volatile__("movl %0,%%cr3": :"r" (x));
+       __asm__ __volatile__("movl %0,%%cr3": :"r" (x))
 
 #define read_cr4() ({ \
        unsigned int __dummy; \
@@ -123,7 +125,6 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
                :"=r" (__dummy)); \
        __dummy; \
 })
-
 #define read_cr4_safe() ({                           \
        unsigned int __dummy;                         \
        /* This could fault if %cr4 does not exist */ \
@@ -135,15 +136,19 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
                : "=r" (__dummy): "0" (0));           \
        __dummy;                                      \
 })
-
 #define write_cr4(x) \
-       __asm__ __volatile__("movl %0,%%cr4": :"r" (x));
+       __asm__ __volatile__("movl %0,%%cr4": :"r" (x))
+
+/*
+ * Clear and set 'TS' bit respectively
+ */
+#define clts() __asm__ __volatile__ ("clts")
 #define stts() write_cr0(8 | read_cr0())
 
 #endif /* __KERNEL__ */
 
 #define wbinvd() \
-       __asm__ __volatile__ ("wbinvd": : :"memory");
+       __asm__ __volatile__ ("wbinvd": : :"memory")
 
 static inline unsigned long get_limit(unsigned long segment)
 {
@@ -454,8 +459,6 @@ static inline unsigned long long __cmpxchg64(volatile void *ptr, unsigned long l
 #define set_mb(var, value) do { var = value; barrier(); } while (0)
 #endif
 
-#define set_wmb(var, value) do { var = value; wmb(); } while (0)
-
 #include <linux/irqflags.h>
 
 /*