dbghelp: Implemented 64 bit versions of EnumerateLoadedModules.
[wine/multimedia.git] / dlls / dbghelp / module.c
blobe7214b3ab20a04e684a4437b516f6c2f2a89217b
1 /*
2 * File module.c - module handling for the wine debugger
4 * Copyright (C) 1993, Eric Youngdale.
5 * 2000-2004, Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "dbghelp_private.h"
29 #include "psapi.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "wine/debug.h"
33 #include "winnls.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
37 static const char * const ext[] = {".acm", ".dll", ".drv", ".exe", ".ocx", ".vxd", NULL};
39 static int match_ext(const char* ptr, size_t len)
41 const char * const *e;
42 size_t l;
44 for (e = ext; *e; e++)
46 l = strlen(*e);
47 if (l >= len) return FALSE;
48 if (strncasecmp(&ptr[len - l], *e, l)) continue;
49 return l;
51 return 0;
54 static void module_fill_module(const char* in, char* out, size_t size)
56 const char *ptr,*endptr;
57 size_t len, l;
59 endptr = in + strlen(in);
60 for (ptr = endptr - 1;
61 ptr >= in && *ptr != '/' && *ptr != '\\';
62 ptr--);
63 ptr++;
64 len = min(endptr-ptr,size-1);
65 memcpy(out, ptr, len);
66 out[len] = '\0';
67 if (len > 4 && (l = match_ext(out, len)))
68 out[len - l] = '\0';
69 else if (len > 12 &&
70 (!strcasecmp(out + len - 12, "wine-pthread") ||
71 !strcasecmp(out + len - 12, "wine-kthread")))
72 lstrcpynA(out, "<wine-loader>", size);
73 else
75 if (len > 3 && !strcasecmp(&out[len - 3], ".so") &&
76 (l = match_ext(out, len - 3)))
77 strcpy(&out[len - l - 3], "<elf>");
79 while ((*out = tolower(*out))) out++;
82 static const char* get_module_type(enum module_type type, BOOL virtual)
84 switch (type)
86 case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
87 case DMT_PE: return virtual ? "Virtual PE" : "PE";
88 default: return "---";
92 /***********************************************************************
93 * Creates and links a new module to a process
95 struct module* module_new(struct process* pcs, const char* name,
96 enum module_type type, BOOL virtual,
97 unsigned long mod_addr, unsigned long size,
98 unsigned long stamp, unsigned long checksum)
100 struct module* module;
102 assert(type == DMT_ELF || type == DMT_PE);
103 if (!(module = HeapAlloc(GetProcessHeap(), 0, sizeof(*module))))
104 return NULL;
106 memset(module, 0, sizeof(*module));
108 module->next = pcs->lmodules;
109 pcs->lmodules = module;
111 TRACE("=> %s %08lx-%08lx %s\n",
112 get_module_type(type, virtual), mod_addr, mod_addr + size, name);
114 pool_init(&module->pool, 65536);
116 module->module.SizeOfStruct = sizeof(module->module);
117 module->module.BaseOfImage = mod_addr;
118 module->module.ImageSize = size;
119 module_fill_module(name, module->module.ModuleName,
120 sizeof(module->module.ModuleName));
121 module->module.ImageName[0] = '\0';
122 lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
123 module->module.SymType = SymNone;
124 module->module.NumSyms = 0;
125 module->module.TimeDateStamp = stamp;
126 module->module.CheckSum = checksum;
128 memset(module->module.LoadedPdbName, 0, sizeof(module->module.CVData));
129 module->module.CVSig = 0;
130 memset(module->module.CVData, 0, sizeof(module->module.CVData));
131 module->module.PdbSig = 0;
132 memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
133 module->module.PdbAge = 0;
134 module->module.PdbUnmatched = FALSE;
135 module->module.DbgUnmatched = FALSE;
136 module->module.LineNumbers = FALSE;
137 module->module.GlobalSymbols = FALSE;
138 module->module.TypeInfo = FALSE;
139 module->module.SourceIndexed = FALSE;
140 module->module.Publics = FALSE;
142 module->type = type;
143 module->is_virtual = virtual ? TRUE : FALSE;
144 module->sortlist_valid = FALSE;
145 module->addr_sorttab = NULL;
146 /* FIXME: this seems a bit too high (on a per module basis)
147 * need some statistics about this
149 hash_table_init(&module->pool, &module->ht_symbols, 4096);
150 hash_table_init(&module->pool, &module->ht_types, 4096);
151 vector_init(&module->vtypes, sizeof(struct symt*), 32);
153 module->sources_used = 0;
154 module->sources_alloc = 0;
155 module->sources = 0;
157 return module;
160 /***********************************************************************
161 * module_find_by_name
164 struct module* module_find_by_name(const struct process* pcs,
165 const char* name, enum module_type type)
167 struct module* module;
169 if (type == DMT_UNKNOWN)
171 if ((module = module_find_by_name(pcs, name, DMT_PE)) ||
172 (module = module_find_by_name(pcs, name, DMT_ELF)))
173 return module;
175 else
177 char modname[MAX_PATH];
179 for (module = pcs->lmodules; module; module = module->next)
181 if (type == module->type &&
182 !strcasecmp(name, module->module.LoadedImageName))
183 return module;
185 module_fill_module(name, modname, sizeof(modname));
186 for (module = pcs->lmodules; module; module = module->next)
188 if (type == module->type &&
189 !strcasecmp(modname, module->module.ModuleName))
190 return module;
193 SetLastError(ERROR_INVALID_NAME);
194 return NULL;
197 /***********************************************************************
198 * module_get_container
201 struct module* module_get_container(const struct process* pcs,
202 const struct module* inner)
204 struct module* module;
206 for (module = pcs->lmodules; module; module = module->next)
208 if (module != inner &&
209 module->module.BaseOfImage <= inner->module.BaseOfImage &&
210 module->module.BaseOfImage + module->module.ImageSize >=
211 inner->module.BaseOfImage + inner->module.ImageSize)
212 return module;
214 return NULL;
217 /***********************************************************************
218 * module_get_containee
221 struct module* module_get_containee(const struct process* pcs,
222 const struct module* outter)
224 struct module* module;
226 for (module = pcs->lmodules; module; module = module->next)
228 if (module != outter &&
229 outter->module.BaseOfImage <= module->module.BaseOfImage &&
230 outter->module.BaseOfImage + outter->module.ImageSize >=
231 module->module.BaseOfImage + module->module.ImageSize)
232 return module;
234 return NULL;
237 /******************************************************************
238 * module_get_debug
240 * get the debug information from a module:
241 * - if the module's type is deferred, then force loading of debug info (and return
242 * the module itself)
243 * - if the module has no debug info and has an ELF container, then return the ELF
244 * container (and also force the ELF container's debug info loading if deferred)
245 * - otherwise return the module itself if it has some debug info
247 BOOL module_get_debug(struct module_pair* pair)
249 IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64;
251 if (!pair->requested) return FALSE;
252 /* for a PE builtin, always get info from container */
253 if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
254 pair->effective = pair->requested;
255 /* if deferred, force loading */
256 if (pair->effective->module.SymType == SymDeferred)
258 BOOL ret;
260 if (pair->effective->is_virtual) ret = FALSE;
261 else switch (pair->effective->type)
263 case DMT_ELF:
264 ret = elf_load_debug_info(pair->effective, NULL);
265 break;
266 case DMT_PE:
267 idsl64.SizeOfStruct = sizeof(idsl64);
268 idsl64.BaseOfImage = pair->effective->module.BaseOfImage;
269 idsl64.CheckSum = pair->effective->module.CheckSum;
270 idsl64.TimeDateStamp = pair->effective->module.TimeDateStamp;
271 strcpy(idsl64.FileName, pair->effective->module.ImageName);
272 idsl64.Reparse = FALSE;
273 idsl64.hFile = INVALID_HANDLE_VALUE;
275 pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
276 ret = pe_load_debug_info(pair->pcs, pair->effective);
277 pcs_callback(pair->pcs,
278 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
279 &idsl64);
280 break;
281 default:
282 ret = FALSE;
283 break;
285 if (!ret) pair->effective->module.SymType = SymNone;
286 assert(pair->effective->module.SymType != SymDeferred);
287 pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
289 return pair->effective->module.SymType != SymNone;
292 /***********************************************************************
293 * module_find_by_addr
295 * either the addr where module is loaded, or any address inside the
296 * module
298 struct module* module_find_by_addr(const struct process* pcs, unsigned long addr,
299 enum module_type type)
301 struct module* module;
303 if (type == DMT_UNKNOWN)
305 if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
306 (module = module_find_by_addr(pcs, addr, DMT_ELF)))
307 return module;
309 else
311 for (module = pcs->lmodules; module; module = module->next)
313 if (type == module->type && addr >= module->module.BaseOfImage &&
314 addr < module->module.BaseOfImage + module->module.ImageSize)
315 return module;
318 SetLastError(ERROR_INVALID_ADDRESS);
319 return module;
322 static BOOL module_is_elf_container_loaded(struct process* pcs, const char* ImageName,
323 const char* ModuleName)
325 char buffer[MAX_PATH];
326 size_t len;
327 struct module* module;
329 if (!ModuleName)
331 module_fill_module(ImageName, buffer, sizeof(buffer));
332 ModuleName = buffer;
334 len = strlen(ModuleName);
335 for (module = pcs->lmodules; module; module = module->next)
337 if (!strncasecmp(module->module.ModuleName, ModuleName, len) &&
338 module->type == DMT_ELF &&
339 !strcmp(module->module.ModuleName + len, "<elf>"))
340 return TRUE;
342 return FALSE;
345 /******************************************************************
346 * module_get_type_by_name
348 * Guesses a filename type from its extension
350 enum module_type module_get_type_by_name(const char* name)
352 const char* ptr;
353 int len = strlen(name);
355 /* check for terminating .so or .so.[digit] */
356 ptr = strrchr(name, '.');
357 if (ptr)
359 if (!strcmp(ptr, ".so") ||
360 (isdigit(ptr[1]) && !ptr[2] && ptr >= name + 3 && !memcmp(ptr - 3, ".so", 3)))
361 return DMT_ELF;
362 else if (!strcasecmp(ptr, ".pdb"))
363 return DMT_PDB;
365 /* wine-[kp]thread is also an ELF module */
366 else if (((len > 12 && name[len - 13] == '/') || len == 12) &&
367 (!strcasecmp(name + len - 12, "wine-pthread") ||
368 !strcasecmp(name + len - 12, "wine-kthread")))
370 return DMT_ELF;
372 return DMT_PE;
375 /***********************************************************************
376 * SymLoadModule (DBGHELP.@)
378 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName,
379 const char* ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
381 struct process* pcs;
382 struct module* module = NULL;
384 TRACE("(%p %p %s %s %08x %08x)\n",
385 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
386 BaseOfDll, SizeOfDll);
388 pcs = process_find_by_handle(hProcess);
389 if (!pcs) return FALSE;
391 /* force transparent ELF loading / unloading */
392 elf_synchronize_module_list(pcs);
394 /* this is a Wine extension to the API just to redo the synchronisation */
395 if (!ImageName && !hFile) return 0;
397 if (module_is_elf_container_loaded(pcs, ImageName, ModuleName))
399 /* force the loading of DLL as builtin */
400 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
401 BaseOfDll, SizeOfDll)))
402 goto done;
403 WARN("Couldn't locate %s\n", ImageName);
404 return 0;
406 TRACE("Assuming %s as native DLL\n", ImageName);
407 if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
409 if (module_get_type_by_name(ImageName) == DMT_ELF &&
410 (module = elf_load_module(pcs, ImageName, BaseOfDll)))
411 goto done;
412 FIXME("Should have successfully loaded debug information for image %s\n",
413 ImageName);
414 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
415 BaseOfDll, SizeOfDll)))
416 goto done;
417 WARN("Couldn't locate %s\n", ImageName);
418 return 0;
420 module->module.NumSyms = module->ht_symbols.num_elts;
421 done:
422 /* by default pe_load_module fills module.ModuleName from a derivation
423 * of ImageName. Overwrite it, if we have better information
425 if (ModuleName)
426 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
427 lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
429 return module->module.BaseOfImage;
432 /***********************************************************************
433 * SymLoadModuleEx (DBGHELP.@)
435 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
436 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
437 PMODLOAD_DATA Data, DWORD Flags)
439 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
440 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
441 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
443 if (Data)
444 FIXME("Unsupported load data parameter %p for %s\n", Data, ImageName);
445 if (!validate_addr64(BaseOfDll)) return FALSE;
446 if (Flags & SLMFLAG_VIRTUAL)
448 struct process* pcs = process_find_by_handle(hProcess);
449 struct module* module;
450 if (!pcs) return FALSE;
452 module = module_new(pcs, ImageName, module_get_type_by_name(ImageName), TRUE,
453 (DWORD)BaseOfDll, DllSize, 0, 0);
454 if (!module) return FALSE;
455 if (ModuleName)
456 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
457 module->module.SymType = SymVirtual;
459 return TRUE;
461 if (Flags & ~(SLMFLAG_VIRTUAL))
462 FIXME("Unsupported Flags %08x for %s\n", Flags, ImageName);
464 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, DllSize);
467 /***********************************************************************
468 * SymLoadModuleExW (DBGHELP.@)
470 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
471 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD DllSize,
472 PMODLOAD_DATA Data, DWORD Flags)
474 LPSTR ImageName, ModuleName;
475 unsigned len;
476 BOOL ret;
478 if (wImageName)
480 len = WideCharToMultiByte(CP_ACP,0, wImageName, -1, NULL, 0, NULL, NULL);
481 ImageName = HeapAlloc(GetProcessHeap(), 0, len);
482 WideCharToMultiByte(CP_ACP,0, wImageName, -1, ImageName, len, NULL, NULL);
484 else ImageName = NULL;
485 if (wModuleName)
487 len = WideCharToMultiByte(CP_ACP,0, wModuleName, -1, NULL, 0, NULL, NULL);
488 ModuleName = HeapAlloc(GetProcessHeap(), 0, len);
489 WideCharToMultiByte(CP_ACP,0, wModuleName, -1, ModuleName, len, NULL, NULL);
491 else ModuleName = NULL;
493 ret = SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName,
494 BaseOfDll, DllSize, Data, Flags);
495 HeapFree(GetProcessHeap(), 0, ImageName);
496 HeapFree(GetProcessHeap(), 0, ModuleName);
497 return ret;
500 /***********************************************************************
501 * SymLoadModule64 (DBGHELP.@)
503 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
504 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
506 if (!validate_addr64(BaseOfDll)) return FALSE;
507 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
510 /******************************************************************
511 * module_remove
514 BOOL module_remove(struct process* pcs, struct module* module)
516 struct module** p;
518 TRACE("%s (%p)\n", module->module.ModuleName, module);
519 hash_table_destroy(&module->ht_symbols);
520 hash_table_destroy(&module->ht_types);
521 HeapFree(GetProcessHeap(), 0, (char*)module->sources);
522 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
523 HeapFree(GetProcessHeap(), 0, module->dwarf2_info);
524 pool_destroy(&module->pool);
525 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
526 * so do we
528 for (p = &pcs->lmodules; *p; p = &(*p)->next)
530 if (*p == module)
532 *p = module->next;
533 HeapFree(GetProcessHeap(), 0, module);
534 return TRUE;
537 FIXME("This shouldn't happen\n");
538 return FALSE;
541 /******************************************************************
542 * SymUnloadModule (DBGHELP.@)
545 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
547 struct process* pcs;
548 struct module* module;
550 pcs = process_find_by_handle(hProcess);
551 if (!pcs) return FALSE;
552 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
553 if (!module) return FALSE;
554 return module_remove(pcs, module);
557 /******************************************************************
558 * SymUnloadModule64 (DBGHELP.@)
561 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
563 struct process* pcs;
564 struct module* module;
566 pcs = process_find_by_handle(hProcess);
567 if (!pcs) return FALSE;
568 if (!validate_addr64(BaseOfDll)) return FALSE;
569 module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
570 if (!module) return FALSE;
571 return module_remove(pcs, module);
574 /******************************************************************
575 * SymEnumerateModules (DBGHELP.@)
578 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
579 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
580 PVOID UserContext)
582 struct process* pcs = process_find_by_handle(hProcess);
583 struct module* module;
585 if (!pcs) return FALSE;
587 for (module = pcs->lmodules; module; module = module->next)
589 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
590 continue;
591 if (!EnumModulesCallback(module->module.ModuleName,
592 module->module.BaseOfImage, UserContext))
593 break;
595 return TRUE;
598 /******************************************************************
599 * SymEnumerateModules64 (DBGHELP.@)
602 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
603 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
604 PVOID UserContext)
606 struct process* pcs = process_find_by_handle(hProcess);
607 struct module* module;
609 if (!pcs) return FALSE;
611 for (module = pcs->lmodules; module; module = module->next)
613 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
614 continue;
615 if (!EnumModulesCallback(module->module.ModuleName,
616 module->module.BaseOfImage, UserContext))
617 break;
619 return TRUE;
622 /******************************************************************
623 * EnumerateLoadedModules64 (DBGHELP.@)
626 BOOL WINAPI EnumerateLoadedModules64(HANDLE hProcess,
627 PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
628 PVOID UserContext)
630 HMODULE* hMods;
631 char base[256], mod[256];
632 DWORD i, sz;
633 MODULEINFO mi;
635 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
636 if (!hMods) return FALSE;
638 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
640 /* hProcess should also be a valid process handle !! */
641 FIXME("If this happens, bump the number in mod\n");
642 HeapFree(GetProcessHeap(), 0, hMods);
643 return FALSE;
645 sz /= sizeof(HMODULE);
646 for (i = 0; i < sz; i++)
648 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
649 !GetModuleBaseNameA(hProcess, hMods[i], base, sizeof(base)))
650 continue;
651 module_fill_module(base, mod, sizeof(mod));
652 EnumLoadedModulesCallback(mod, (DWORD_PTR)mi.lpBaseOfDll, mi.SizeOfImage,
653 UserContext);
655 HeapFree(GetProcessHeap(), 0, hMods);
657 return sz != 0 && i == sz;
660 /******************************************************************
661 * EnumerateLoadedModules (DBGHELP.@)
664 struct enum_load_mod64_32
666 PENUMLOADED_MODULES_CALLBACK cb;
667 PVOID user;
670 static BOOL CALLBACK enum_load_mod64_32(PSTR name, DWORD64 base, ULONG size,
671 PVOID user)
673 struct enum_load_mod64_32* x = user;
674 return x->cb(name, (DWORD)base, size, x->user);
677 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
678 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
679 PVOID UserContext)
681 struct enum_load_mod64_32 x;
683 x.cb = EnumLoadedModulesCallback;
684 x.user = UserContext;
686 return EnumerateLoadedModules64(hProcess, enum_load_mod64_32, &x);
689 /******************************************************************
690 * EnumerateLoadedModulesW64 (DBGHELP.@)
693 struct enum_load_mod64_W64
695 PENUMLOADED_MODULES_CALLBACKW64 cb;
696 PVOID user;
697 WCHAR module[MAX_PATH];
700 static BOOL CALLBACK enum_load_mod64_W64(PSTR name, DWORD64 base, ULONG size,
701 PVOID user)
703 struct enum_load_mod64_W64* x = user;
705 MultiByteToWideChar(CP_ACP, 0, name, -1,
706 x->module, sizeof(x->module) / sizeof(WCHAR));
707 return x->cb(x->module, base, size, x->user);
710 BOOL WINAPI EnumerateLoadedModulesW64(HANDLE hProcess,
711 PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback,
712 PVOID UserContext)
714 struct enum_load_mod64_W64 x;
716 x.cb = EnumLoadedModulesCallback;
717 x.user = UserContext;
719 return EnumerateLoadedModules64(hProcess, enum_load_mod64_W64, &x);
722 /******************************************************************
723 * SymGetModuleInfo (DBGHELP.@)
726 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
727 PIMAGEHLP_MODULE ModuleInfo)
729 struct process* pcs = process_find_by_handle(hProcess);
730 struct module* module;
731 IMAGEHLP_MODULE mod;
733 if (!pcs) return FALSE;
734 if (ModuleInfo->SizeOfStruct < sizeof(*ModuleInfo)) return FALSE;
735 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
736 if (!module) return FALSE;
738 mod.SizeOfStruct = ModuleInfo->SizeOfStruct;
739 mod.BaseOfImage = module->module.BaseOfImage;
740 mod.ImageSize = module->module.ImageSize;
741 mod.TimeDateStamp = module->module.TimeDateStamp;
742 mod.CheckSum = module->module.CheckSum;
743 mod.NumSyms = module->module.NumSyms;
744 mod.SymType = module->module.SymType;
745 strcpy(mod.ModuleName, module->module.ModuleName);
746 strcpy(mod.ImageName, module->module.ImageName);
747 strcpy(mod.LoadedImageName, module->module.LoadedImageName);
749 if (module->module.SymType == SymNone)
751 module = module_get_container(pcs, module);
752 if (module && module->module.SymType != SymNone)
754 mod.SymType = module->module.SymType;
755 mod.NumSyms = module->module.NumSyms;
758 memcpy(ModuleInfo, &mod, ModuleInfo->SizeOfStruct);
759 return TRUE;
762 /******************************************************************
763 * SymGetModuleInfoW (DBGHELP.@)
766 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
767 PIMAGEHLP_MODULEW ModuleInfo)
769 IMAGEHLP_MODULE mi;
770 IMAGEHLP_MODULEW miw;
772 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
774 mi.SizeOfStruct = sizeof(mi);
775 if (!SymGetModuleInfo(hProcess, dwAddr, &mi)) return FALSE;
777 miw.SizeOfStruct = mi.SizeOfStruct;
778 miw.BaseOfImage = mi.BaseOfImage;
779 miw.ImageSize = mi.ImageSize;
780 miw.TimeDateStamp = mi.TimeDateStamp;
781 miw.CheckSum = mi.CheckSum;
782 miw.NumSyms = mi.NumSyms;
783 miw.SymType = mi.SymType;
784 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
785 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
786 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
787 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
788 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
789 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
790 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
792 return TRUE;
795 /******************************************************************
796 * SymGetModuleInfo64 (DBGHELP.@)
799 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
800 PIMAGEHLP_MODULE64 ModuleInfo)
802 struct process* pcs = process_find_by_handle(hProcess);
803 struct module* module;
805 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
807 if (!pcs) return FALSE;
808 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
809 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
810 if (!module) return FALSE;
812 memcpy(ModuleInfo, &module->module, ModuleInfo->SizeOfStruct);
814 if (module->module.SymType == SymNone)
816 module = module_get_container(pcs, module);
817 if (module && module->module.SymType != SymNone)
819 ModuleInfo->SymType = module->module.SymType;
820 ModuleInfo->NumSyms = module->module.NumSyms;
823 return TRUE;
826 /******************************************************************
827 * SymGetModuleInfoW64 (DBGHELP.@)
830 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
831 PIMAGEHLP_MODULEW64 ModuleInfo)
833 IMAGEHLP_MODULE64 mi;
834 IMAGEHLP_MODULEW64 miw;
836 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
838 mi.SizeOfStruct = sizeof(mi);
839 if (!SymGetModuleInfo64(hProcess, dwAddr, &mi)) return FALSE;
841 miw.SizeOfStruct = mi.SizeOfStruct;
842 miw.BaseOfImage = mi.BaseOfImage;
843 miw.ImageSize = mi.ImageSize;
844 miw.TimeDateStamp = mi.TimeDateStamp;
845 miw.CheckSum = mi.CheckSum;
846 miw.NumSyms = mi.NumSyms;
847 miw.SymType = mi.SymType;
848 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
849 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
850 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
851 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
852 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
853 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
854 MultiByteToWideChar(CP_ACP, 0, mi.LoadedPdbName, -1,
855 miw.LoadedPdbName, sizeof(miw.LoadedPdbName) / sizeof(WCHAR));
857 miw.CVSig = mi.CVSig;
858 MultiByteToWideChar(CP_ACP, 0, mi.CVData, -1,
859 miw.CVData, sizeof(miw.CVData) / sizeof(WCHAR));
860 miw.PdbSig = mi.PdbSig;
861 miw.PdbSig70 = mi.PdbSig70;
862 miw.PdbAge = mi.PdbAge;
863 miw.PdbUnmatched = mi.PdbUnmatched;
864 miw.DbgUnmatched = mi.DbgUnmatched;
865 miw.LineNumbers = mi.LineNumbers;
866 miw.GlobalSymbols = mi.GlobalSymbols;
867 miw.TypeInfo = mi.TypeInfo;
868 miw.SourceIndexed = mi.SourceIndexed;
869 miw.Publics = mi.Publics;
871 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
873 return TRUE;
876 /***********************************************************************
877 * SymGetModuleBase (DBGHELP.@)
879 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
881 struct process* pcs = process_find_by_handle(hProcess);
882 struct module* module;
884 if (!pcs) return 0;
885 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
886 if (!module) return 0;
887 return module->module.BaseOfImage;
890 /***********************************************************************
891 * SymGetModuleBase64 (DBGHELP.@)
893 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
895 if (!validate_addr64(dwAddr)) return 0;
896 return SymGetModuleBase(hProcess, (DWORD)dwAddr);
899 /******************************************************************
900 * module_reset_debug_info
901 * Removes any debug information linked to a given module.
903 void module_reset_debug_info(struct module* module)
905 module->sortlist_valid = TRUE;
906 module->addr_sorttab = NULL;
907 hash_table_destroy(&module->ht_symbols);
908 module->ht_symbols.num_buckets = 0;
909 module->ht_symbols.buckets = NULL;
910 hash_table_destroy(&module->ht_types);
911 module->ht_types.num_buckets = 0;
912 module->ht_types.buckets = NULL;
913 module->vtypes.num_elts = 0;
914 hash_table_destroy(&module->ht_symbols);
915 module->sources_used = module->sources_alloc = 0;
916 module->sources = NULL;