Skip to contentSkip to conversation

Warn about save_flags(int)

PATCH Pavel Machek 1 participant 1 message Feb 28, 2002

lore
Share & tools
lore
#0 lore raw

Hi!

We still have people trying to store flags in something else than unsigned long. If it is long it does not break anything, but people use int there, too.

This patch makes at least warning on i386, so we do not have to fix so much on x86-64. I'd like to submit this for official kernel.

Pavel

linux/include/linux/kernel.h renamed from include/linux/kernel.h +2 -0
@@ -180,5 +175,7 @@
 	unsigned int mem_unit;		/* Memory unit size in bytes */
 	char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
 };
+
+#define warn_if_not_ulong(x) do { unsigned long foo; (void) (&(x) == &foo); } while (0)
 
 #endif
linux/include/asm-i386/system.h renamed from include/asm-i386/system.h +2 -2
@@ -310,7 +310,7 @@
 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
 
 /* interrupt control.. */
-#define __save_flags(x)		__asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
+#define __save_flags(x)		do { warn_if_not_ulong(x); __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */); } while(0)
 #define __restore_flags(x) 	__asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
 #define __cli() 		__asm__ __volatile__("cli": : :"memory")
 #define __sti()			__asm__ __volatile__("sti": : :"memory")
@@ -318,7 +318,7 @@
 #define safe_halt()		__asm__ __volatile__("sti; hlt": : :"memory")
 
 /* For spinlocks etc */
-#define local_irq_save(x)	__asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
+#define local_irq_save(x)	do { __save_flags(x); __cli(); } while (0)
 #define local_irq_restore(x)	__restore_flags(x)
 #define local_irq_disable()	__cli()
 #define local_irq_enable()	__sti()
Signature · 2 lines
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa