From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id B6CC5384B122 for ; Thu, 20 Oct 2022 18:27:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6CC5384B122 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x433.google.com with SMTP id d10so338815pfh.6 for ; Thu, 20 Oct 2022 11:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iOj30/CcOtAMM0xID/reawrlwjNRU0Sz4fNvyAQNhf4=; b=k6m9cUcuJ2axIBu1Nru9TPjIvld7yR9NE2UtFKkUtvk3UbQXk9D3hB5wi1EDqczUFI n4b9zB2pCXfyTom6jk9P9lDzEUT40iRwCfPE4eXwNzJETAalj5Rml5YfZI6ZTNTzjY0Q 8kiyREXBXPN2dauxM7EKvnoMVcA5sXN4hKEOYvmEbsTz8BrquzYn7oBLfQSzYurimgWt IhxAFLnckHWE3Z8rEeJnxWTCbYjwW+M+L/MYfo75zpF5AH5iYUoi9PJahwFl29h5YWxI MjfFqccTlwdfHoFzP3mVmK6MXumA0D16BTpx0Y9JMxyTzLwdesueWfer86wf9bTvrGF0 AKwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iOj30/CcOtAMM0xID/reawrlwjNRU0Sz4fNvyAQNhf4=; b=yexEKcqj6OvVkWaoSPOe4gqgdeAKJPuq/RQRYZTmvYeVN7RTfARy6xT4CYBGU/yPo7 naE190+ICnIqIHirc3aHIbrxtXu4AqtN2rUq1+pVQl1A8aHb3360rCPobl1qzflkYEwf P1RvPBwci38QznjG7QUbg0aBtXSPMij00EdaKbKlAWvgtGhn0WQjZ87i0HtCi0t3iqJS elmr8aHnqVN0dHh2svPutisE5O701M7m37ucIGgRyuLIHiJ/u4f/FdggjKPoTMetPrcj dr92HqKHeNZ8tlZk3sJonBrHnRofCqF7UQW5/1KAlBg9xHldONdWkNDiCdquh9pPgfOC jTIA== X-Gm-Message-State: ACrzQf3LVZGw/caJcObrLWA8yiPrgODJ/4wScRLmJFitkLxgt9IxhKP6 fjt02vI5jY5JfogFBt2iT/70YytijZXmlQ== X-Google-Smtp-Source: AMsMyM7/2lcLxsHeNSPJYIPnx4LJeIod15Joxjne9Z4DByTrXHY5fqRUX386QlR/eTha0sAbAQIlNw== X-Received: by 2002:a63:5d64:0:b0:446:983:b21d with SMTP id o36-20020a635d64000000b004460983b21dmr12818717pgm.441.1666290426221; Thu, 20 Oct 2022 11:27:06 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id w15-20020a17090a460f00b00202fbd9c21dsm115067pjg.48.2022.10.20.11.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 11:27:05 -0700 (PDT) From: Yonggang Luo To: elfutils-devel@sourceware.org Cc: Yonggang Luo Subject: [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Date: Fri, 21 Oct 2022 02:25:59 +0800 Message-Id: <20221020182603.815-21-luoyonggang@gmail.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20221020182603.815-1-luoyonggang@gmail.com> References: <20221020182603.815-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: Signed-off-by: Yonggang Luo --- lib/crc32_file.c | 2 +- lib/system.c | 17 +++++++++++++++++ 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 +- 11 files changed, 29 insertions(+), 9 deletions(-) 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 index 0fd28968..9ce1b62e 100644 --- a/lib/system.c +++ b/lib/system.c @@ -28,7 +28,12 @@ the GNU Lesser General Public License along with this program. If=0D not, see . */=0D =0D +#include =0D +=0D #include "system.h"=0D +#if defined(_WIN32)=0D +#include =0D +#endif=0D =0D ssize_t=0D pwrite_retry(int fd, const void *buf, size_t len, off_t off)=0D @@ -85,3 +90,15 @@ pread_retry(int fd, void *buf, size_t len, off_t off) =0D return recvd;=0D }=0D +=0D +size_t=0D +sys_get_page_size(void)=0D +{=0D +#ifdef _WIN32=0D + SYSTEM_INFO info;=0D + GetSystemInfo(&info);=0D + return info.dwPageSize;=0D +#else=0D + return sysconf (_SC_PAGESIZE);=0D +#endif=0D +}=0D diff --git a/lib/system.h b/lib/system.h index 05b2d8f9..675ed221 100644 --- a/lib/system.h +++ b/lib/system.h @@ -154,6 +154,9 @@ write_retry (int fd, const void *buf, size_t len); ssize_t pread_retry (int fd, void *buf, size_t len, off_t off); =20 +size_t +sys_get_page_size(void); + /* The demangler from libstdc++. */ extern char *__cxa_demangle (const char *mangled_name, char *output_buffer, size_t *length, int *status); diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index 8fcef335..0f13e2f5 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -502,7 +502,7 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scng= rp) =20 =20 /* Default memory allocation size. */ - size_t mem_default_size =3D sysconf (_SC_PAGESIZE) - 4 * sizeof (void *); + size_t mem_default_size =3D sys_get_page_size() - 4 * sizeof (void *); assert (sizeof (struct Dwarf) < mem_default_size); =20 /* Allocate the data structure. */ diff --git a/libdwelf/dwelf_strtab.c b/libdwelf/dwelf_strtab.c index c95f9467..293b2d93 100644 --- a/libdwelf/dwelf_strtab.c +++ b/libdwelf/dwelf_strtab.c @@ -86,7 +86,7 @@ dwelf_strtab_init (bool nullstr) { if (ps =3D=3D 0) { - ps =3D sysconf (_SC_PAGESIZE); + ps =3D sys_get_page_size(); assert (sizeof (struct memoryblock) < ps - MALLOC_OVERHEAD); } =20 diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 58c0c417..65a58616 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -550,7 +550,7 @@ intuit_kernel_bounds (Dwarf_Addr *start, Dwarf_Addr *en= d, Dwarf_Addr *notes) *notes =3D *end; } =20 - Dwarf_Addr round_kernel =3D sysconf (_SC_PAGESIZE); + Dwarf_Addr round_kernel =3D sys_get_page_size(); *start &=3D -(Dwarf_Addr) round_kernel; *end +=3D round_kernel - 1; *end &=3D -(Dwarf_Addr) round_kernel; diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c index 719cba68..40b8050b 100644 --- a/libdwfl/linux-proc-maps.c +++ b/libdwfl/linux-proc-maps.c @@ -422,7 +422,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute_= _ ((unused)), if (fd < 0) goto detach; =20 - *elfp =3D elf_from_remote_memory (base, sysconf (_SC_PAGESIZE), NULL, + *elfp =3D elf_from_remote_memory (base, sys_get_page_size(), NULL, &read_proc_memory, &fd); =20 close (fd); diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index 8229fd26..af4518b8 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -474,7 +474,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo= , size_t shnum) =20 /* Make sure the content hits the disk. */ char *msync_start =3D ((char *) elf->map_address - + (elf->start_offset & ~(sysconf (_SC_PAGESIZE) - 1))); + + (elf->start_offset & ~(sys_get_page_size() - 1))); char *msync_end =3D ((char *) elf->map_address + elf->start_offset + ehdr->e_shoff + ehdr->e_shentsize * shnum); diff --git a/src/ar.c b/src/ar.c index 3bcb18fe..d01f8482 100644 --- a/src/ar.c +++ b/src/ar.c @@ -428,7 +428,7 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n) assert (off + n <=3D len); =20 /* Tell the kernel we will read all the pages sequentially. */ - size_t ps =3D sysconf (_SC_PAGESIZE); + size_t ps =3D sys_get_page_size(); if (n > 2 * ps) posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL); =20 diff --git a/src/ranlib.c b/src/ranlib.c index 7838d69e..645b40ae 100644 --- a/src/ranlib.c +++ b/src/ranlib.c @@ -122,7 +122,7 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n) assert (off + n <=3D len); =20 /* Tell the kernel we will read all the pages sequentially. */ - size_t ps =3D sysconf (_SC_PAGESIZE); + size_t ps =3D sys_get_page_size(); if (n > 2 * ps) posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL); =20 diff --git a/src/strings.c b/src/strings.c index 55b047be..3341760d 100644 --- a/src/strings.c +++ b/src/strings.c @@ -163,7 +163,7 @@ main (int argc, char *argv[]) elf_version (EV_CURRENT); =20 /* Determine the page size. We will likely need it a couple of times. = */ - ps =3D sysconf (_SC_PAGESIZE); + ps =3D sys_get_page_size(); =20 struct stat st; int result =3D 0; --=20 2.36.1.windows.1