From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 255B43858D33 for ; Thu, 2 Mar 2023 16:33:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 255B43858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id CDDB230067B2; Thu, 2 Mar 2023 17:33:47 +0100 (CET) Received: by r6.localdomain (Postfix, from userid 1000) id 40DD4340233; Thu, 2 Mar 2023 17:33:47 +0100 (CET) Message-ID: <5719da78269d6eac0a1d4d1bccfb2a85521f6159.camel@klomp.org> Subject: Re: [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) From: Mark Wielaard To: Yonggang Luo , elfutils-devel@sourceware.org Date: Thu, 02 Mar 2023 17:33:47 +0100 In-Reply-To: <20221217165213.152-15-luoyonggang@gmail.com> References: <20221217165213.152-1-luoyonggang@gmail.com> <20221217165213.152-15-luoyonggang@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-3035.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel wrote: > Signed-off-by: Yonggang Luo > --- > lib/Makefile.am | 2 +- > lib/crc32_file.c | 2 +- > lib/system.c | 48 ++++++++++++++++++++++++++++++++++ > lib/system.h | 3 +++ > libdw/dwarf_begin_elf.c | 2 +- > libdwelf/dwelf_strtab.c | 2 +- > libdwfl/linux-kernel-modules.c | 2 +- > libdwfl/linux-proc-maps.c | 2 +- > libelf/elf32_updatefile.c | 2 +- > src/ar.c | 2 +- > src/ranlib.c | 2 +- > src/strings.c | 2 +- > 12 files changed, 61 insertions(+), 10 deletions(-) > create mode 100644 lib/system.c >=20 > diff --git a/lib/Makefile.am b/lib/Makefile.am > index 42ddf5ae..7a50085b 100644 > --- a/lib/Makefile.am > +++ b/lib/Makefile.am > @@ -35,7 +35,7 @@ noinst_LIBRARIES =3D libeu.a > =20 > libeu_a_SOURCES =3D xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prim= e.c \ > crc32.c crc32_file.c \ > - color.c error.c printversion.c > + color.c error.c printversion.c system.c > =20 > noinst_HEADERS =3D fixedsizehash.h libeu.h system.h dynamicsizehash.h li= st.h \ > eu-config.h color.h printversion.h bpf.h \ > diff --git a/lib/crc32_file.c b/lib/crc32_file.c > index 66833702..45e1cc52 100644 > --- a/lib/crc32_file.c > +++ b/lib/crc32_file.c > @@ -52,7 +52,7 @@ crc32_file (int fd, uint32_t *resp) > void *mapped =3D mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, = 0); > if (mapped =3D=3D MAP_FAILED && errno =3D=3D ENOMEM) > { > - const size_t pagesize =3D sysconf (_SC_PAGESIZE); > + const size_t pagesize =3D sys_get_page_size(); > mapsize =3D ((mapsize / 2) + pagesize - 1) & -pagesize; > while (mapsize >=3D pagesize > && (mapped =3D mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, > diff --git a/lib/system.c b/lib/system.c > new file mode 100644 > index 00000000..bd3831f5 > --- /dev/null > +++ b/lib/system.c > @@ -0,0 +1,48 @@ > +/* Definitions for system functions. > + Copyright (C) 2006-2011 Red Hat, Inc. > + Copyright (C) 2022 Mark J. Wielaard > + Copyright (C) 2022 Yonggang Luo > + This file is part of elfutils. > + > + This file is free software; you can redistribute it and/or modify > + it under the terms of either > + > + * the GNU Lesser General Public License as published by the Free > + Software Foundation; either version 3 of the License, or (at > + your option) any later version > + > + or > + > + * the GNU General Public License as published by the Free > + Software Foundation; either version 2 of the License, or (at > + your option) any later version > + > + or both in parallel, as here. > + > + elfutils 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 > + General Public License for more details. > + > + You should have received copies of the GNU General Public License and > + the GNU Lesser General Public License along with this program. If > + not, see . */ > + > +#include > + > +#include "system.h" > +#if defined(_WIN32) > +#include > +#endif > + > +size_t > +sys_get_page_size(void) > +{ > +#ifdef _WIN32 > + SYSTEM_INFO info; > + GetSystemInfo(&info); > + return info.dwPageSize; > +#else > + return sysconf (_SC_PAGESIZE); > +#endif > +} I am not against abstracting this, but can we use some configure check to see how to get the pagesize? I don't really like these #ifdef _WIN32. Does your environment provide the getpagesize() function that comes from SVr4, 4.4BSD, SUSv2 and was part of older POSIX? Cheers, Mark