git: 9fdb30b9167c - stable/13 - Unstaticize parts of coredumping code

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 12 May 2022 22:56:26 UTC
The branch stable/13 has been updated by jhb:

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

commit 9fdb30b9167c776fe45e37cb062d6a84bced926d
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-05-26 09:23:37 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-12 22:12:59 +0000

    Unstaticize parts of coredumping code
    
    This makes it possible to call __elfN(size_segments) and __elfN(puthdr)
    from Linux coredump code.
    
    Reviewed By:    kib
    Sponsored By:   EPSRC
    Differential Revision:  https://reviews.freebsd.org/D30455
    
    (cherry picked from commit 905d192d6f161496c26db29d0d429525166bfff7)
---
 sys/kern/imgact_elf.c | 23 ++++++++++++-----------
 sys/sys/imgact_elf.h  |  8 ++++++++
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index d2cee91e0531..d189339283a7 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1504,12 +1504,6 @@ struct phdr_closure {
 	Elf_Off offset;		/* Offset of segment in core file */
 };
 
-/* Closure for cb_size_segment(). */
-struct sseg_closure {
-	int count;		/* Count of writable segments. */
-	size_t size;		/* Total size of all writable segments. */
-};
-
 typedef void (*outfunc_t)(void *, struct sbuf *, size_t *);
 
 struct note_info {
@@ -1533,7 +1527,6 @@ static int __elfN(corehdr)(struct coredump_params *, int, void *, size_t,
     struct note_info_list *, size_t, int);
 static void __elfN(prepare_notes)(struct thread *, struct note_info_list *,
     size_t *);
-static void __elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int);
 static void __elfN(putnote)(struct note_info *, struct sbuf *);
 static size_t register_note(struct note_info_list *, int, outfunc_t, void *);
 
@@ -1578,9 +1571,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
 	TAILQ_INIT(&notelst);
 
 	/* Size the program segments. */
-	seginfo.count = 0;
-	seginfo.size = 0;
-	each_dumpable_segment(td, cb_size_segment, &seginfo, flags);
+	__elfN(size_segments)(td, &seginfo, flags);
 
 	/*
 	 * Collect info about the core file header area.
@@ -1715,6 +1706,16 @@ cb_size_segment(vm_map_entry_t entry, void *closure)
 	ssc->size += entry->end - entry->start;
 }
 
+void
+__elfN(size_segments)(struct thread *td, struct sseg_closure *seginfo,
+    int flags)
+{
+	seginfo->count = 0;
+	seginfo->size = 0;
+
+	each_dumpable_segment(td, cb_size_segment, seginfo, flags);
+}
+
 /*
  * For each writable segment in the process's memory map, call the given
  * function with a pointer to the map entry and some arbitrary
@@ -1873,7 +1874,7 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list,
 	*sizep = size;
 }
 
-static void
+void
 __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs,
     size_t notesz, int flags)
 {
diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h
index 5ad26e5c1084..61937642a91a 100644
--- a/sys/sys/imgact_elf.h
+++ b/sys/sys/imgact_elf.h
@@ -100,6 +100,12 @@ __ElfType(Brandinfo);
 
 #define	MAX_BRANDS	8
 
+/* Closure for __elfN(size_segments)(). */
+struct sseg_closure {
+	int count;              /* Count of writable segments. */
+	size_t size;            /* Total size of all writable segments. */
+};
+
 int	__elfN(brand_inuse)(Elf_Brandinfo *entry);
 int	__elfN(insert_brand_entry)(Elf_Brandinfo *entry);
 int	__elfN(remove_brand_entry)(Elf_Brandinfo *entry);
@@ -107,6 +113,8 @@ int	__elfN(freebsd_fixup)(uintptr_t *, struct image_params *);
 int	__elfN(coredump)(struct thread *, struct vnode *, off_t, int);
 size_t	__elfN(populate_note)(int, void *, void *, size_t, void **);
 int	__elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t);
+void	__elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int);
+void	__elfN(size_segments)(struct thread *, struct sseg_closure *, int);
 
 /* Machine specific function to dump per-thread information. */
 void	__elfN(dump_thread)(struct thread *, void *, size_t *);