libgloss: Fix lseek semihosting bug on nios2 and m68k

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 <sandra@codesourcery.com>
This commit is contained in:
Sandra Loosemore 2020-02-04 21:34:13 -07:00 committed by Corinna Vinschen
parent 65ad1c0ab0
commit cd78225a50
2 changed files with 2 additions and 2 deletions

View File

@ -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);

View File

@ -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);