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