Date: Mon, 3 May 2021 16:20:38 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 86ffb3d1a0cb - main - ELF coredump: define several useful flags for the coredump operations Message-ID: <202105031620.143GKcJo022215@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=86ffb3d1a0cbb09ba0123ff8d34149e691b461c4 commit 86ffb3d1a0cbb09ba0123ff8d34149e691b461c4 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-04-24 11:45:01 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-05-03 16:13:47 +0000 ELF coredump: define several useful flags for the coredump operations - SVC_ALL request dumping all map entries, including those marked as non-dumpable - SVC_NOCOMPRESS disallows compressing the dump regardless of the sysctl policy - SVC_PC_COREDUMP is provided for future use by userspace core dump request Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29955 --- 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, ¶ms); 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?202105031620.143GKcJo022215>