/****************************************************************** * macho_search_and_load_file * * Lookup a file in standard Mach-O locations, and if found, load it */ static BOOL macho_search_and_load_file(struct process* pcs, const WCHAR* filename, unsigned long load_addr, struct macho_info* macho_info) { BOOL ret = FALSE; struct module* module; static WCHAR S_libstdcPPW[] = {'l','i','b','s','t','d','c','+','+','\0'}; const WCHAR* p; TRACE("(%p/%p, %s, 0x%08lx, %p)\n", pcs, pcs->handle, debugstr_w(filename), load_addr, macho_info); if (filename == NULL || *filename == '\0') return FALSE; if ((module = module_is_already_loaded(pcs, filename))) { macho_info->module = module; module->format_info[DFI_MACHO]->u.macho_info->in_use = 1; return module->module.SymType; } if (strstrW(filename, S_libstdcPPW)) return FALSE; /* We know we can't do it */ /* If has no directories, try LD_LIBRARY_PATH first. */ if (!strchrW(filename, '/')) { ret = macho_load_file_from_path(pcs, filename, load_addr, getenv("PATH"), macho_info); } /* Try DYLD_LIBRARY_PATH, with just the filename (no directories). */ if (!ret) { if ((p = strrchrW(filename, '/'))) p++; else p = filename; ret = macho_load_file_from_path(pcs, p, load_addr, getenv("DYLD_LIBRARY_PATH"), macho_info); } /* Try the path as given. */ if (!ret) ret = macho_load_file(pcs, filename, load_addr, macho_info); /* Try DYLD_FALLBACK_LIBRARY_PATH, with just the filename (no directories). */ if (!ret) { ret = macho_load_file_from_path(pcs, p, load_addr, getenv("DYLD_FALLBACK_LIBRARY_PATH"), macho_info); } if (!ret && !strchrW(filename, '/')) ret = macho_load_file_from_dll_path(pcs, filename, load_addr, macho_info); return ret; }
/*********************************************************************** * SymLoadModuleExW (DBGHELP.@) */ DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName, PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll, PMODLOAD_DATA Data, DWORD Flags) { struct process* pcs; struct module* module = NULL; TRACE("(%p %p %s %s %s %08x %p %08x)\n", hProcess, hFile, debugstr_w(wImageName), debugstr_w(wModuleName), wine_dbgstr_longlong(BaseOfDll), SizeOfDll, Data, Flags); if (Data) FIXME("Unsupported load data parameter %p for %s\n", Data, debugstr_w(wImageName)); if (!validate_addr64(BaseOfDll)) return FALSE; if (!(pcs = process_find_by_handle(hProcess))) return FALSE; if (Flags & SLMFLAG_VIRTUAL) { if (!wImageName) return FALSE; module = module_new(pcs, wImageName, module_get_type_by_name(wImageName), TRUE, BaseOfDll, SizeOfDll, 0, 0); if (!module) return FALSE; if (wModuleName) module_set_module(module, wModuleName); module->module.SymType = SymVirtual; return TRUE; } if (Flags & ~(SLMFLAG_VIRTUAL)) FIXME("Unsupported Flags %08x for %s\n", Flags, debugstr_w(wImageName)); refresh_module_list(pcs); /* this is a Wine extension to the API just to redo the synchronisation */ if (!wImageName && !hFile) return 0; /* check if the module is already loaded, or if it's a builtin PE module with * an containing ELF module */ if (wImageName) { module = module_is_already_loaded(pcs, wImageName); if (!module && module_is_container_loaded(pcs, wImageName, BaseOfDll)) { /* force the loading of DLL as builtin */ module = pe_load_builtin_module(pcs, wImageName, BaseOfDll, SizeOfDll); } } if (!module) { /* otherwise, try a regular PE module */ if (!(module = pe_load_native_module(pcs, wImageName, hFile, BaseOfDll, SizeOfDll)) && wImageName) { /* and finally an ELF or Mach-O module */ switch (module_get_type_by_name(wImageName)) { case DMT_ELF: module = elf_load_module(pcs, wImageName, BaseOfDll); break; case DMT_MACHO: module = macho_load_module(pcs, wImageName, BaseOfDll); break; default: /* Ignored */ break; } } } if (!module) { WARN("Couldn't locate %s\n", debugstr_w(wImageName)); return 0; } module->module.NumSyms = module->ht_symbols.num_elts; /* by default module_new fills module.ModuleName from a derivation * of LoadedImageName. Overwrite it, if we have better information */ if (wModuleName) module_set_module(module, wModuleName); if (wImageName) lstrcpynW(module->module.ImageName, wImageName, sizeof(module->module.ImageName) / sizeof(WCHAR)); return module->module.BaseOfImage; }