Skip to content
Snippets Groups Projects
Commit f39789bf authored by Simon McVittie's avatar Simon McVittie
Browse files

process_pt_dynamic: Use more type-safe pointers


The type-safety isn't particularly important, but the types make them
more self-documenting.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent a18a17a8
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -230,18 +230,16 @@ reloc_type_name (int type) ...@@ -230,18 +230,16 @@ reloc_type_name (int type)
} }
int int
process_dt_rela (const void *start, process_dt_rela (const ElfW(Rela) *start,
int relasz, int relasz,
const char *strtab, const char *strtab,
const void *symtab, const ElfW(Sym) *symtab,
void *base, void *base,
void *data) void *data)
{ {
ElfW(Rela) *entry; const ElfW(Rela) *entry;
for( entry = (ElfW(Rela) *)start; for( entry = start; entry < start + (relasz / sizeof(*entry)); entry++ )
entry < (ElfW(Rela) *)(start + relasz);
entry++ )
{ {
int sym; int sym;
int chr; int chr;
...@@ -403,18 +401,16 @@ process_dt_rela (const void *start, ...@@ -403,18 +401,16 @@ process_dt_rela (const void *start,
} }
int int
process_dt_rel (const void *start, process_dt_rel (const ElfW(Rel) *start,
int relasz, int relasz,
const char *strtab, const char *strtab,
const void *symtab, const ElfW(Sym) *symtab,
void *base, void *base,
void *data) void *data)
{ {
ElfW(Rel) *entry; const ElfW(Rel) *entry;
for( entry = (ElfW(Rel) *)start; for( entry = start; entry < start + (relasz / sizeof(*entry)); entry++ )
entry < (ElfW(Rel) *)(start + relasz);
entry++ )
{ {
int sym; int sym;
int chr; int chr;
...@@ -595,8 +591,8 @@ int ...@@ -595,8 +591,8 @@ int
process_pt_dynamic (ElfW(Addr) start, process_pt_dynamic (ElfW(Addr) start,
size_t size, size_t size,
void *base, void *base,
relocate_cb_t process_rela, relocate_rela_cb_t process_rela,
relocate_cb_t process_rel, relocate_rel_cb_t process_rel,
void *data) void *data)
{ {
int ret = 0; int ret = 0;
...@@ -605,8 +601,7 @@ process_pt_dynamic (ElfW(Addr) start, ...@@ -605,8 +601,7 @@ process_pt_dynamic (ElfW(Addr) start,
int relasz = -1; int relasz = -1;
int jmprelsz = -1; int jmprelsz = -1;
int jmpreltype = DT_NULL; int jmpreltype = DT_NULL;
const void *relstart; const ElfW(Sym) *symtab = NULL;
const void *symtab = NULL;
const char *strtab = dynamic_section_find_strtab( base + start, base, NULL ); const char *strtab = dynamic_section_find_strtab( base + start, base, NULL );
DEBUG( DEBUG_ELF, DEBUG( DEBUG_ELF,
...@@ -672,6 +667,8 @@ process_pt_dynamic (ElfW(Addr) start, ...@@ -672,6 +667,8 @@ process_pt_dynamic (ElfW(Addr) start,
case DT_RELA: case DT_RELA:
if( process_rela != NULL ) if( process_rela != NULL )
{ {
const ElfW(Rela) *relstart;
DEBUG( DEBUG_ELF, "processing DT_RELA section" ); DEBUG( DEBUG_ELF, "processing DT_RELA section" );
if( relasz == -1 ) if( relasz == -1 )
{ {
...@@ -706,6 +703,8 @@ process_pt_dynamic (ElfW(Addr) start, ...@@ -706,6 +703,8 @@ process_pt_dynamic (ElfW(Addr) start,
case DT_REL: case DT_REL:
if( process_rel != NULL ) if( process_rel != NULL )
{ {
const ElfW(Rel) *relstart;
DEBUG( DEBUG_ELF, DEBUG( DEBUG_ELF,
"processing DT_JMPREL/DT_REL section" ); "processing DT_JMPREL/DT_REL section" );
relstart = fix_addr( base, entry->d_un.d_ptr ); relstart = fix_addr( base, entry->d_un.d_ptr );
...@@ -723,6 +722,8 @@ process_pt_dynamic (ElfW(Addr) start, ...@@ -723,6 +722,8 @@ process_pt_dynamic (ElfW(Addr) start,
case DT_RELA: case DT_RELA:
if( process_rela != NULL ) if( process_rela != NULL )
{ {
const ElfW(Rela) *relstart;
DEBUG( DEBUG_ELF, DEBUG( DEBUG_ELF,
"processing DT_JMPREL/DT_RELA section" ); "processing DT_JMPREL/DT_RELA section" );
relstart = fix_addr( base, entry->d_un.d_ptr ); relstart = fix_addr( base, entry->d_un.d_ptr );
......
...@@ -41,7 +41,25 @@ typedef struct ...@@ -41,7 +41,25 @@ typedef struct
} relocation_data_t; } relocation_data_t;
/* /*
* relocate_cb_t: * relocate_rela_cb_t:
* @start: array of relocation entries
* @relasz: number of bytes (not number of structs!) following @start
* @strtab: string table, a series of 0-terminated strings concatenated
* @symtab: symbol table, an array of ElfW(Sym) structs
* @base: base address of the shared object
* @data: the same data that was passed to process_pt_dynamic()
*
* Callback used to iterate over relocations.
*/
typedef int (*relocate_rela_cb_t)(const ElfW(Rela) *start,
const int relasz,
const char *strtab,
const ElfW(Sym) *symtab,
void *base,
void *data);
/*
* relocate_rel_cb_t:
* @start: beginning of an array of relocation entries * @start: beginning of an array of relocation entries
* @relasz: number of bytes (not number of structs!) following @start * @relasz: number of bytes (not number of structs!) following @start
* @strtab: string table, a series of 0-terminated strings concatenated * @strtab: string table, a series of 0-terminated strings concatenated
...@@ -51,30 +69,30 @@ typedef struct ...@@ -51,30 +69,30 @@ typedef struct
* *
* Callback used to iterate over relocations. * Callback used to iterate over relocations.
*/ */
typedef int (*relocate_cb_t)(const void *start, typedef int (*relocate_rel_cb_t)(const ElfW(Rel) *start,
const int relasz, const int relasz,
const char *strtab, const char *strtab,
const void *symtab, const ElfW(Sym) *symtab,
void *base, void *base,
void *data); void *data);
int process_dt_rela (const void *start, int process_dt_rela (const ElfW(Rela) *start,
const int relasz, const int relasz,
const char *strtab, const char *strtab,
const void *symtab, const ElfW(Sym) *symtab,
void *base, void *base,
void *data); void *data);
int process_dt_rel (const void *start, int process_dt_rel (const ElfW(Rel) *start,
const int relasz, const int relasz,
const char *strtab, const char *strtab,
const void *symtab, const ElfW(Sym) *symtab,
void *base, void *base,
void *data); void *data);
int process_pt_dynamic (ElfW(Addr) start, int process_pt_dynamic (ElfW(Addr) start,
size_t size, size_t size,
void *base, void *base,
relocate_cb_t process_rela, relocate_rela_cb_t process_rela,
relocate_cb_t process_rel, relocate_rel_cb_t process_rel,
void *data); void *data);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment