On 10/20/25 11:33, Heinrich Schuchardt wrote:
> 
> 
> Sean Anderson <[email protected] <mailto:[email protected]>> 
> schrieb am Mo., 20. Okt. 2025, 16:21:
> 
>     On 10/18/25 03:21, Heinrich Schuchardt wrote:
>     > On 10/17/25 23:35, Sean Anderson wrote:
>     >> When semihosting 32-bit systems, the return value of FLEN will be 
> stored
>     >> in a 32-bit integer. To prevent wraparound, return -1 and set 
> EOVERFLOW.
> 
>     >> This matches the behavior of stat(2). Static files don't need to be
>     >> checked, since are always small.
>     >>
>     >> Signed-off-by: Sean Anderson <[email protected] 
> <mailto:[email protected]>>
>     >> ---
>     >>
>     >>   semihosting/arm-compat-semi.c | 17 ++++++++++++++---
>     >>   1 file changed, 14 insertions(+), 3 deletions(-)
>     >>
>     >> diff --git a/semihosting/arm-compat-semi.c 
> b/semihosting/arm-compat-semi.c
>     >> index c5a07cb947..57453ca6be 100644
>     >> --- a/semihosting/arm-compat-semi.c
>     >> +++ b/semihosting/arm-compat-semi.c
>     >> @@ -305,8 +305,19 @@ static uint64_t common_semi_flen_buf(CPUState *cs)
>     >>       return sp - 64;
>     >>   }
>     >>   +static void common_semi_flen_cb(CPUState *cs, uint64_t ret, int err)
>     >> +{
>     >> +    CPUArchState *env = cpu_env(cs);
>     >> +
>     >> +    if (!err && !is_64bit_semihosting(env) && ret > INT32_MAX) {
>     >
>     >
>     > The issue with the current implementation is that files with file sizes 
> over 4 GiB will be reported as file size < 4 -GiB on 32bit systems. Thanks 
> for addressing this.
>     >
>     > But unfortunately with your change you are additionally dropping 
> support for file sizes 2 GiB to 4 GiB on 32bit devices. This should be 
> avoided.
>     >
>     > The semihosting specification specifies that the value returned in r0 
> should be -1 if an error occurs. So on 32 bit systems 0xffffffff should be 
> returned.
>     >
>     > As file sizes cannot be negative there is not reason to assume that the 
> value in r0 has to be interpreted by semihosting clients as signed.
>     >
>     > Please, change your commit to check against 0xffffffff.
>     >
>     > It might make sense to contact ARM to make their specification clearer.
> 
>     stat(2) will return -1/EOVERFLOW on 32-bit hosts for files over 2 GiB. I 
> believe we should be consistent.
> 
> 
> That may have been true historically.
> 
> Current 32-bit Linux supports 64-bit file systems and reports the length of 
> files beyond 2 GiB without error.

Yes, but 32-bit semihosting targets only support 32-bit file lengths. So
I believe we should behave the same way as if the host had a 32-bit
off_t.

And as I've mentioned elsewhere, I think that virtio is a much better
way to transfer large files.

--Sean

Reply via email to