@@ -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,
@@ -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
+}
@@ -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);
@@ -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. */
@@ -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);
}
@@ -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;
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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;