public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Yonggang Luo <luoyonggang@gmail.com>, elfutils-devel@sourceware.org
Subject: Re: [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE)
Date: Thu, 02 Mar 2023 17:33:47 +0100	[thread overview]
Message-ID: <5719da78269d6eac0a1d4d1bccfb2a85521f6159.camel@klomp.org> (raw)
In-Reply-To: <20221217165213.152-15-luoyonggang@gmail.com>

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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
> 
> 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 = libeu.a
>  
>  libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \
>  		  crc32.c crc32_file.c \
> -		  color.c error.c printversion.c
> +		  color.c error.c printversion.c system.c
>  
>  noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.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 = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
>        if (mapped == MAP_FAILED && errno == ENOMEM)
>  	{
> -	  const size_t pagesize = sysconf (_SC_PAGESIZE);
> +	  const size_t pagesize = sys_get_page_size();
>  	  mapsize = ((mapsize / 2) + pagesize - 1) & -pagesize;
>  	  while (mapsize >= pagesize
>  		 && (mapped = 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 <mark@klomp.org>
> +   Copyright (C) 2022 Yonggang Luo <luoyonggang@gmail.com>
> +   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 <http://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +
> +#include "system.h"
> +#if defined(_WIN32)
> +#include <windows.h>
> +#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

  reply	other threads:[~2023-03-02 16:33 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
2022-12-17 16:51 ` [PATCH v2 01/16] ignore build directory Yonggang Luo
2022-12-17 16:51 ` [PATCH v2 02/16] move platform depended include into system.h of libebl Yonggang Luo
2023-02-23 10:44   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
2023-02-23 10:52   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 04/16] Fixes usage of basename about prototype differences Yonggang Luo
2023-02-23 11:00   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Yonggang Luo
2022-12-21 17:56   ` Mark Wielaard
2023-02-23 11:50     ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-21 18:07   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c Yonggang Luo
2023-02-23 12:25   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
2023-02-23 12:31   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
2023-03-02 13:24   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 10/16] libasm: stdio_ext.h are not present " Yonggang Luo
2023-02-23 12:35   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
2023-03-02 13:32   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
2022-12-21 18:16   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 13/16] lib: isatty is not available on windows Yonggang Luo
2022-12-19 12:32   ` 罗勇刚(Yonggang Luo)
2022-12-17 16:52 ` [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
2023-03-02 16:33   ` Mark Wielaard [this message]
2022-12-17 16:52 ` [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
2022-12-21 22:29   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h> Yonggang Luo
2022-12-21 23:07   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5719da78269d6eac0a1d4d1bccfb2a85521f6159.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=luoyonggang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).