static int lshowmount(int lookup, int enumerate, int verbose) { NIDList nidlist = NULL; glob_t exp_list; int i; i = get_lustre_param_path("{mgs,mdt,obdfilter}", "*", FILTER_BY_EXACT, "exports", &exp_list); if (i < 0) return i; if (!verbose) nidlist = nl_create(); for (i = 0; i < exp_list.gl_pathc; i++) { if (verbose) { nidlist = nl_create(); read_exports(exp_list.gl_pathv[i], nidlist); print_expname(exp_list.gl_pathv[i]); print_nids(nidlist, lookup, enumerate, 1); nl_destroy(nidlist); } else read_exports(exp_list.gl_pathv[i], nidlist); } if (!verbose) { print_nids(nidlist, lookup, enumerate, 0); nl_destroy(nidlist); } cfs_free_param_data(&exp_list); return i; }
static int lshowmount(int lookup, int enumerate, int verbose) { char *dirs[] = PROC_DIRS; char exp[PATH_MAX + 1]; NIDList nidlist = NULL; DIR *topdirp; struct dirent *dp; int i; int opens = 0; if (!verbose) nidlist = nl_create(); for (i = 0; dirs[i] != NULL; i++) { if ((topdirp = opendir(dirs[i])) == NULL) continue; while ((dp = readdir(topdirp))) { if (dp->d_type != DT_DIR) continue; if (!strcmp(dp->d_name, ".")) continue; if (!strcmp(dp->d_name, "..")) continue; sprintf(exp, PROC_EXPORTS_TMPL, dirs[i], dp->d_name); if (verbose) { nidlist = nl_create(); read_exports(exp, nidlist); printf("%s:\n", dp->d_name); print_nids(nidlist, lookup, enumerate, 1); nl_destroy(nidlist); } else read_exports(exp, nidlist); } closedir(topdirp); opens++; } if (!verbose) { print_nids(nidlist, lookup, enumerate, 0); nl_destroy(nidlist); } return opens; }
int load_pe_images(struct pe_image *pe_image, int n) { struct nt_header *nt_hdr; unsigned int nt_hdr_offset; int i = 0; void *image; int size; struct optional_header *opt_hdr; for (i = 0; i < n; i++) { image = pe_image[i].image; size = pe_image[i].size; /* The PE header is found at the RVA specified at offset 3c. */ if (size < 0x3c + 4) return -EINVAL; nt_hdr_offset = *(unsigned int *)(image+0x3c); nt_hdr = (struct nt_header *)((char *)image + nt_hdr_offset); pe_image[i].type = check_nt_hdr(nt_hdr); if (pe_image[i].type <= 0) return -EINVAL; if (read_exports(image, nt_hdr, pe_image[i].name)) return -EINVAL; } for (i = 0; i < n; i++) { image = pe_image[i].image; size = pe_image[i].size; nt_hdr_offset = *(unsigned int *)(image+0x3c); nt_hdr = (struct nt_header *)((char *)image + nt_hdr_offset); opt_hdr = &nt_hdr->opt_hdr; if (fixup_reloc(image, nt_hdr)) return -EINVAL; if (fixup_imports(image, nt_hdr)) return -EINVAL; flush_icache_range(image, pe_image[i].size); pe_image[i].entry = RVA2VA(image, opt_hdr->opt_std_hdr.entry_rva, void *); DBGTRACE1("entry is at %p, rva at %08X", pe_image[i].entry, (unsigned int)opt_hdr->opt_std_hdr.entry_rva); } for (i = 0; i < n; i++) { image = pe_image[i].image; size = pe_image[i].size; nt_hdr_offset = *(unsigned int *)(image+0x3c); nt_hdr = (struct nt_header *)((char *)image + nt_hdr_offset); opt_hdr = &nt_hdr->opt_hdr; if (pe_image[i].type == COFF_CHAR_DLL) { struct ustring ustring; char *buf = "0\0t0m0p00"; int (*dll_entry)(struct ustring *ustring) STDCALL; memset(&ustring, 0, sizeof(ustring)); ustring.buf = buf; dll_entry = (void *)get_dll_init(pe_image[i].name); DBGTRACE1("calling dll_init at %p", dll_entry); if (!dll_entry || dll_entry(&ustring)) ERROR("DLL initialize failed for %s", pe_image[i].name); } else if (pe_image[i].type == COFF_CHAR_IMAGE) ; else ERROR("illegal image type: %d", pe_image[i].type); }
int load_pe_images(struct pe_image *pe_image, int n) { int i; struct pe_image *pe; #ifdef DEBUG /* Sanity checkings */ CHECK_SZ(IMAGE_SECTION_HEADER, IMAGE_SIZEOF_SECTION_HEADER); CHECK_SZ(IMAGE_FILE_HEADER, IMAGE_SIZEOF_FILE_HEADER); CHECK_SZ(IMAGE_OPTIONAL_HEADER, IMAGE_SIZEOF_NT_OPTIONAL_HEADER); CHECK_SZ(IMAGE_NT_HEADERS, 4 + IMAGE_SIZEOF_FILE_HEADER + IMAGE_SIZEOF_NT_OPTIONAL_HEADER); CHECK_SZ(IMAGE_DOS_HEADER, 0x40); CHECK_SZ(IMAGE_EXPORT_DIRECTORY, 40); CHECK_SZ(IMAGE_BASE_RELOCATION, 8); CHECK_SZ(IMAGE_IMPORT_DESCRIPTOR, 20); #endif for (i = 0; i < n; i++) { IMAGE_DOS_HEADER *dos_hdr; pe = &pe_image[i]; dos_hdr = pe->image; if (pe->size < sizeof(IMAGE_DOS_HEADER)) { DBGTRACE1("image too small: %d", pe->size); return -EINVAL; } pe->nt_hdr = (IMAGE_NT_HEADERS *)(pe->image + dos_hdr->e_lfanew); pe->opt_hdr = &pe->nt_hdr->OptionalHeader; pe->type = check_nt_hdr(pe->nt_hdr); if (pe->type <= 0) { DBGTRACE1("type <= 0"); return -EINVAL; } if (fix_pe_image(pe)) { DBGTRACE1("bad PE image"); return -EINVAL; } if (read_exports(pe)) { DBGTRACE1("read exports failed"); return -EINVAL; } } for (i = 0; i < n; i++) { pe = &pe_image[i]; if (fixup_reloc(pe->image, pe->nt_hdr)) { DBGTRACE1("fixup reloc failed"); return -EINVAL; } if (fixup_imports(pe->image, pe->nt_hdr)) { DBGTRACE1("fixup imports failed"); return -EINVAL; } #if defined(CONFIG_X86_64) INFO("fixing KI_USER_SHARED_DATA address in the driver"); fix_user_shared_data_addr(pe_image[i].image, pe_image[i].size); #endif flush_icache_range(pe->image, pe->size); pe->entry = RVA2VA(pe->image, pe->opt_hdr->AddressOfEntryPoint, void *); DBGTRACE1("entry is at %p, rva at %08X", pe->entry, pe->opt_hdr->AddressOfEntryPoint); } for (i = 0; i < n; i++) { pe = &pe_image[i]; if (pe->type == IMAGE_FILE_DLL) { struct unicode_string ustring; char *buf = "0/0t0m0p00"; int (*dll_entry)(struct unicode_string *ustring) wstdcall; memset(&ustring, 0, sizeof(ustring)); ustring.buf = (wchar_t *)buf; dll_entry = (void *)get_dll_init(pe->name); DBGTRACE1("calling dll_init at %p", dll_entry); if (!dll_entry || dll_entry(&ustring)) ERROR("DLL initialize failed for %s", pe->name); } else if (pe->type != IMAGE_FILE_EXECUTABLE_IMAGE) ERROR("illegal image type: %d", pe->type); }