VSF Documented
vsf_elfloader.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
29#ifndef __VSF_ELFLOADER_H__
30#define __VSF_ELFLOADER_H__
31
32/*============================ INCLUDES ======================================*/
33
35
36#if VSF_USE_LOADER == ENABLED && VSF_LOADER_USE_ELF == ENABLED
37
38#include <stdint.h>
39
40#if defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
41# define __VSF_CLASS_IMPLEMENT__
42#elif defined(__VSF_ELFLOADER_CLASS_INHERIT__)
43# define __VSF_CLASS_INHERIT__
44#endif
45
46#include "utilities/ooc_class.h"
47
48#if defined(__VSF_ELFLOADER_CLASS_INHERIT__) || defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
49# include "./elf.h"
50#endif
51
52// for VSF_ARCH_CFG_CALLSTACK_TRACE and vsf_arch_text_region_t
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/*============================ MACROS ========================================*/
60/*============================ MACROFIED FUNCTIONS ===========================*/
61/*============================ TYPES =========================================*/
62
64 public_member(
65 implement(vsf_loader_t)
66 )
67
68 protected_member(
69 void *arch_data;
70#if VSF_ARCH_CFG_CALLSTACK_TRACE == ENABLED
71 vsf_arch_text_region_t arch_text_region;
72#endif
73 )
74
75 private_member(
76 void *ram_base;
77
78 void *initarr;
79 void *finiarr;
80 uint32_t initarr_sz;
81 uint32_t finiarr_sz;
82
83 uintptr_t ram_base_vaddr;
84 uintptr_t ram_base_size;
85 bool is_xip;
86 bool is_got;
87 )
88};
89
91 VSF_ELFLOADER_SYM_NONE = 0, // STT_NOTYPE
92 VSF_ELFLOADER_SYM_OBJECT = 1, // STT_OBJECT
93 VSF_ELFLOADER_SYM_FUNC = 2, // STT_FUNC
94 VSF_ELFLOADER_SYM_SECTION = 3, // STT_SECTION
95 VSF_ELFLOADER_SYM_FILE = 4, // STT_FILE
97
98enum {
102};
103
104/*============================ GLOBAL VARIABLES ==============================*/
105
106extern const struct vsf_loader_op_t vsf_elfloader_op;
107
108/*============================ PROTOTYPES ====================================*/
109
110extern int vsf_elfloader_load(vsf_elfloader_t *elfloader, vsf_loader_target_t *target);
111extern void vsf_elfloader_cleanup(vsf_elfloader_t *elfloader);
113extern void vsf_elfloader_call_fini_array(vsf_elfloader_t *elfloader);
114extern void * vsf_elfloader_remap(vsf_elfloader_t *elfloader, void *vaddr);
115
116// can be called before vsf_elfloader_load
117#if defined(__VSF_ELFLOADER_CLASS_INHERIT__) || defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
118extern int vsf_elfloader_foreach_program_header(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param,
119 int (*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Phdr *header, int index, void *param));
120extern int vsf_elfloader_foreach_section(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param,
121 int (*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Shdr *header, char *name, int index, void *param));
122// vsf_elfloader_get_section returns size of the section if found, returns 0 if not found
124 const char *name, Elf_Shdr *header);
125#endif
126
127// CAN NOT be called before vsf_elfloader_load
129 const char *symbol_name, vsf_elfloader_sym_type_t symbol_type);
130
131#ifdef __cplusplus
132}
133#endif
134
135#undef __VSF_ELFLOADER_CLASS_IMPLEMENT
136#undef __VSF_ELFLOADER_CLASS_INHERIT__
137
// vsf_elfloader
139
140#endif // VSF_USE_ELFLOADER
141#endif // __VSF_ELFLOADER_H__
Definition vsf_elfloader.h:63
Definition vsf_loader.h:176
#define Elf_Phdr
Definition elf.h:359
#define Elf_Shdr
Definition elf.h:355
#define vsf_class(__name)
Definition ooc_class.h:52
uint32_t uintptr_t
Definition stdint.h:38
unsigned uint32_t
Definition stdint.h:9
Definition vsf_arch_abstraction.h:67
Definition vsf_loader.h:167
Definition vsf_loader.h:132
int vsf_elfloader_foreach_program_header(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param, int(*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Phdr *pheader, int index, void *param))
Definition vsf_elfloader.c:226
int vsf_elfloader_foreach_section(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param, int(*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Shdr *header, char *name, int index, void *param))
Definition vsf_elfloader.c:185
uint32_t vsf_elfloader_get_section(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, const char *name, Elf_Shdr *header)
Definition vsf_elfloader.c:665
void * vsf_elfloader_remap(vsf_elfloader_t *elfloader, void *vaddr)
Definition vsf_elfloader.c:283
void vsf_elfloader_call_fini_array(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:267
vsf_elfloader_sym_type_t
Definition vsf_elfloader.h:90
@ VSF_ELFLOADER_SYM_NONE
Definition vsf_elfloader.h:91
@ VSF_ELFLOADER_SYM_OBJECT
Definition vsf_elfloader.h:92
@ VSF_ELFLOADER_SYM_FILE
Definition vsf_elfloader.h:95
@ VSF_ELFLOADER_SYM_FUNC
Definition vsf_elfloader.h:93
@ VSF_ELFLOADER_SYM_SECTION
Definition vsf_elfloader.h:94
int vsf_elfloader_call_init_array(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:254
int vsf_elfloader_load(vsf_elfloader_t *elfloader, vsf_loader_target_t *target)
Definition vsf_elfloader.c:458
@ VSF_ELFLOADER_CB_GOON
Definition vsf_elfloader.h:100
@ VSF_ELFLOADER_CB_DONE
Definition vsf_elfloader.h:101
@ VSF_ELFLOADER_CB_FAIL
Definition vsf_elfloader.h:99
void vsf_elfloader_cleanup(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:150
void * vsf_elfloader_get_symbol(vsf_elfloader_t *elfloader, const char *symbol_name, vsf_elfloader_sym_type_t symbol_type)
const struct vsf_loader_op_t vsf_elfloader_op
Definition vsf_elfloader.c:97
Generated from commit: vsfteam/vsf@1e0abbc