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// for VSF_ARCH_CFG_CALLSTACK_TRACE and vsf_arch_text_region_t
42
43#if defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
44# define __VSF_CLASS_IMPLEMENT__
45#elif defined(__VSF_ELFLOADER_CLASS_INHERIT__)
46# define __VSF_CLASS_INHERIT__
47#endif
48
49#include "utilities/ooc_class.h"
50
51#if defined(__VSF_ELFLOADER_CLASS_INHERIT__) || defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
52# include "./elf.h"
53#endif
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 // initarr/finiarr point into ram_base(the writable segment owns
79 // them, cleanup frees them with ram_base - never free separately)
80 void *initarr;
81 void *finiarr;
82 uint32_t initarr_sz;
83 uint32_t finiarr_sz;
84 // guard: init at most once per load; fini only after init ran, and
85 // at most once(the applet _start fini path and the later dlclose
86 // path both funnel here - the second caller must see a no-op)
87 bool initarr_done;
88 bool finiarr_done;
89
90 uintptr_t ram_base_vaddr;
91 uintptr_t ram_base_size;
92 bool is_xip;
93 bool is_got;
94 )
95};
96
104
105enum {
109};
110
111/*============================ GLOBAL VARIABLES ==============================*/
112
113extern const struct vsf_loader_op_t vsf_elfloader_op;
114
115/*============================ PROTOTYPES ====================================*/
116
117extern int vsf_elfloader_load(vsf_elfloader_t *elfloader, vsf_loader_target_t *target);
118extern void vsf_elfloader_cleanup(vsf_elfloader_t *elfloader);
120extern void vsf_elfloader_call_fini_array(vsf_elfloader_t *elfloader);
121extern void * vsf_elfloader_remap(vsf_elfloader_t *elfloader, void *vaddr);
122
123// can be called before vsf_elfloader_load
124#if defined(__VSF_ELFLOADER_CLASS_INHERIT__) || defined(__VSF_ELFLOADER_CLASS_IMPLEMENT)
125extern int vsf_elfloader_foreach_program_header(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param,
126 int (*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Phdr *header, int index, void *param));
127extern int vsf_elfloader_foreach_section(vsf_elfloader_t *elfloader, vsf_loader_target_t *target, void *param,
128 int (*callback)(vsf_elfloader_t *, vsf_loader_target_t *, Elf_Shdr *header, char *name, int index, void *param));
129// vsf_elfloader_get_section returns size of the section if found, returns 0 if not found
131 const char *name, Elf_Shdr *header);
132#endif
133
134// CAN NOT be called before vsf_elfloader_load
136 const char *symbol_name, vsf_elfloader_sym_type_t symbol_type);
137
138#ifdef __cplusplus
139}
140#endif
141
142#undef __VSF_ELFLOADER_CLASS_IMPLEMENT
143#undef __VSF_ELFLOADER_CLASS_INHERIT__
144
145 // vsf_elfloader
146
147#endif // VSF_USE_ELFLOADER
148#endif // __VSF_ELFLOADER_H__
Definition vsf_elfloader.h:63
Definition vsf_loader.h:177
#define Elf_Phdr
Definition elf.h:363
#define Elf_Shdr
Definition elf.h:359
#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:168
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:236
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:195
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:778
void * vsf_elfloader_remap(vsf_elfloader_t *elfloader, void *vaddr)
Definition vsf_elfloader.c:304
void vsf_elfloader_call_fini_array(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:281
vsf_elfloader_sym_type_t
Definition vsf_elfloader.h:97
@ VSF_ELFLOADER_SYM_NONE
Definition vsf_elfloader.h:98
@ VSF_ELFLOADER_SYM_OBJECT
Definition vsf_elfloader.h:99
@ VSF_ELFLOADER_SYM_FILE
Definition vsf_elfloader.h:102
@ VSF_ELFLOADER_SYM_FUNC
Definition vsf_elfloader.h:100
@ VSF_ELFLOADER_SYM_SECTION
Definition vsf_elfloader.h:101
int vsf_elfloader_call_init_array(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:264
@ VSF_ELFLOADER_CB_GOON
Definition vsf_elfloader.h:107
@ VSF_ELFLOADER_CB_DONE
Definition vsf_elfloader.h:108
@ VSF_ELFLOADER_CB_FAIL
Definition vsf_elfloader.h:106
int vsf_elfloader_load(vsf_elfloader_t *elfloader, vsf_loader_target_t *target)
Definition vsf_elfloader.c:494
void vsf_elfloader_cleanup(vsf_elfloader_t *elfloader)
Definition vsf_elfloader.c:160
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:107
Generated from commit: vsfteam/vsf@2a137b0