int trusty_app_symbolize(struct trusty_app* app,
uintptr_t pc, struct pc_symbol_info* info) { if (!app) { goto out_no_symbol;
} /* Adjust pc to be relative to app image */ if (__builtin_sub_overflow(pc, app->load_bias, &pc)) { goto out_no_symbol;
} /* pc must be within the app image */ struct trusty_app_img* app_img = &app->app_img; if (app_img->img_end <= app_img->img_start) { goto out_no_symbol;
} if (pc > app_img->img_end - app_img->img_start) { goto out_no_symbol;
}
/* Find section headers for .symtab and .strtab */ for (size_t i = 0; i < ehdr->e_shnum; i++) { if (shdr[i].sh_type == SHT_SYMTAB) {
symtab_shdr = shdr + i;
} if (shdr[i].sh_type == SHT_STRTAB) {
strtab_shdr = shdr + i;
}
}
/* Handle the case when app is not built with .symtab or .strtab */ if (!symtab_shdr || !strtab_shdr) {
LTRACEF("App built without symbol table\n"); goto out_no_symbol;
}
/* Validate .symtab and .strtab locations */ if (!range_within_app_img(symtab_start, symtab_size, app_img)) {
TRACEF(".symtab section is not within the app image\n"); goto out_no_symbol;
} if (!range_within_app_img(strtab_start, strtab_size, app_img)) {
TRACEF(".strtab section is not within the app image\n"); goto out_no_symbol;
}
/* Find closest symbol preceding pc */
info->offset = ULONG_MAX; for (uintptr_t curr = symtab_start;
curr < symtab_start + symtab_shdr->sh_size;
curr += symtab_shdr->sh_entsize) { /* Entry must be within .symtab section */ if (!range_within_range(curr, symtab_shdr->sh_entsize, symtab_start,
symtab_size)) {
TRACEF(".symtab section is malformed\n"); goto out_no_symbol;
}
ELF_SYM* symtab_entry = (ELF_SYM*)curr; /* We are looking for a symbol of a function */ if (ELF_ST_TYPE(symtab_entry->st_info) != STT_FUNC) { continue;
}
uintptr_t func_start = symtab_entry->st_value; if (func_start <= pc && info->offset > pc - func_start) { /* Offset must be within .strtab section */ if (symtab_entry->st_name >= strtab_size) {
TRACEF(".strtab section is malformed\n"); goto out_no_symbol;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.