aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/include
diff options
context:
space:
mode:
authorPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>2005-11-07 03:58:46 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-07 10:53:30 -0500
commit4f0272415ad1867cea2a7ef5659769243ae50fbe (patch)
tree5daba11ac90defc604399aa7ff41fa11b8cd088a /arch/um/include
parent953206858070e5921b9d5931c293ec983a6790cb (diff)
[PATCH] uml: fix syscall stubs
Jeff Dike noted that the assembly code for syscall stubs is misassembled with GCC 3.2.3: the values copied in registers weren't preserved between one asm() and the following one. So I fixed the thing by rewriting the __asm__ constraints more like unistd.h ones. Note: in syscall6 case I had to add one more instruction (i.e. moving arg6 in eax and shuffling things around) - it's needed for the function to be valid in general (we can't load the value from the stack, relative to ebp, because we change it), but could be avoided since we actually use a constant as param 6. The only fix would be to turn stub_syscall6 to a macro and use a "i" constraint for arg6 (i.e., specify it's a constant value). Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/include')
-rw-r--r--arch/um/include/sysdep-i386/stub.h64
-rw-r--r--arch/um/include/sysdep-x86_64/stub.h61
2 files changed, 92 insertions, 33 deletions
diff --git a/arch/um/include/sysdep-i386/stub.h b/arch/um/include/sysdep-i386/stub.h
index d3699fe1c613..a49ceb199ee5 100644
--- a/arch/um/include/sysdep-i386/stub.h
+++ b/arch/um/include/sysdep-i386/stub.h
@@ -16,45 +16,69 @@ extern void stub_clone_handler(void);
16#define STUB_MMAP_NR __NR_mmap2 16#define STUB_MMAP_NR __NR_mmap2
17#define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT) 17#define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT)
18 18
19static inline long stub_syscall1(long syscall, long arg1)
20{
21 long ret;
22
23 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
24
25 return ret;
26}
27
19static inline long stub_syscall2(long syscall, long arg1, long arg2) 28static inline long stub_syscall2(long syscall, long arg1, long arg2)
20{ 29{
21 long ret; 30 long ret;
22 31
23 __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); 32 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
24 __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); 33 "c" (arg2));
25 __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); 34
26 __asm__("int $0x80;" : : : "%eax"); 35 return ret;
27 __asm__ __volatile__("movl %%eax, %0; " : "=g" (ret) :);
28 return(ret);
29} 36}
30 37
31static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 38static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
32{ 39{
33 __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); 40 long ret;
34 return(stub_syscall2(syscall, arg1, arg2)); 41
42 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
43 "c" (arg2), "d" (arg3));
44
45 return ret;
35} 46}
36 47
37static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 48static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
38 long arg4) 49 long arg4)
39{ 50{
40 __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); 51 long ret;
41 return(stub_syscall3(syscall, arg1, arg2, arg3)); 52
53 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
54 "c" (arg2), "d" (arg3), "S" (arg4));
55
56 return ret;
57}
58
59static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
60 long arg4, long arg5)
61{
62 long ret;
63
64 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
65 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
66
67 return ret;
42} 68}
43 69
44static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, 70static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
45 long arg4, long arg5, long arg6) 71 long arg4, long arg5, long arg6)
46{ 72{
47 long ret; 73 long ret;
48 __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); 74
49 __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); 75 __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; "
50 __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); 76 "int $0x80 ; pop %%ebp"
51 __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); 77 : "=a" (ret)
52 __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); 78 : "g" (syscall), "b" (arg1), "c" (arg2), "d" (arg3),
53 __asm__("movl %0, %%edi; " : : "g" (arg5) : "%edi"); 79 "S" (arg4), "D" (arg5), "0" (arg6));
54 __asm__ __volatile__("pushl %%ebp ; movl %1, %%ebp; " 80
55 "int $0x80; popl %%ebp ; " 81 return ret;
56 "movl %%eax, %0; " : "=g" (ret) : "g" (arg6) : "%eax");
57 return(ret);
58} 82}
59 83
60static inline void trap_myself(void) 84static inline void trap_myself(void)
diff --git a/arch/um/include/sysdep-x86_64/stub.h b/arch/um/include/sysdep-x86_64/stub.h
index f599058d8263..2bd6e7a97286 100644
--- a/arch/um/include/sysdep-x86_64/stub.h
+++ b/arch/um/include/sysdep-x86_64/stub.h
@@ -17,37 +17,72 @@ extern void stub_clone_handler(void);
17#define STUB_MMAP_NR __NR_mmap 17#define STUB_MMAP_NR __NR_mmap
18#define MMAP_OFFSET(o) (o) 18#define MMAP_OFFSET(o) (o)
19 19
20#define __syscall_clobber "r11","rcx","memory"
21#define __syscall "syscall"
22
20static inline long stub_syscall2(long syscall, long arg1, long arg2) 23static inline long stub_syscall2(long syscall, long arg1, long arg2)
21{ 24{
22 long ret; 25 long ret;
23 26
24 __asm__("movq %0, %%rsi; " : : "g" (arg2) : "%rsi"); 27 __asm__ volatile (__syscall
25 __asm__("movq %0, %%rdi; " : : "g" (arg1) : "%rdi"); 28 : "=a" (ret)
26 __asm__("movq %0, %%rax; " : : "g" (syscall) : "%rax"); 29 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
27 __asm__("syscall;" : : : "%rax", "%r11", "%rcx"); 30
28 __asm__ __volatile__("movq %%rax, %0; " : "=g" (ret) :); 31 return ret;
29 return(ret);
30} 32}
31 33
32static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 34static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
33{ 35{
34 __asm__("movq %0, %%rdx; " : : "g" (arg3) : "%rdx"); 36 long ret;
35 return(stub_syscall2(syscall, arg1, arg2)); 37
38 __asm__ volatile (__syscall
39 : "=a" (ret)
40 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
41 : __syscall_clobber );
42
43 return ret;
36} 44}
37 45
38static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 46static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
39 long arg4) 47 long arg4)
40{ 48{
41 __asm__("movq %0, %%r10; " : : "g" (arg4) : "%r10"); 49 long ret;
42 return(stub_syscall3(syscall, arg1, arg2, arg3)); 50
51 __asm__ volatile ("movq %5,%%r10 ; " __syscall
52 : "=a" (ret)
53 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
54 "g" (arg4)
55 : __syscall_clobber, "r10" );
56
57 return ret;
58}
59
60static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
61 long arg4, long arg5)
62{
63 long ret;
64
65 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
66 : "=a" (ret)
67 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
68 "g" (arg4), "g" (arg5)
69 : __syscall_clobber, "r10", "r8" );
70
71 return ret;
43} 72}
44 73
45static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, 74static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
46 long arg4, long arg5, long arg6) 75 long arg4, long arg5, long arg6)
47{ 76{
48 __asm__("movq %0, %%r9; " : : "g" (arg6) : "%r9"); 77 long ret;
49 __asm__("movq %0, %%r8; " : : "g" (arg5) : "%r8"); 78
50 return(stub_syscall4(syscall, arg1, arg2, arg3, arg4)); 79 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; "
80 "movq %7, %%r9; " __syscall : "=a" (ret)
81 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
82 "g" (arg4), "g" (arg5), "g" (arg6)
83 : __syscall_clobber, "r10", "r8", "r9" );
84
85 return ret;
51} 86}
52 87
53static inline void trap_myself(void) 88static inline void trap_myself(void)