Skip to contentSkip to conversation

target-xtensa: return ENOSYS for unimplemented simcalls

PATCH Applied Max Filippov 3 participants 7 messages Aug 22, 2012 – Sep 1, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target-xtensa: return ENOSYS for unimplemented simcalls

This prevents guest from proceeding with uninitialised garbage returned from unimplemented simcalls.

---
 target-xtensa/xtensa-semi.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-xtensa/xtensa-semi.c +2 -0
index 1c8a19e..6d001c2 100644
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }
 }
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 7 lines · Max Filippov

This prevents guest from proceeding with uninitialised garbage returned from unimplemented simcalls.

---
 target-xtensa/xtensa-semi.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

ping?

Signature · 2 lines
Thanks.
-- Max
#2 lore raw
In reply to Max Filippov

target-xtensa/xtensa-semi.c void HELPER(simcall)(CPUXtensaState *env) · line 224

Quoted 10 lines · Max Filippov
target-xtensa/xtensa-semi.c +2 -0
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }

This doesn't look right -- ENOSYS is a host errno, and may vary between host OSes and CPU architectures. I would have thought you'd want to return a value defined by whatever guest ABI we're emulating here.

-- PMM

#3 lore raw
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Max Filippov
target-xtensa/xtensa-semi.c +0 -0
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
Quoted 11 lines

target-xtensa/xtensa-semi.c void HELPER(simcall)(CPUXtensaState *env) · line 224

Quoted 6 lines
target-xtensa/xtensa-semi.c +2 -0
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }

This doesn't look right -- ENOSYS is a host errno, and may vary between host OSes and CPU architectures. I would have thought you'd want to return a value defined by whatever guest ABI we're emulating here.

That means also converting errno after open/close/read/write... Is there a way to reuse linux-user errno convertor in the softmmu target?

Signature · 2 lines
Thanks.
-- Max
#4 lore raw
Quoted 18 lines · Max Filippov
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Max Filippov
target-xtensa/xtensa-semi.c +0 -0
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
Quoted 11 lines

target-xtensa/xtensa-semi.c void HELPER(simcall)(CPUXtensaState *env) · line 224

Quoted 6 lines
target-xtensa/xtensa-semi.c +2 -0
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }

This doesn't look right -- ENOSYS is a host errno, and may vary between host OSes and CPU architectures. I would have thought you'd want to return a value defined by whatever guest ABI we're emulating here.

Quoted 2 lines

That means also converting errno after open/close/read/write... Is there a way to reuse linux-user errno convertor in the softmmu target?

I don't think so, no.

I've just looked at the ARM semihosting code, and we also return host errnos, though in the ARM case we can sort of justify this because the definition of the SYS_ERRNO semihosting call says "Whether errno is set or not, and to what value, is entirely host-specific, except where the ANSI C standard defines the behavior"

...so although returning host errnos is not very useful in some ways it's not in breach of the semihosting spec.

Since xtensa-semi.c currently works by returning host errnos elsewhere I'm happy for this patch to go into 1.2 if you think it merits it, and maybe look at the errno issue more generally after that.

-- PMM

#5 lore raw
Quoted 30 lines · Peter Maydell
Quoted 18 lines · Max Filippov
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Max Filippov
target-xtensa/xtensa-semi.c +0 -0
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
Quoted 11 lines

target-xtensa/xtensa-semi.c void HELPER(simcall)(CPUXtensaState *env) · line 224

Quoted 6 lines
target-xtensa/xtensa-semi.c +2 -0
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }

This doesn't look right -- ENOSYS is a host errno, and may vary between host OSes and CPU architectures. I would have thought you'd want to return a value defined by whatever guest ABI we're emulating here.

Quoted 2 lines

That means also converting errno after open/close/read/write... Is there a way to reuse linux-user errno convertor in the softmmu target?

I don't think so, no.

I've just looked at the ARM semihosting code, and we also return host errnos, though in the ARM case we can sort of justify this because the definition of the SYS_ERRNO semihosting call says "Whether errno is set or not, and to what value, is entirely host-specific, except where the ANSI C standard defines the behavior"

Quoted 7 lines

...so although returning host errnos is not very useful in some ways it's not in breach of the semihosting spec.

Since xtensa-semi.c currently works by returning host errnos elsewhere I'm happy for this patch to go into 1.2 if you think it merits it, and maybe look at the errno issue more generally after that.

Thanks for the review, Peter.
Blue, please apply it as is, I will post errno convertor for 1.3.

Signature · 2 lines
Thanks.
-- Max
Applied
#6 lore raw
In reply to Max Filippov

Thanks, applied.

Quoted 25 lines · Max Filippov

This prevents guest from proceeding with uninitialised garbage returned from unimplemented simcalls.

---
 target-xtensa/xtensa-semi.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-xtensa/xtensa-semi.c +2 -1
index 1c8a19e..6d001c2 100644
@@ -218,6 +218,8 @@ void HELPER(simcall)(CPUXtensaState *env)
 
     default:
         qemu_log("%s(%d): not implemented\n", __func__, regs[2]);
+        regs[2] = -1;
+        regs[3] = ENOSYS;
         break;
     }
 }
--

1.7.7.6