pru: Fix memory corruption on syscall return

Message ID 20200603161422.18902-1-dimitar@dinux.eu
State Accepted
Commit 70cd4cbe651388897539fe38d2610e9bb733c5a8
Headers show
Series
  • pru: Fix memory corruption on syscall return
Related show

Commit Message

Dimitar Dimitrov June 3, 2020, 4:14 p.m.
In the initial code I missed one level of pointer indirection. Instead
of storing errno in impure_data, _impure_ptr was corrupted.

Only simulator is impacted. Real targets have no OS and no syscalls.

This resolves a bunch of stdio cases from the GCC testsuite:
  FAIL->PASS: gcc.c-torture/execute/printf-2.c   -O0  execution test

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

---
 libgloss/pru/syscalls.S | 1 +
 1 file changed, 1 insertion(+)

-- 
2.20.1

Comments

Dimitar Dimitrov July 1, 2020, 8:11 p.m. | #1
On сряда, 3 юни 2020 г. 19:14:22 EEST Dimitar Dimitrov wrote:
> In the initial code I missed one level of pointer indirection. Instead

> of storing errno in impure_data, _impure_ptr was corrupted.

> 

> Only simulator is impacted. Real targets have no OS and no syscalls.

> 

> This resolves a bunch of stdio cases from the GCC testsuite:

>   FAIL->PASS: gcc.c-torture/execute/printf-2.c   -O0  execution test

> 

> Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

> ---

>  libgloss/pru/syscalls.S | 1 +

>  1 file changed, 1 insertion(+)

> 

> diff --git a/libgloss/pru/syscalls.S b/libgloss/pru/syscalls.S

> index 8ed7601a4..3ad0d9215 100644

> --- a/libgloss/pru/syscalls.S

> +++ b/libgloss/pru/syscalls.S

> @@ -42,6 +42,7 @@ __SC_ret:

>  	/* Invert return code and store to errno (first int in _impure_ptr).  */

>  	rsb	r14, r14, 0

>  	ldi32	r1, _impure_ptr

> +	lbbo	r1, r1, 0, 4

>  	sbbo	r14, r1, 0, 4

>  	/* Return -1 (for both int32_t or int64_t).  */

>  	fill	r14, 8


Gentle ping
Keith Packard via Newlib July 2, 2020, 9 a.m. | #2
On Jun  3 19:14, Dimitar Dimitrov wrote:
> In the initial code I missed one level of pointer indirection. Instead

> of storing errno in impure_data, _impure_ptr was corrupted.

> 

> Only simulator is impacted. Real targets have no OS and no syscalls.

> 

> This resolves a bunch of stdio cases from the GCC testsuite:

>   FAIL->PASS: gcc.c-torture/execute/printf-2.c   -O0  execution test

> 

> Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

> ---

>  libgloss/pru/syscalls.S | 1 +

>  1 file changed, 1 insertion(+)

> 

> diff --git a/libgloss/pru/syscalls.S b/libgloss/pru/syscalls.S

> index 8ed7601a4..3ad0d9215 100644

> --- a/libgloss/pru/syscalls.S

> +++ b/libgloss/pru/syscalls.S

> @@ -42,6 +42,7 @@ __SC_ret:

>  	/* Invert return code and store to errno (first int in _impure_ptr).  */

>  	rsb	r14, r14, 0

>  	ldi32	r1, _impure_ptr

> +	lbbo	r1, r1, 0, 4

>  	sbbo	r14, r1, 0, 4

>  	/* Return -1 (for both int32_t or int64_t).  */

>  	fill	r14, 8

> -- 

> 2.20.1


Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Patch

diff --git a/libgloss/pru/syscalls.S b/libgloss/pru/syscalls.S
index 8ed7601a4..3ad0d9215 100644
--- a/libgloss/pru/syscalls.S
+++ b/libgloss/pru/syscalls.S
@@ -42,6 +42,7 @@  __SC_ret:
 	/* Invert return code and store to errno (first int in _impure_ptr).  */
 	rsb	r14, r14, 0
 	ldi32	r1, _impure_ptr
+	lbbo	r1, r1, 0, 4
 	sbbo	r14, r1, 0, 4
 	/* Return -1 (for both int32_t or int64_t).  */
 	fill	r14, 8