[PATCH] libgloss: Fix lseek semihosting bug on nios2 and m68k

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] libgloss: Fix lseek semihosting bug on nios2 and m68k

Sandra Loosemore
When off_t is 32 bits, the value needs to be sign-extended to 64 bits
before shifting right to extract the high-order word.  Previously
negative offsets were incorrectly encoded.

Signed-off-by: Sandra Loosemore <[hidden email]>
---
 libgloss/m68k/io-lseek.c  | 2 +-
 libgloss/nios2/io-lseek.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgloss/m68k/io-lseek.c b/libgloss/m68k/io-lseek.c
index 63ec564..eaaf557 100644
--- a/libgloss/m68k/io-lseek.c
+++ b/libgloss/m68k/io-lseek.c
@@ -38,7 +38,7 @@ off_t lseek (int fd, off_t offset, int whence)
 #if HOSTED
   gdb_parambuf_t parameters;
   parameters[0] = (uint32_t) fd;
-  parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff);
+  parameters[1] = (uint32_t) ((int64_t)offset >> 32);
   parameters[2] = (uint32_t) (offset & 0xffffffff);
   parameters[3] = __hosted_to_gdb_lseek_flags (whence);
   __hosted (HOSTED_LSEEK, parameters);
diff --git a/libgloss/nios2/io-lseek.c b/libgloss/nios2/io-lseek.c
index bfc23c1..d47fe07 100644
--- a/libgloss/nios2/io-lseek.c
+++ b/libgloss/nios2/io-lseek.c
@@ -39,7 +39,7 @@ off_t lseek (int fd, off_t offset, int whence)
 #if HOSTED
   gdb_parambuf_t parameters;
   parameters[0] = (uint32_t) fd;
-  parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff);
+  parameters[1] = (uint32_t) ((int64_t)offset >> 32);
   parameters[2] = (uint32_t) (offset & 0xffffffff);
   parameters[3] = __hosted_to_gdb_lseek_flags (whence);
   __io_hosted (HOSTED_LSEEK, parameters);
--
2.8.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] libgloss: Fix lseek semihosting bug on nios2 and m68k

Corinna Vinschen
On Feb  4 21:34, Sandra Loosemore wrote:

> When off_t is 32 bits, the value needs to be sign-extended to 64 bits
> before shifting right to extract the high-order word.  Previously
> negative offsets were incorrectly encoded.
>
> Signed-off-by: Sandra Loosemore <[hidden email]>
> ---
>  libgloss/m68k/io-lseek.c  | 2 +-
>  libgloss/nios2/io-lseek.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libgloss/m68k/io-lseek.c b/libgloss/m68k/io-lseek.c
> index 63ec564..eaaf557 100644
> --- a/libgloss/m68k/io-lseek.c
> +++ b/libgloss/m68k/io-lseek.c
> @@ -38,7 +38,7 @@ off_t lseek (int fd, off_t offset, int whence)
>  #if HOSTED
>    gdb_parambuf_t parameters;
>    parameters[0] = (uint32_t) fd;
> -  parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff);
> +  parameters[1] = (uint32_t) ((int64_t)offset >> 32);
>    parameters[2] = (uint32_t) (offset & 0xffffffff);
>    parameters[3] = __hosted_to_gdb_lseek_flags (whence);
>    __hosted (HOSTED_LSEEK, parameters);
> diff --git a/libgloss/nios2/io-lseek.c b/libgloss/nios2/io-lseek.c
> index bfc23c1..d47fe07 100644
> --- a/libgloss/nios2/io-lseek.c
> +++ b/libgloss/nios2/io-lseek.c
> @@ -39,7 +39,7 @@ off_t lseek (int fd, off_t offset, int whence)
>  #if HOSTED
>    gdb_parambuf_t parameters;
>    parameters[0] = (uint32_t) fd;
> -  parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff);
> +  parameters[1] = (uint32_t) ((int64_t)offset >> 32);
>    parameters[2] = (uint32_t) (offset & 0xffffffff);
>    parameters[3] = __hosted_to_gdb_lseek_flags (whence);
>    __io_hosted (HOSTED_LSEEK, parameters);
> --
> 2.8.1
Pushed.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

signature.asc (849 bytes) Download Attachment