45 while (*p != 0 && *p != delimiter)
62 char *path = (
char *)
format (0,
"%s/%s%c", dir, file, 0);
66 yes = (stat (path, &s) >= 0
67 && S_ISREG (s.st_mode)
68 && 0 != (s.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)));
83 if (file[0] ==
'.' || file[0] ==
'/')
86 if (getenv (
"PATH") == 0)
96 if (i < vec_len (ps.
path))
97 result = (
char *)
format (0,
"%s/%s%c", ps.
path[i], file);
106 char *file_name,
void *link_address)
112 uword mmap_length = 0;
118 fd = open (file_name, 0);
125 if (fstat (fd, &fd_stat) < 0)
130 mmap_length = fd_stat.st_size;
132 data = mmap (0, mmap_length, PROT_READ, MAP_SHARED, fd, 0);
139 error =
elf_parse (em, data, mmap_length);
146 uword section_name_start_len = strlen (section_name_start);
156 if (memcmp (name, section_name_start, section_name_start_len))
159 name += section_name_start_len;
165 name =
format (0,
"%s%c", name, 0);
174 b->
lo = link_address + s->
header.exec_address;
199 if (s->
header.type != ELF_SECTION_STRING_TABLE)
210 munmap (data, mmap_length);
222 char *name = (
char *) info->dlpi_name;
223 void *
addr = (
void *) info->dlpi_addr;
226 is_main = strlen (name) == 0;
303 if (by_address >= x->value && by_address < x->value + x->size)
361 s =
format (s,
"%s + 0x%wx",
363 address - sym.
symbol.value);
366 s =
format (s,
"0x%wx", address);
clib_elf_section_t * sections
static void elf_main_free(elf_main_t *em)
sll srl srl sll sra u16x4 i
static u8 * elf_section_name(elf_main_t *em, elf_section_t *s)
static void path_search_free(path_search_t *p)
static int file_exists_and_is_executable(char *dir, char *file)
#define clib_error(format, args...)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define CLIB_ELF_SECTION_ADD_PREFIX(n)
#define hash_set_mem(h, key, value)
void elf_parse_symbols(elf_main_t *em)
uword clib_elf_symbol_by_address(uword by_address, clib_elf_symbol_t *s)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
clib_elf_section_bounds_t * bounds
static clib_error_t * clib_elf_parse_file(clib_elf_main_t *cem, char *file_name, void *link_address)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static char ** split_string(char *string, u8 delimiter)
elf_symbol_table_t * symbol_tables
static uword pointer_to_uword(const void *p)
#define hash_create_string(elts, value_bytes)
#define clib_error_return_unix(e, args...)
#define vec_free(V)
Free vector's memory (no header).
void clib_elf_main_init(char *exec_path)
uword clib_elf_symbol_by_name(char *by_name, clib_elf_symbol_t *s)
#define clib_error_report(e)
static char * path_search(char *file)
clib_elf_section_bounds_t * clib_elf_get_section_bounds(char *name)
static uword symbol_by_address_or_name(char *by_name, uword by_address, clib_elf_symbol_t *s)
#define vec_elt(v, i)
Get vector value at index i.
u8 * format_clib_elf_symbol(u8 *s, va_list *args)
static u8 * elf_symbol_name(elf_symbol_table_t *t, elf64_symbol_t *sym)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * elf_parse(elf_main_t *em, void *data, uword data_bytes)
format_function_t format_elf_symbol
#define hash_get_mem(h, key)
u8 * format_clib_elf_symbol_with_address(u8 *s, va_list *args)
elf64_section_header_t header
#define vec_foreach(var, vec)
Vector iterator.
static int add_section(struct dl_phdr_info *info, size_t size, void *opaque)
static clib_elf_main_t clib_elf_main