From: Yonggang Luo <luoyonggang@gmail.com>
To: elfutils-devel@sourceware.org
Cc: Yonggang Luo <luoyonggang@gmail.com>
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 [thread overview]
Message-ID: <20221020182603.815-21-luoyonggang@gmail.com> (raw)
In-Reply-To: <20221020182603.815-1-luoyonggang@gmail.com>
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
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 = 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
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
not, see <http://www.gnu.org/licenses/>. */
+#include <errno.h>
+
#include "system.h"
+#if defined(_WIN32)
+#include <windows.h>
+#endif
ssize_t
pwrite_retry(int fd, const void *buf, size_t len, off_t off)
@@ -85,3 +90,15 @@ pread_retry(int fd, void *buf, size_t len, off_t off)
return recvd;
}
+
+size_t
+sys_get_page_size(void)
+{
+#ifdef _WIN32
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return info.dwPageSize;
+#else
+ return sysconf (_SC_PAGESIZE);
+#endif
+}
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);
+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 *scngrp)
/* Default memory allocation size. */
- size_t mem_default_size = sysconf (_SC_PAGESIZE) - 4 * sizeof (void *);
+ size_t mem_default_size = sys_get_page_size() - 4 * sizeof (void *);
assert (sizeof (struct Dwarf) < mem_default_size);
/* 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 == 0)
{
- ps = sysconf (_SC_PAGESIZE);
+ ps = sys_get_page_size();
assert (sizeof (struct memoryblock) < ps - MALLOC_OVERHEAD);
}
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 *end, Dwarf_Addr *notes)
*notes = *end;
}
- Dwarf_Addr round_kernel = sysconf (_SC_PAGESIZE);
+ Dwarf_Addr round_kernel = sys_get_page_size();
*start &= -(Dwarf_Addr) round_kernel;
*end += round_kernel - 1;
*end &= -(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;
- *elfp = elf_from_remote_memory (base, sysconf (_SC_PAGESIZE), NULL,
+ *elfp = elf_from_remote_memory (base, sys_get_page_size(), NULL,
&read_proc_memory, &fd);
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)
/* Make sure the content hits the disk. */
char *msync_start = ((char *) elf->map_address
- + (elf->start_offset & ~(sysconf (_SC_PAGESIZE) - 1)));
+ + (elf->start_offset & ~(sys_get_page_size() - 1)));
char *msync_end = ((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 <= len);
/* Tell the kernel we will read all the pages sequentially. */
- size_t ps = sysconf (_SC_PAGESIZE);
+ size_t ps = sys_get_page_size();
if (n > 2 * ps)
posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL);
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 <= len);
/* Tell the kernel we will read all the pages sequentially. */
- size_t ps = sysconf (_SC_PAGESIZE);
+ size_t ps = sys_get_page_size();
if (n > 2 * ps)
posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL);
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);
/* Determine the page size. We will likely need it a couple of times. */
- ps = sysconf (_SC_PAGESIZE);
+ ps = sys_get_page_size();
struct stat st;
int result = 0;
--
2.36.1.windows.1
next prev parent reply other threads:[~2022-10-20 18:27 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
2022-10-27 13:02 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
2022-10-27 13:03 ` Mark Wielaard
2022-12-16 21:14 ` 罗勇刚(Yonggang Luo)
2022-12-20 12:35 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
2022-10-27 13:09 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
2022-10-27 13:20 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
2022-10-27 13:26 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
2022-10-28 11:35 ` Mark Wielaard
2022-12-16 21:19 ` 罗勇刚(Yonggang Luo)
2022-12-20 13:59 ` Mark Wielaard
2022-12-20 17:44 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
2022-10-28 12:07 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
2022-10-28 11:41 ` Mark Wielaard
2022-12-16 21:21 ` 罗勇刚(Yonggang Luo)
2022-12-20 14:04 ` Mark Wielaard
2022-12-20 16:30 ` 罗勇刚(Yonggang Luo)
2022-12-21 16:54 ` Mark Wielaard
2022-12-22 3:50 ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 09/25] include libgen.h in system.h Yonggang Luo
2022-10-28 11:45 ` Mark Wielaard
2022-12-16 21:22 ` 罗勇刚(Yonggang Luo)
2022-12-16 21:34 ` 罗勇刚(Yonggang Luo)
2022-12-20 15:05 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
2022-12-12 12:37 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 12:42 ` Mark Wielaard
2022-12-16 21:36 ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 12/25] libcpu: Use "#define FCT_mod$64r_m FCT_mod$r_m" is enough and can be recognized by clang-cl on windows in i386_data.h Yonggang Luo
2022-12-12 12:58 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 13:12 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
2022-12-12 13:31 ` Mark Wielaard
2022-12-16 21:47 ` 罗勇刚(Yonggang Luo)
2022-12-20 15:08 ` Mark Wielaard
2022-12-20 16:31 ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
2022-12-12 15:37 ` Mark Wielaard
2022-12-16 21:50 ` 罗勇刚(Yonggang Luo)
2022-12-20 15:10 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
2022-12-12 15:45 ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
2022-10-20 18:25 ` [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h> Yonggang Luo
2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
2022-12-12 15:54 ` Mark Wielaard
2022-10-20 18:25 ` Yonggang Luo [this message]
2022-10-20 18:26 ` [PATCH 21/25] libasm: stdio_ext.h are not present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
2022-10-20 18:26 ` [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 24/25] lib: isatty is not available on windows Yonggang Luo
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=20221020182603.815-21-luoyonggang@gmail.com \
--to=luoyonggang@gmail.com \
--cc=elfutils-devel@sourceware.org \
/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).