/* * prex_isaexec() - there is only one case this function get called * 64 bit prex, 32 bit target, need to exec 32 bit * prex here. */ static void prex_isaexec(char **argv, char **envp) { char path[PATH_MAX + sizeof (PREX32DIR)]; strcat(strcat(strcpy(path, dirname(dirname(argv[0]))), PREX32DIR), basename(argv[0])); if (get_elf_class(path) != ELFCLASS32) strcpy(path, PREX32EXEC); argv[0] = path; (void) execve(path, argv, envp); (void) fprintf(stderr, gettext("%s: execve(\"%s\") failed\n"), argv[0], path); exit(1); }
/* * check_exec_model() - check the consistency between prex data model * and target elf class and act accordingly */ static void check_exec_model(char **argv, char **envp) { int elfclass; elfclass = get_elf_class(g_cmdname); if (((elfclass == ELFCLASS32) && (prex_dmodel == PR_MODEL_ILP32)) || ((elfclass == ELFCLASS64) && (prex_dmodel == PR_MODEL_LP64))) return; if ((prex_dmodel == PR_MODEL_ILP32) && (elfclass == ELFCLASS64)) { (void) fprintf(stderr, gettext( "Error: 32 bit prex can not exec 64 bit target\n")); exit(1); } if ((prex_dmodel == PR_MODEL_LP64) && (elfclass == ELFCLASS32)) prex_isaexec(argv, envp); }
int main(int argc, char *argv[]) { opts_t *opts; if ((opts = usage(argc, argv)) == NULL) { exit(-1); } /* TODO Integrity check host for section header table */ int elf_class = get_elf_class(opts->host); if (elf_class == ELF_CLASS_32) { return elfit32(opts); } else if (elf_class == ELF_CLASS_64) { return elfit64(opts); } else { printf("Unkown elf class: %d\n", elf_class); return -1; } }
/* Performs the core dump */ int do_coredump(int pid, char *core_file) { int ret; /* Initialise members of core process */ init_core(); /* Getting thread information and seizing them */ ret = seize_threads(pid); if (ret) goto cleanup; /* Wait for threads to stop */ ret = wait_for_threads_to_stop(); if (ret) goto cleanup; /* Get VMAS */ ret = get_vmas(pid, &cp); if (ret) goto cleanup; /* Compat Support */ cp.elf_class = ret = get_elf_class(pid, &cp); if (ret == -1) goto cleanup; /* Initialise core file name */ cp.corefile = core_file; /* Do elf_dump */ if (cp.elf_class == ELFCLASS32) ret = do_elf32_coredump(pid, &cp); else ret = do_elf64_coredump(pid, &cp); if (ret) goto cleanup; cleanup: /* Release the threads */ release_threads(); if (cp.t_id) free(cp.t_id); if (cp.vmas) free_maps(cp.vmas); if (cp.elf_hdr) free(cp.elf_hdr); if (cp.notes) free_notes(cp.notes); if (cp.phdrs) free(cp.phdrs); if (cp.phdrs_count) free(cp.shdrs); errno = status; return ret; }