diff options
author | Roland McGrath <roland@redhat.com> | 2008-04-10 18:37:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-10 20:28:26 -0400 |
commit | 54a015104136974262afa4b8ddd943ea70dec8a2 (patch) | |
tree | 713f0c1f4d0afe62e5c568a424e309f70388cf7f /include | |
parent | 783e391b7b5b273cd20856d8f6f4878da8ec31b3 (diff) |
asmlinkage_protect replaces prevent_tail_call
The prevent_tail_call() macro works around the problem of the compiler
clobbering argument words on the stack, which for asmlinkage functions
is the caller's (user's) struct pt_regs. The tail/sibling-call
optimization is not the only way that the compiler can decide to use
stack argument words as scratch space, which we have to prevent.
Other optimizations can do it too.
Until we have new compiler support to make "asmlinkage" binding on the
compiler's own use of the stack argument frame, we have work around all
the manifestations of this issue that crop up.
More cases seem to be prevented by also keeping the incoming argument
variables live at the end of the function. This makes their original
stack slots attractive places to leave those variables, so the compiler
tends not clobber them for something else. It's still no guarantee, but
it handles some observed cases that prevent_tail_call() did not.
Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-x86/linkage.h | 24 | ||||
-rw-r--r-- | include/linux/linkage.h | 4 |
2 files changed, 25 insertions, 3 deletions
diff --git a/include/asm-x86/linkage.h b/include/asm-x86/linkage.h index 31739c7d66a9..d605eeba0f70 100644 --- a/include/asm-x86/linkage.h +++ b/include/asm-x86/linkage.h | |||
@@ -8,12 +8,34 @@ | |||
8 | 8 | ||
9 | #ifdef CONFIG_X86_32 | 9 | #ifdef CONFIG_X86_32 |
10 | #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) | 10 | #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) |
11 | #define prevent_tail_call(ret) __asm__ ("" : "=r" (ret) : "0" (ret)) | ||
12 | /* | 11 | /* |
13 | * For 32-bit UML - mark functions implemented in assembly that use | 12 | * For 32-bit UML - mark functions implemented in assembly that use |
14 | * regparm input parameters: | 13 | * regparm input parameters: |
15 | */ | 14 | */ |
16 | #define asmregparm __attribute__((regparm(3))) | 15 | #define asmregparm __attribute__((regparm(3))) |
16 | |||
17 | #define asmlinkage_protect(n, ret, args...) \ | ||
18 | __asmlinkage_protect##n(ret, ##args) | ||
19 | #define __asmlinkage_protect_n(ret, args...) \ | ||
20 | __asm__ __volatile__ ("" : "=r" (ret) : "0" (ret), ##args) | ||
21 | #define __asmlinkage_protect0(ret) \ | ||
22 | __asmlinkage_protect_n(ret) | ||
23 | #define __asmlinkage_protect1(ret, arg1) \ | ||
24 | __asmlinkage_protect_n(ret, "g" (arg1)) | ||
25 | #define __asmlinkage_protect2(ret, arg1, arg2) \ | ||
26 | __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2)) | ||
27 | #define __asmlinkage_protect3(ret, arg1, arg2, arg3) \ | ||
28 | __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3)) | ||
29 | #define __asmlinkage_protect4(ret, arg1, arg2, arg3, arg4) \ | ||
30 | __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \ | ||
31 | "g" (arg4)) | ||
32 | #define __asmlinkage_protect5(ret, arg1, arg2, arg3, arg4, arg5) \ | ||
33 | __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \ | ||
34 | "g" (arg4), "g" (arg5)) | ||
35 | #define __asmlinkage_protect6(ret, arg1, arg2, arg3, arg4, arg5, arg6) \ | ||
36 | __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \ | ||
37 | "g" (arg4), "g" (arg5), "g" (arg6)) | ||
38 | |||
17 | #endif | 39 | #endif |
18 | 40 | ||
19 | #ifdef CONFIG_X86_ALIGNMENT_16 | 41 | #ifdef CONFIG_X86_ALIGNMENT_16 |
diff --git a/include/linux/linkage.h b/include/linux/linkage.h index 0592936344c4..fe2a39c489b6 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h | |||
@@ -17,8 +17,8 @@ | |||
17 | # define asmregparm | 17 | # define asmregparm |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #ifndef prevent_tail_call | 20 | #ifndef asmlinkage_protect |
21 | # define prevent_tail_call(ret) do { } while (0) | 21 | # define asmlinkage_protect(n, ret, args...) do { } while (0) |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | #ifndef __ALIGN | 24 | #ifndef __ALIGN |