| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | 
|---|
| 2 | #ifndef _LINUX_COREDUMP_H | 
|---|
| 3 | #define _LINUX_COREDUMP_H | 
|---|
| 4 |  | 
|---|
| 5 | #include <linux/types.h> | 
|---|
| 6 | #include <linux/mm.h> | 
|---|
| 7 | #include <linux/fs.h> | 
|---|
| 8 | #include <asm/siginfo.h> | 
|---|
| 9 |  | 
|---|
| 10 | #ifdef CONFIG_COREDUMP | 
|---|
| 11 | struct core_vma_metadata { | 
|---|
| 12 | unsigned long start, end; | 
|---|
| 13 | vm_flags_t flags; | 
|---|
| 14 | unsigned long dump_size; | 
|---|
| 15 | unsigned long pgoff; | 
|---|
| 16 | struct file   *file; | 
|---|
| 17 | }; | 
|---|
| 18 |  | 
|---|
| 19 | struct coredump_params { | 
|---|
| 20 | const kernel_siginfo_t *siginfo; | 
|---|
| 21 | struct file *file; | 
|---|
| 22 | unsigned long limit; | 
|---|
| 23 | unsigned long mm_flags; | 
|---|
| 24 | int cpu; | 
|---|
| 25 | loff_t written; | 
|---|
| 26 | loff_t pos; | 
|---|
| 27 | loff_t to_skip; | 
|---|
| 28 | int vma_count; | 
|---|
| 29 | size_t vma_data_size; | 
|---|
| 30 | struct core_vma_metadata *vma_meta; | 
|---|
| 31 | struct pid *pid; | 
|---|
| 32 | }; | 
|---|
| 33 |  | 
|---|
| 34 | extern unsigned int core_file_note_size_limit; | 
|---|
| 35 |  | 
|---|
| 36 | /* | 
|---|
| 37 | * These are the only things you should do on a core-file: use only these | 
|---|
| 38 | * functions to write out all the necessary info. | 
|---|
| 39 | */ | 
|---|
| 40 | extern void dump_skip_to(struct coredump_params *cprm, unsigned long to); | 
|---|
| 41 | extern void dump_skip(struct coredump_params *cprm, size_t nr); | 
|---|
| 42 | extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr); | 
|---|
| 43 | extern int dump_align(struct coredump_params *cprm, int align); | 
|---|
| 44 | int dump_user_range(struct coredump_params *cprm, unsigned long start, | 
|---|
| 45 | unsigned long len); | 
|---|
| 46 | extern void vfs_coredump(const kernel_siginfo_t *siginfo); | 
|---|
| 47 |  | 
|---|
| 48 | /* | 
|---|
| 49 | * Logging for the coredump code, ratelimited. | 
|---|
| 50 | * The TGID and comm fields are added to the message. | 
|---|
| 51 | */ | 
|---|
| 52 |  | 
|---|
| 53 | #define __COREDUMP_PRINTK(Level, Format, ...) \ | 
|---|
| 54 | do {	\ | 
|---|
| 55 | char comm[TASK_COMM_LEN];	\ | 
|---|
| 56 | /* This will always be NUL terminated. */ \ | 
|---|
| 57 | memcpy(comm, current->comm, sizeof(comm)); \ | 
|---|
| 58 | printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n",	\ | 
|---|
| 59 | task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__);	\ | 
|---|
| 60 | } while (0)	\ | 
|---|
| 61 |  | 
|---|
| 62 | #define coredump_report(fmt, ...) __COREDUMP_PRINTK(KERN_INFO, fmt, ##__VA_ARGS__) | 
|---|
| 63 | #define coredump_report_failure(fmt, ...) __COREDUMP_PRINTK(KERN_WARNING, fmt, ##__VA_ARGS__) | 
|---|
| 64 |  | 
|---|
| 65 | #else | 
|---|
| 66 | static inline void vfs_coredump(const kernel_siginfo_t *siginfo) {} | 
|---|
| 67 |  | 
|---|
| 68 | #define coredump_report(...) | 
|---|
| 69 | #define coredump_report_failure(...) | 
|---|
| 70 |  | 
|---|
| 71 | #endif | 
|---|
| 72 |  | 
|---|
| 73 | #if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL) | 
|---|
| 74 | extern void validate_coredump_safety(void); | 
|---|
| 75 | #else | 
|---|
| 76 | static inline void validate_coredump_safety(void) {} | 
|---|
| 77 | #endif | 
|---|
| 78 |  | 
|---|
| 79 | #endif /* _LINUX_COREDUMP_H */ | 
|---|
| 80 |  | 
|---|