git: f9ca52bab510 - main - Use getpagesize in gcore to find the page size

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Thu, 19 May 2022 10:33:20 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=f9ca52bab510ff97c6a3c513ddce698a0d19934c

commit f9ca52bab510ff97c6a3c513ddce698a0d19934c
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-05-13 11:56:14 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-05-19 10:32:26 +0000

    Use getpagesize in gcore to find the page size
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D35194
---
 usr.bin/gcore/elfcore.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c
index 1fcd14698a9e..6ef1f31d28cd 100644
--- a/usr.bin/gcore/elfcore.c
+++ b/usr.bin/gcore/elfcore.c
@@ -234,7 +234,7 @@ elf_coredump(int efd, int fd, pid_t pid)
 	/* Put notes. */
 	elf_putnotes(pid, sb, &notesz);
 	/* Align up to a page boundary for the program segments. */
-	sbuf_end_section(sb, -1, PAGE_SIZE, 0);
+	sbuf_end_section(sb, -1, getpagesize(), 0);
 	if (sbuf_finish(sb) != 0)
 		err(1, "sbuf_finish");
 	hdr = sbuf_data(sb);
@@ -295,15 +295,17 @@ cb_put_phdr(struct map_entry *entry, void *closure)
 {
 	struct phdr_closure *phc = (struct phdr_closure *)closure;
 	Elf_Phdr *phdr = phc->phdr;
+	size_t page_size;
 
-	phc->offset = round_page(phc->offset);
+	page_size = getpagesize();
+	phc->offset = roundup2(phc->offset, page_size);
 
 	phdr->p_type = PT_LOAD;
 	phdr->p_offset = phc->offset;
 	phdr->p_vaddr = entry->start;
 	phdr->p_paddr = 0;
 	phdr->p_filesz = phdr->p_memsz = entry->end - entry->start;
-	phdr->p_align = PAGE_SIZE;
+	phdr->p_align = page_size;
 	phdr->p_flags = 0;
 	if (entry->protection & VM_PROT_READ)
 		phdr->p_flags |= PF_R;