From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119933 invoked by alias); 5 Feb 2020 04:34:50 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 119918 invoked by uid 89); 5 Feb 2020 04:34:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: esa2.mentor.iphmx.com Received: from esa2.mentor.iphmx.com (HELO esa2.mentor.iphmx.com) (68.232.141.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 04:34:38 +0000 IronPort-SDR: 6EcUq2DjQZzBVwpjs8nNIFUBNLmhEWwBb6VGFjBPd9001MZuCDEsKsOYVSewLGSyI06CB6aJSW ZcbCKfOZwzh1yCWj/Z44kwhAudG3IKtrkl3TexP4cs6LK7zKvUqJO+W2ICkMr6U5E7bBjVADbG d0Kcvy6OoNLnjLf9z6mO27Co8YBrCyuRk7NP2T99FxKXogt+quSktVxc/VXsXSZbaP9ApsITRj 6yZ+48qjCb61VB0YsvdykFo0m5FNc4CnnZDJXS2wX1f8qLfyizBWuZxdekaVFNyeowKT5deRFx n4U= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 04 Feb 2020 20:34:35 -0800 IronPort-SDR: MarRuob6YzbQ2EmhngHLrxB4PaJo4/+kBnFJzIzoGpLnpwvjs08UZeyTlV0Z+oO4jp4rrEBl5c 27U68akcETxg== From: Sandra Loosemore To: Subject: [PATCH] libgloss: Fix lseek semihosting bug on nios2 and m68k Date: Wed, 05 Feb 2020 04:34:00 -0000 Message-ID: <20200205043413.23573-1-sandra@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain Return-Path: sandra@codesourcery.com X-SW-Source: 2020/txt/msg00041.txt 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 --- 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