1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _LINUX_EXECMEM_ALLOC_H 3 #define _LINUX_EXECMEM_ALLOC_H 4 5 #include <linux/types.h> 6 #include <linux/moduleloader.h> 7 8 #if (defined(CONFIG_KASAN_GENERIC) || defined( 9 !defined(CONFIG_KASAN_VMALLOC) 10 #include <linux/kasan.h> 11 #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADO 12 #else 13 #define MODULE_ALIGN PAGE_SIZE 14 #endif 15 16 /** 17 * enum execmem_type - types of executable mem 18 * 19 * There are several subsystems that allocate 20 * Architectures define different restrictions 21 * permissions, alignment and other parameters 22 * by these subsystems. 23 * Types in this enum identify subsystems that 24 * and let architectures define parameters for 25 * allocations by each subsystem. 26 * 27 * @EXECMEM_DEFAULT: default parameters that w 28 * are not explicitly defined. 29 * @EXECMEM_MODULE_TEXT: parameters for module 30 * @EXECMEM_KPROBES: parameters for kprobes 31 * @EXECMEM_FTRACE: parameters for ftrace 32 * @EXECMEM_BPF: parameters for BPF 33 * @EXECMEM_MODULE_DATA: parameters for module 34 * @EXECMEM_TYPE_MAX: 35 */ 36 enum execmem_type { 37 EXECMEM_DEFAULT, 38 EXECMEM_MODULE_TEXT = EXECMEM_DEFAULT, 39 EXECMEM_KPROBES, 40 EXECMEM_FTRACE, 41 EXECMEM_BPF, 42 EXECMEM_MODULE_DATA, 43 EXECMEM_TYPE_MAX, 44 }; 45 46 /** 47 * enum execmem_range_flags - options for exec 48 * @EXECMEM_KASAN_SHADOW: allocate kasan 49 */ 50 enum execmem_range_flags { 51 EXECMEM_KASAN_SHADOW = (1 << 0), 52 }; 53 54 /** 55 * struct execmem_range - definition of an add 56 * related data allocat 57 * @start: address space start 58 * @end: address space end (inclusive) 59 * @fallback_start: start of the secondary add 60 * allocations on architectur 61 * @fallback_end: start of the secondary add 62 * @pgprot: permissions for memory in this 63 * @alignment: alignment required for text al 64 * @flags: options for memory allocations 65 */ 66 struct execmem_range { 67 unsigned long start; 68 unsigned long end; 69 unsigned long fallback_start; 70 unsigned long fallback_end; 71 pgprot_t pgprot; 72 unsigned int alignment; 73 enum execmem_range_flags flags; 74 }; 75 76 /** 77 * struct execmem_info - architecture paramete 78 * @ranges: array of parameter sets defining a 79 * parameters for executable memory allocation 80 * explicitly initialized by an architecture u 81 * @EXECMEM_DEFAULT. 82 */ 83 struct execmem_info { 84 struct execmem_range ranges[EXECMEM 85 }; 86 87 /** 88 * execmem_arch_setup - define parameters for 89 * 90 * A hook for architectures to define paramete 91 * executable memory. These parameters should 92 * @execmem_info structure. 93 * 94 * For architectures that do not implement thi 95 * parameters will be used 96 * 97 * Return: a structure defining architecture p 98 * for allocations of executable memory 99 */ 100 struct execmem_info *execmem_arch_setup(void); 101 102 /** 103 * execmem_alloc - allocate executable memory 104 * @type: type of the allocation 105 * @size: how many bytes of memory are require 106 * 107 * Allocates memory that will contain executab 108 * loaded from kernel modules. 109 * 110 * Allocates memory that will contain data cou 111 * like data sections in kernel modules. 112 * 113 * The memory will have protections defined by 114 * region of the @type. 115 * 116 * Return: a pointer to the allocated memory o 117 */ 118 void *execmem_alloc(enum execmem_type type, si 119 120 /** 121 * execmem_free - free executable memory 122 * @ptr: pointer to the memory that should be 123 */ 124 void execmem_free(void *ptr); 125 126 #if defined(CONFIG_EXECMEM) && !defined(CONFIG 127 void execmem_init(void); 128 #else 129 static inline void execmem_init(void) {} 130 #endif 131 132 #endif /* _LINUX_EXECMEM_ALLOC_H */ 133
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.