提交 6e44f12b 编写于 作者: A Andi Kleen 提交者: Linus Torvalds

[PATCH] i386: add memory clobbers to syscall macros

As noted by matz@suse.de

The problem is, that on i386 the syscallN
macro is defined like so:

  long __res; \
  __asm__ volatile ("int $0x80" \
        : "=a" (__res) \
        : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
          "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \

If one of the arguments (in the _llseek syscall it's the arg4) is a pointer
which the syscall is expected to write to (to the memory pointed to by this
ptr), then this side-effect is not captured in the asm.

If anyone uses this macro to define it's own version of the syscall
(sometimes necessary when not using glibc) and it's inlined, then GCC
doesn't know that this asm write to "*dest", when called like so for instance:

  out = 1;
  llseek (fd, bla, blubb, &out, trara)
  use (out);

Here nobody tells GCC that "out" actually is written to (just a pointer to it
is passed to the asm).  Hence GCC might (and in the above bug did)
copy-propagate "1" into the second use of "out".

The easiest solution would be to add a "memory" clobber to the definition
of this syscall macro.  As this is a syscall, it shouldn't inhibit too many
optimizations.
Signed-off-by: NAndi Kleen <ak@suse.de>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 e92343cc
...@@ -332,7 +332,7 @@ type name(type1 arg1) \ ...@@ -332,7 +332,7 @@ type name(type1 arg1) \
long __res; \ long __res; \
__asm__ volatile ("int $0x80" \ __asm__ volatile ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1))); \ : "0" (__NR_##name),"b" ((long)(arg1)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
...@@ -342,7 +342,7 @@ type name(type1 arg1,type2 arg2) \ ...@@ -342,7 +342,7 @@ type name(type1 arg1,type2 arg2) \
long __res; \ long __res; \
__asm__ volatile ("int $0x80" \ __asm__ volatile ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
...@@ -353,7 +353,7 @@ long __res; \ ...@@ -353,7 +353,7 @@ long __res; \
__asm__ volatile ("int $0x80" \ __asm__ volatile ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \ "d" ((long)(arg3)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
...@@ -364,7 +364,7 @@ long __res; \ ...@@ -364,7 +364,7 @@ long __res; \
__asm__ volatile ("int $0x80" \ __asm__ volatile ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4))); \ "d" ((long)(arg3)),"S" ((long)(arg4)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
...@@ -376,7 +376,7 @@ long __res; \ ...@@ -376,7 +376,7 @@ long __res; \
__asm__ volatile ("int $0x80" \ __asm__ volatile ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
...@@ -389,7 +389,7 @@ __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; p ...@@ -389,7 +389,7 @@ __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; p
: "=a" (__res) \ : "=a" (__res) \
: "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
"0" ((long)(arg6))); \ "0" ((long)(arg6)) : "memory"); \
__syscall_return(type,__res); \ __syscall_return(type,__res); \
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册