Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 May 2021 01:14:47 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 969dcc5f49af - stable/13 - ELF coredump: define several useful flags for the coredump operations
Message-ID:  <202105100114.14A1ElWl028602@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

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

commit 969dcc5f49af783a91a1e1744b06518c0dd49670
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-04-24 11:45:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-05-10 01:02:16 +0000

    ELF coredump: define several useful flags for the coredump operations
    
    (cherry picked from commit 86ffb3d1a0cbb09ba0123ff8d34149e691b461c4)
---
 sys/kern/imgact_elf.c | 31 ++++++++++++++++++++-----------
 sys/sys/sysent.h      |  5 +++++
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 77045842a13c..563629b747b5 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1655,7 +1655,7 @@ int
 __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
 {
 	struct ucred *cred = td->td_ucred;
-	int error = 0;
+	int compm, error = 0;
 	struct sseg_closure seginfo;
 	struct note_info_list notelst;
 	struct coredump_params params;
@@ -1706,9 +1706,13 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
 	}
 
 	/* Create a compression stream if necessary. */
-	if (compress_user_cores != 0) {
+	compm = compress_user_cores;
+	if ((flags & (SVC_PT_COREDUMP | SVC_NOCOMPRESS)) == SVC_PT_COREDUMP &&
+	    compm == 0)
+		compm = COMPRESS_GZIP;
+	if (compm != 0) {
 		params.comp = compressor_init(core_compressed_write,
-		    compress_user_cores, CORE_BUF_SIZE,
+		    compm, CORE_BUF_SIZE,
 		    compress_user_cores_level, &params);
 		if (params.comp == NULL) {
 			error = EFAULT;
@@ -1826,12 +1830,15 @@ each_dumpable_segment(struct thread *td, segment_callback func, void *closure,
 		 * are marked MAP_ENTRY_NOCOREDUMP now so we no longer
 		 * need to arbitrarily ignore such segments.
 		 */
-		if (elf_legacy_coredump) {
-			if ((entry->protection & VM_PROT_RW) != VM_PROT_RW)
-				continue;
-		} else {
-			if ((entry->protection & VM_PROT_ALL) == 0)
-				continue;
+		if ((flags & SVC_ALL) == 0) {
+			if (elf_legacy_coredump) {
+				if ((entry->protection & VM_PROT_RW) !=
+				    VM_PROT_RW)
+					continue;
+			} else {
+				if ((entry->protection & VM_PROT_ALL) == 0)
+					continue;
+			}
 		}
 
 		/*
@@ -1840,9 +1847,11 @@ each_dumpable_segment(struct thread *td, segment_callback func, void *closure,
 		 * madvise(2).  Do not dump submaps (i.e. parts of the
 		 * kernel map).
 		 */
-		if (entry->eflags & (MAP_ENTRY_NOCOREDUMP|MAP_ENTRY_IS_SUB_MAP))
+		if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0)
+			continue;
+		if ((entry->eflags & MAP_ENTRY_NOCOREDUMP) != 0 &&
+		    (flags & SVC_ALL) == 0)
 			continue;
-
 		if ((object = entry->object.vm_object) == NULL)
 			continue;
 
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index db729239243f..e6db2ec3dfb1 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -171,6 +171,11 @@ struct sysentvec {
 #define	SV_ABI_CLOUDABI	17
 #define	SV_ABI_UNDEF	255
 
+/* sv_coredump flags */
+#define	SVC_PT_COREDUMP	0x00000001	/* dump requested by ptrace(2) */
+#define	SVC_NOCOMPRESS	0x00000002	/* disable compression. */
+#define	SVC_ALL		0x00000004	/* dump everything */
+
 #ifdef _KERNEL
 extern struct sysentvec aout_sysvec;
 extern struct sysent sysent[];



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105100114.14A1ElWl028602>