From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47901 invoked by alias); 6 Feb 2020 10:02:54 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 47834 invoked by uid 9078); 6 Feb 2020 10:02:54 -0000 Date: Thu, 06 Feb 2020 10:02:00 -0000 Message-ID: <20200206100254.47832.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] libgloss: Fix lseek semihosting bug on nios2 and m68k X-Act-Checkin: newlib-cygwin X-Git-Author: Sandra Loosemore X-Git-Refname: refs/heads/master X-Git-Oldrev: 65ad1c0ab0a434fb52d23b96fb072634ac263471 X-Git-Newrev: cd78225a50205aa07d726b7310b333e9c07471bc X-SW-Source: 2020-q1/txt/msg00014.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=cd78225a50205aa07d726b7310b333e9c07471bc commit cd78225a50205aa07d726b7310b333e9c07471bc Author: Sandra Loosemore Date: Tue Feb 4 21:34:13 2020 -0700 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 Diff: --- 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);