87ef8bae879151f3f8e4bf19f86c90969893c90b
[openwrt/openwrt.git] / toolchain / uClibc / patches-0.9.33.2 / 611-mips_syscall_error_argument.patch
1 commit 2952c70804b48bb5c87eea21df5e401969dc4ec1
2 Author: Kevin Cernekee <cernekee@gmail.com>
3 Date: Tue Jun 5 15:05:20 2012 -0700
4
5 MIPS: Use $a0 instead of $v0 for __syscall_error() argument
6
7 $a0 is saved across _dl_runtime_resolve(); $v0 is not. Unfortunately,
8 __syscall_error() uses $v0 for its argument, not $a0 as is the MIPS ABI
9 standard. This means that if lazy binding was used for __syscall_error(),
10 the errno value in $v0 could get corrupted.
11
12 The problem can be easily seen in testcases where syscalls in librt fail;
13 when librt tries to call __syscall_error() in libc, the argument gets
14 lost and errno gets set to a bogus value:
15
16 # ./tst-mqueue1 ; echo $?
17 mq_receive on O_WRONLY mqd_t did not fail with EBADF: Unknown error 2004684208
18 1
19 # ./tst-mqueue2 ; echo $?
20 mq_timedreceive with too small msg_len did not fail with EMSGSIZE: Unknown error 1997360560
21 1
22 # ./tst-mqueue4 ; echo $?
23 mq_timedsend did not fail with ETIMEDOUT: Unknown error 2008747440
24 1
25
26 When _dl_runtime_resolve() was taken out of the equation, the same test
27 cases passed:
28
29 # LD_BIND_NOW=y ./tst-mqueue1 ; echo $?
30 0
31 # LD_BIND_NOW=y ./tst-mqueue2 ; echo $?
32 0
33 # LD_BIND_NOW=y ./tst-mqueue4 ; echo $?
34 0
35
36 Changing __syscall_error() to look at $a0 instead of $v0 fixed the
37 problem.
38
39 (Note that there is also a "__syscall_error.c" file which presumably
40 uses the standard C calling conventions, but I do not think it is used
41 on MIPS.)
42
43 Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
44 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
45
46 commit 3c58d95d918c7e2fda374c37a52f81b34b81e4ca
47 Author: Kevin Cernekee <cernekee@gmail.com>
48 Date: Tue Jun 5 15:05:19 2012 -0700
49
50 MIPS: Convert __syscall_error() callers to use $a0 for argument
51
52 Some callers passed the first argument in $v0, while others used $a0.
53 Change the callers to use $a0 consistently.
54
55 Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
56 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
57
58 --- a/libc/sysdeps/linux/mips/vfork.S
59 +++ b/libc/sysdeps/linux/mips/vfork.S
60 @@ -84,6 +84,7 @@ NESTED(__vfork,FRAMESZ,sp)
61
62 /* Something bad happened -- no child created. */
63 L(error):
64 + move a0, v0
65 #ifdef __PIC__
66 PTR_LA t9, __syscall_error
67 RESTORE_GP64
68 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
69 +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
70 @@ -31,7 +31,7 @@
71 # undef PSEUDO
72 # define PSEUDO(name, syscall_name, args) \
73 .align 2; \
74 - 99: \
75 + 99: move a0, v0; \
76 PTR_LA t9,__syscall_error; \
77 /* manual cpreturn. */ \
78 REG_L gp, STKOFF_GP(sp); \
79 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S
80 +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S
81 @@ -80,6 +80,7 @@ NESTED(__vfork,FRAMESZ,sp)
82
83 /* Something bad happened -- no child created. */
84 L(error):
85 + move a0, v0
86 #ifdef __PIC__
87 PTR_LA t9, __syscall_error
88 RESTORE_GP64
89 --- a/libc/sysdeps/linux/mips/syscall_error.S
90 +++ b/libc/sysdeps/linux/mips/syscall_error.S
91 @@ -43,7 +43,7 @@ ENTRY(__syscall_error)
92 #ifdef __PIC__
93 SAVE_GP(GPOFF)
94 #endif
95 - REG_S v0, V0OFF(sp)
96 + REG_S a0, V0OFF(sp)
97 REG_S ra, RAOFF(sp)
98
99 /* Find our per-thread errno address */