1 /* 2 * 3 * Copyright (c) 2015 Mark Johnston <markj@FreeBSD.org> 4 * Copyright (c) 2025 Kyle Evans <kevans@FreeBSD.org> 5 * 6 * SPDX-License-Identifier: BSD-2-Clause 7 * 8 */ 9 10 #ifndef _SYS_UCOREDUMP_H_ 11 #define _SYS_UCOREDUMP_H_ 12 13 #ifdef _KERNEL 14 15 #include <sys/_uio.h> 16 #include <sys/blockcount.h> 17 #include <sys/queue.h> 18 19 /* Coredump output parameters. */ 20 struct coredump_params; 21 struct coredump_writer; 22 struct thread; 23 struct ucred; 24 25 typedef int coredump_init_fn(const struct coredump_writer *, 26 const struct coredump_params *); 27 typedef int coredump_write_fn(const struct coredump_writer *, const void *, size_t, 28 off_t, enum uio_seg, struct ucred *, size_t *, struct thread *); 29 typedef int coredump_extend_fn(const struct coredump_writer *, off_t, 30 struct ucred *); 31 32 struct coredump_vnode_ctx { 33 struct vnode *vp; 34 struct ucred *fcred; 35 }; 36 37 coredump_write_fn core_vn_write; 38 coredump_extend_fn core_vn_extend; 39 40 struct coredump_writer { 41 void *ctx; 42 coredump_init_fn *init_fn; 43 coredump_write_fn *write_fn; 44 coredump_extend_fn *extend_fn; 45 }; 46 47 struct coredump_params { 48 off_t offset; 49 struct ucred *active_cred; 50 struct thread *td; 51 const struct coredump_writer *cdw; 52 struct compressor *comp; 53 }; 54 55 #define CORE_BUF_SIZE (16 * 1024) 56 57 int core_write(struct coredump_params *, const void *, size_t, off_t, 58 enum uio_seg, size_t *); 59 int core_output(char *, size_t, off_t, struct coredump_params *, void *); 60 int sbuf_drain_core_output(void *, const char *, int); 61 62 extern int coredump_pack_fileinfo; 63 extern int coredump_pack_vmmapinfo; 64 65 extern int compress_user_cores; 66 extern int compress_user_cores_level; 67 68 typedef int coredumper_probe_fn(struct thread *); 69 70 /* 71 * Some arbitrary values for coredumper probes to return. The highest priority 72 * we can find wins. It's somewhat expected that a coredumper may want to bid 73 * differently based on the process in question. Note that probe functions will 74 * be called with the proc lock held, so they must not sleep. 75 */ 76 #define COREDUMPER_NOMATCH (-1) /* Decline to touch it */ 77 #define COREDUMPER_GENERIC (0) /* I handle coredumps */ 78 #define COREDUMPER_SPECIAL (50) /* Special handler */ 79 #define COREDUMPER_HIGH_PRIORITY (100) /* High-priority handler */ 80 81 /* 82 * The handle functions will be called with the proc lock held, and should 83 * return with the proc lock dropped. 84 */ 85 typedef int coredumper_handle_fn(struct thread *, off_t); 86 87 struct coredumper { 88 SLIST_ENTRY(coredumper) cd_entry; 89 const char *cd_name; 90 coredumper_probe_fn *cd_probe; 91 coredumper_handle_fn *cd_handle; 92 blockcount_t cd_refcount; 93 }; 94 95 void coredumper_register(struct coredumper *); 96 void coredumper_unregister(struct coredumper *); 97 98 #endif /* _KERNEL */ 99 #endif /* _SYS_UCOREDUMP_H_ */ 100