~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/execmem.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
  9                 !defined(CONFIG_KASAN_VMALLOC)
 10 #include <linux/kasan.h>
 11 #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
 12 #else
 13 #define MODULE_ALIGN PAGE_SIZE
 14 #endif
 15 
 16 /**
 17  * enum execmem_type - types of executable memory ranges
 18  *
 19  * There are several subsystems that allocate executable memory.
 20  * Architectures define different restrictions on placement,
 21  * permissions, alignment and other parameters for memory that can be used
 22  * by these subsystems.
 23  * Types in this enum identify subsystems that allocate executable memory
 24  * and let architectures define parameters for ranges suitable for
 25  * allocations by each subsystem.
 26  *
 27  * @EXECMEM_DEFAULT: default parameters that would be used for types that
 28  * are not explicitly defined.
 29  * @EXECMEM_MODULE_TEXT: parameters for module text sections
 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 data sections
 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 executable memory allocations
 48  * @EXECMEM_KASAN_SHADOW:       allocate kasan shadow
 49  */
 50 enum execmem_range_flags {
 51         EXECMEM_KASAN_SHADOW    = (1 << 0),
 52 };
 53 
 54 /**
 55  * struct execmem_range - definition of an address space suitable for code and
 56  *                        related data allocations
 57  * @start:      address space start
 58  * @end:        address space end (inclusive)
 59  * @fallback_start: start of the secondary address space range for fallback
 60  *                  allocations on architectures that require it
 61  * @fallback_end:   start of the secondary address space (inclusive)
 62  * @pgprot:     permissions for memory in this address space
 63  * @alignment:  alignment required for text allocations
 64  * @flags:      options for memory allocations for this range
 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 parameters for code allocations
 78  * @ranges: array of parameter sets defining architecture specific
 79  * parameters for executable memory allocations. The ranges that are not
 80  * explicitly initialized by an architecture use parameters defined for
 81  * @EXECMEM_DEFAULT.
 82  */
 83 struct execmem_info {
 84         struct execmem_range    ranges[EXECMEM_TYPE_MAX];
 85 };
 86 
 87 /**
 88  * execmem_arch_setup - define parameters for allocations of executable memory
 89  *
 90  * A hook for architectures to define parameters for allocations of
 91  * executable memory. These parameters should be filled into the
 92  * @execmem_info structure.
 93  *
 94  * For architectures that do not implement this method a default set of
 95  * parameters will be used
 96  *
 97  * Return: a structure defining architecture parameters and restrictions
 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 required
106  *
107  * Allocates memory that will contain executable code, either generated or
108  * loaded from kernel modules.
109  *
110  * Allocates memory that will contain data coupled with executable code,
111  * like data sections in kernel modules.
112  *
113  * The memory will have protections defined by architecture for executable
114  * region of the @type.
115  *
116  * Return: a pointer to the allocated memory or %NULL
117  */
118 void *execmem_alloc(enum execmem_type type, size_t size);
119 
120 /**
121  * execmem_free - free executable memory
122  * @ptr: pointer to the memory that should be freed
123  */
124 void execmem_free(void *ptr);
125 
126 #if defined(CONFIG_EXECMEM) && !defined(CONFIG_ARCH_WANTS_EXECMEM_LATE)
127 void execmem_init(void);
128 #else
129 static inline void execmem_init(void) {}
130 #endif
131 
132 #endif /* _LINUX_EXECMEM_ALLOC_H */
133 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php