1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef __COREDUMP_TEST_HELPERS_H 4 #define __COREDUMP_TEST_HELPERS_H 5 6 #include <link.h> 7 #include <stdbool.h> 8 #include <sys/types.h> 9 #include <linux/coredump.h> 10 11 #include "../pidfd/pidfd.h" 12 13 #ifndef PAGE_SIZE 14 #define PAGE_SIZE 4096 15 #endif 16 17 #define NUM_THREAD_SPAWN 128 18 19 /* Size of the mostly unpopulated mapping the sparse coredump test maps. */ 20 #define SPARSE_MAPPING_SIZE (256 * 1024 * 1024) 21 22 /* A task mapping at least this much is worth a record stream. */ 23 #define SPARSE_STREAM_THRESHOLD (SPARSE_MAPPING_SIZE / 2) 24 25 /* Size of the shared anonymous mapping the memory types tests map. */ 26 #define MEMORY_MAPPING_SIZE (4 * 1024 * 1024) 27 28 /* Leave the coredump_filter the crashing child inherited alone. */ 29 #define FILTER_TASK_INHERIT ((__u64)-1) 30 31 /* Every memory type the kernel is expected to advertise. */ 32 #define TEST_MEMORY_ALL \ 33 (COREDUMP_MEMORY_ANON_PRIVATE | COREDUMP_MEMORY_ANON_SHARED | \ 34 COREDUMP_MEMORY_FILE_PRIVATE | COREDUMP_MEMORY_FILE_SHARED | \ 35 COREDUMP_MEMORY_ELF_HEADERS | \ 36 COREDUMP_MEMORY_HUGETLB_PRIVATE | COREDUMP_MEMORY_HUGETLB_SHARED | \ 37 COREDUMP_MEMORY_DAX_PRIVATE | COREDUMP_MEMORY_DAX_SHARED) 38 39 /* Shared helper function declarations */ 40 void *do_nothing(void *arg); 41 void crashing_child(void); 42 void crashing_child_thread(void); 43 void crashing_child_sparse(size_t size); 44 void crashing_child_memory(__u64 task_filter, int fd_addr); 45 bool find_coredump_segment(int fd, __u64 vaddr, ElfW(Phdr) *segment); 46 bool sum_coredump_segments(int fd, __u64 *data, __u64 *notes); 47 bool check_coredump_extent(int fd); 48 bool peer_coredump_filter(int fd_peer_pidfd, __u64 *memory_types); 49 ssize_t peer_read_mem(int fd_peer_pidfd, __u64 addr, void *buf, size_t len); 50 ssize_t recv_coredump_records(int fd_coredump, int fd_core_file, 51 off_t *coredump_size, bool *truncated, 52 int fd_peer_pidfd); 53 ssize_t recv_coredump_compact(int fd_coredump, int fd_object, int fd_reference, 54 off_t *coredump_size); 55 ssize_t recv_coredump_bytes(int fd_coredump, int fd_core_file); 56 ssize_t peer_vm_size(int fd_peer_pidfd); 57 bool is_elf_core(int fd); 58 int check_compact_coredump(int fd_object, int fd_reference); 59 int create_detached_tmpfs(void); 60 int create_and_listen_unix_socket(const char *path); 61 bool set_core_pattern(const char *pattern); 62 int get_peer_pidfd(int fd); 63 int get_peer_pidfd_thread(int fd); 64 bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info); 65 66 /* Protocol helper function declarations */ 67 ssize_t recv_marker(int fd); 68 bool read_marker(int fd, enum coredump_mark mark); 69 bool read_hangup(int fd); 70 bool read_coredump_req(int fd, struct coredump_req *req); 71 bool read_coredump_req_sized(int fd, struct coredump_req *req, size_t user_size); 72 bool send_coredump_ack(int fd, const struct coredump_req *req, 73 __u64 mask, size_t size_ack); 74 bool send_coredump_ack_types(int fd, const struct coredump_req *req, 75 __u64 mask, __u64 memory_types, size_t size_ack); 76 bool send_coredump_ack_bytes(int fd, const struct coredump_ack *ack, size_t len); 77 bool check_coredump_req(const struct coredump_req *req); 78 int open_coredump_tmpfile(int fd_tmpfs_detached); 79 void process_coredump_worker(int fd_coredump, int fd_peer_pidfd, int fd_core_file); 80 81 #endif /* __COREDUMP_TEST_HELPERS_H */ 82