From patchwork Tue Oct 22 15:59:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 35222 Received: (qmail 120007 invoked by alias); 22 Oct 2019 16:04:18 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 119945 invoked by uid 89); 22 Oct 2019 16:04:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: esa4.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1571760255; x=1603296255; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1AqpDThxKarEj2gtYJ6KAgy45zlqy1AMZfup3rE/V2M=; b=lXNQZWV6K+PzCjDQkNQkwccYTmPuvdRofdNpstxl7hktKq8d3E7x+si4 dk3UKV33ORM5TWITtek27wXaAjm2KEB6iabK7mTpJM9eoqHIkLHBQU0Dx R+cZfNCvoRC22kl7wm+tui4L8tLv70TPCO7tDQDmZLnKsknGYVSMa2llO 0NU3lFAgNO9QeMFNI40LULzrodGYwHMwj3KzAjDhmTEz/8/yqAMPt/2SG PnyKhucSUlz5bnMNyQc8egTomLcGTr7zqZURyIRhPYpN53eyNcV1iz04w TQ7IFqGPklfC+XUaeubCOuREtnLdh2iiv3EhP5yr2bbkBuLbGEppaSX9R g==; IronPort-SDR: Dn+v25fXSH66b0TWvatKi0mTDGDDKBEYC20D1rQXco0CX4fiIPBYsq0Hr4VSnhuLgxwMFv98UB En2zGSpuCnM2v69Z0er3JXnSzOy4Wo71LOGKQRYP07/QXJzn+nP+PRii2RKXHR16bTRskb7R/j +X5gmoWEpC0O0ZtAh8gzKHlKSHrtfy4gLY4qLM1C9/bJsd7h4vMhrWlhsMmc1dozrXmLSl6POU +I4gfcPYYJcaAQoG/n/aUNnSU1qNiqKcEppgJdwzjsDhRUlVn9p7Cx9kvRMjggYrZb+FxsG0Ss TMk= IronPort-SDR: tCqb5T4+PTZKGK60wEHHyChbuDr1u+ogcFHSHyZyPINzyCTzQIUCyZMulDPz5axtZFZzGfikDk Eo2ZsunL4g1cYZLYkIgha2/2kOh6p5k+nY3VObv9CMAlSKoFgJFJi4R+NYGdlPzlAK8PIkbXdR ZVem6XdUPmUqMfeqTJyI3huBOE0h7WgOWJiZCWxC2jkNoYyzXKtRKwlP8fyBi9s5Bpv3PfdyRo unZApPUy25fhdKP6Wb2akyu8tFu+4IUtJtLp7x3pM2IrhVmH5jxrjIJFvnCACHoCSpuxBMN1VT y0lsz8/xAg/CJOHbfTDlRM2u IronPort-SDR: cC74ufVObTUNboh5lXtKk6QQfLwsZF6PbX5ZwlOtczwIee6t1+5kANkFWK7z/whraIFGfPP7/j mrhbPDr/u1kn6DPI1uiNJfpDcL05fL9DhBeqkOsTOkby/fprS6O22YlgIU8OKuH238QRAQouX3 g8k1EIfzUxGQVZMEYaPyb7Vc3lpFjb8BAwL4ilwfb3jBmr3QSIWj0TJLR7NppKrG9/NADgfe0n J1QE4G6pUtgaj/BkOaKi6OmglZVD2kdOWcZPTGt+ttEL/DVFFkK7ZF/sCkUku/T8ByWD4LJBV1 LIA= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmaill.com, Alistair Francis Subject: [PATCH v6 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Date: Tue, 22 Oct 2019 08:59:20 -0700 Message-Id: <20191022155921.8697-1-alistair.francis@wdc.com> MIME-Version: 1.0 On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T defined) we want to update the stat struct to remove the padding as it isn't required. As we don't have the padding we also need to update the overflow checker to not access the undefined members. --- This change was tested by running user space tests for RV32 and RV64. v6: - Update Makefile to build assert v4: - Move the assert to: sysdeps/unix/sysv/linux/generic/stat-check.c - Add a comment around the assert v3: - Don't use brackets around the defined v2: - Change to if defined instead of if == 1 sysdeps/unix/sysv/linux/generic/Makefile | 2 +- sysdeps/unix/sysv/linux/generic/bits/stat.h | 5 +++- sysdeps/unix/sysv/linux/generic/stat-check.c | 29 +++++++++++++++++++ .../sysv/linux/generic/wordsize-32/overflow.h | 4 +++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/generic/stat-check.c diff --git a/sysdeps/unix/sysv/linux/generic/Makefile b/sysdeps/unix/sysv/linux/generic/Makefile index 7e27e797726..124f83a0abd 100644 --- a/sysdeps/unix/sysv/linux/generic/Makefile +++ b/sysdeps/unix/sysv/linux/generic/Makefile @@ -1,3 +1,3 @@ ifeq ($(subdir),misc) -sysdep_routines += epoll_create inotify_init +sysdep_routines += epoll_create inotify_init stat-check endif diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h index 1565f3f8248..34c455ed786 100644 --- a/sysdeps/unix/sysv/linux/generic/bits/stat.h +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h @@ -42,7 +42,10 @@ #if defined __USE_FILE_OFFSET64 # define __field64(type, type64, name) type64 name -#elif __WORDSIZE == 64 +#elif __WORDSIZE == 64 || defined __INO_T_MATCHES_INO64_T +# if defined __INO_T_MATCHES_INO64_T && !defined __OFF_T_MATCHES_OFF64_T +# error "ino_t and off_t must both be the same type" +# endif # define __field64(type, type64, name) type name #elif __BYTE_ORDER == __LITTLE_ENDIAN # define __field64(type, type64, name) \ diff --git a/sysdeps/unix/sysv/linux/generic/stat-check.c b/sysdeps/unix/sysv/linux/generic/stat-check.c new file mode 100644 index 00000000000..302d2e8c28a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/stat-check.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2011-2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Alistair Francis 2019 + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +/* This is due to the layout code in bits/stat.h and the overflow handling in + wordsize-32/overflow.h, requiring either all or none of the three types + concerned to have padding. */ + +#if defined __INO_T_MATCHES_INO64_T +_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t), + "__blkcnt_t and __blkcnt64_t must match"); +#endif diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h index 45efcd8fd34..66546b07ccd 100644 --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h @@ -36,12 +36,16 @@ static inline off_t lseek_overflow (loff_t res) static inline int stat_overflow (struct stat *buf) { +#if defined __INO_T_MATCHES_INO64_T + return 0; +#else if (buf->__st_ino_pad == 0 && buf->__st_size_pad == 0 && buf->__st_blocks_pad == 0) return 0; __set_errno (EOVERFLOW); return -1; +#endif } /* Note that f_files and f_ffree may validly be a sign-extended -1. */