1 /* 2 * SPDX-License-Identifier: CDDL 1.0 3 * 4 * Copyright 2022 Christos Margiolis <christos@FreeBSD.org> 5 */ 6 7 #ifndef _KINST_H_ 8 #define _KINST_H_ 9 10 #include <sys/dtrace.h> 11 12 typedef struct { 13 char kpd_func[DTRACE_FUNCNAMELEN]; 14 char kpd_mod[DTRACE_MODNAMELEN]; 15 int kpd_off; 16 } dtrace_kinst_probedesc_t; 17 18 #define KINSTIOC_MAKEPROBE _IOW('k', 1, dtrace_kinst_probedesc_t) 19 20 #ifdef _KERNEL 21 22 #include <sys/queue.h> 23 24 #include "kinst_isa.h" 25 26 struct kinst_probe { 27 LIST_ENTRY(kinst_probe) kp_hashnext; 28 const char *kp_func; 29 char kp_name[16]; 30 dtrace_id_t kp_id; 31 kinst_patchval_t kp_patchval; 32 kinst_patchval_t kp_savedval; 33 kinst_patchval_t *kp_patchpoint; 34 35 struct kinst_probe_md kp_md; 36 }; 37 38 LIST_HEAD(kinst_probe_list, kinst_probe); 39 40 extern struct kinst_probe_list *kinst_probetab; 41 42 #define KINST_PROBETAB_MAX 0x8000 /* 32k */ 43 #define KINST_ADDR2NDX(addr) (((uintptr_t)(addr)) & (KINST_PROBETAB_MAX - 1)) 44 #define KINST_GETPROBE(i) (&kinst_probetab[KINST_ADDR2NDX(i)]) 45 46 struct linker_file; 47 struct linker_symval; 48 49 int kinst_invop(uintptr_t, struct trapframe *, uintptr_t); 50 int kinst_make_probe(struct linker_file *, int, struct linker_symval *, 51 void *); 52 void kinst_patch_tracepoint(struct kinst_probe *, kinst_patchval_t); 53 void kinst_probe_create(struct kinst_probe *, struct linker_file *); 54 55 int kinst_trampoline_init(void); 56 int kinst_trampoline_deinit(void); 57 uint8_t *kinst_trampoline_alloc(int); 58 void kinst_trampoline_dealloc(uint8_t *); 59 60 int kinst_md_init(void); 61 void kinst_md_deinit(void); 62 63 #ifdef MALLOC_DECLARE 64 MALLOC_DECLARE(M_KINST); 65 #endif /* MALLOC_DECLARE */ 66 67 #define KINST_LOG_HELPER(fmt, ...) \ 68 printf("%s:%d: " fmt "%s\n", __func__, __LINE__, __VA_ARGS__) 69 #define KINST_LOG(...) \ 70 KINST_LOG_HELPER(__VA_ARGS__, "") 71 72 #endif /* _KERNEL */ 73 74 #endif /* _KINST_H_ */ 75