git: c74a6c3038ea - stable/13 - Use getpagesize in gcore to find the page size

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 07 Jun 2022 14:23:32 UTC
The branch stable/13 has been updated by andrew:

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

commit c74a6c3038ea1cf381931b59f4c9a3cb2b6eae20
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-05-13 11:56:14 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-06-07 14:20:18 +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
    
    (cherry picked from commit f9ca52bab510ff97c6a3c513ddce698a0d19934c)
---
 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;