1 /* SPDX-License-Identifier: GPL-2.0 */ 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 /** 9 * enum execmem_type - types of executable memory ranges 10 * 11 * There are several subsystems that allocate executable memory. 12 * Architectures define different restrictions on placement, 13 * permissions, alignment and other parameters for memory that can be used 14 * by these subsystems. 15 * Types in this enum identify subsystems that allocate executable memory 16 * and let architectures define parameters for ranges suitable for 17 * allocations by each subsystem. 18 * 19 * @EXECMEM_DEFAULT: default parameters that would be used for types that 20 * are not explicitly defined. 21 * @EXECMEM_MODULE_TEXT: parameters for module text sections 22 * @EXECMEM_KPROBES: parameters for kprobes 23 * @EXECMEM_FTRACE: parameters for ftrace 24 * @EXECMEM_BPF: parameters for BPF 25 * @EXECMEM_TYPE_MAX: 26 */ 27 enum execmem_type { 28 EXECMEM_DEFAULT, 29 EXECMEM_MODULE_TEXT = EXECMEM_DEFAULT, 30 EXECMEM_KPROBES, 31 EXECMEM_FTRACE, 32 EXECMEM_BPF, 33 EXECMEM_TYPE_MAX, 34 }; 35 36 /** 37 * execmem_alloc - allocate executable memory 38 * @type: type of the allocation 39 * @size: how many bytes of memory are required 40 * 41 * Allocates memory that will contain executable code, either generated or 42 * loaded from kernel modules. 43 * 44 * The memory will have protections defined by architecture for executable 45 * region of the @type. 46 * 47 * Return: a pointer to the allocated memory or %NULL 48 */ 49 void *execmem_alloc(enum execmem_type type, size_t size); 50 51 /** 52 * execmem_free - free executable memory 53 * @ptr: pointer to the memory that should be freed 54 */ 55 void execmem_free(void *ptr); 56 57 #endif /* _LINUX_EXECMEM_ALLOC_H */ 58