1 /*
2  * Copyright (c) 2024 Arduino SA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SUBSYS_LLEXT_PRIV_H_
8 #define ZEPHYR_SUBSYS_LLEXT_PRIV_H_
9 
10 #include <zephyr/kernel.h>
11 #include <zephyr/llext/llext.h>
12 #include <zephyr/llext/llext_internal.h>
13 
14 /*
15  * Memory management (llext_mem.c)
16  */
17 
18 int llext_copy_strings(struct llext_loader *ldr, struct llext *ext,
19 		       const struct llext_load_param *ldr_parm);
20 int llext_copy_regions(struct llext_loader *ldr, struct llext *ext,
21 		       const struct llext_load_param *ldr_parm);
22 void llext_free_regions(struct llext *ext);
23 void llext_adjust_mmu_permissions(struct llext *ext);
24 
llext_alloc(size_t bytes)25 static inline void *llext_alloc(size_t bytes)
26 {
27 	extern struct k_heap llext_heap;
28 
29 	return k_heap_alloc(&llext_heap, bytes, K_NO_WAIT);
30 }
31 
llext_aligned_alloc(size_t align,size_t bytes)32 static inline void *llext_aligned_alloc(size_t align, size_t bytes)
33 {
34 	extern struct k_heap llext_heap;
35 
36 	return k_heap_aligned_alloc(&llext_heap, align, bytes, K_NO_WAIT);
37 }
38 
llext_free(void * ptr)39 static inline void llext_free(void *ptr)
40 {
41 	extern struct k_heap llext_heap;
42 
43 	k_heap_free(&llext_heap, ptr);
44 }
45 
46 /*
47  * ELF parsing (llext_load.c)
48  */
49 
50 int do_llext_load(struct llext_loader *ldr, struct llext *ext,
51 		  const struct llext_load_param *ldr_parm);
52 
53 /*
54  * Relocation (llext_link.c)
55  */
56 
57 int llext_link(struct llext_loader *ldr, struct llext *ext,
58 	       const struct llext_load_param *ldr_parm);
59 ssize_t llext_file_offset(struct llext_loader *ldr, uintptr_t offset);
60 void llext_dependency_remove_all(struct llext *ext);
61 
62 #endif /* ZEPHYR_SUBSYS_LLEXT_PRIV_H_ */
63