ReactOS  0.4.15-dev-3308-g9455def
image_private.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  elf_header
 
struct  elf_section_header
 
struct  macho_load_command
 
struct  macho_uuid_command
 
struct  macho_section
 
struct  macho_section32
 
struct  image_file_map
 
struct  image_section_map
 
struct  stab_nlist
 
struct  macho64_nlist
 
struct  image_file_map_ops
 

Macros

#define IMAGE_NO_MAP   ((void*)-1)
 

Functions

BOOL image_check_alternate (struct image_file_map *fmap, const struct module *module) DECLSPEC_HIDDEN
 
BOOL elf_map_handle (HANDLE handle, struct image_file_map *fmap) DECLSPEC_HIDDEN
 
BOOL pe_map_file (HANDLE file, struct image_file_map *fmap, enum module_type mt) DECLSPEC_HIDDEN
 
static BOOL image_find_section (struct image_file_map *fmap, const char *name, struct image_section_map *ism)
 
static void image_unmap_file (struct image_file_map *fmap)
 
static const charimage_map_section (struct image_section_map *ism)
 
static void image_unmap_section (struct image_section_map *ism)
 
static DWORD_PTR image_get_map_rva (const struct image_section_map *ism)
 
static unsigned image_get_map_size (const struct image_section_map *ism)
 

Macro Definition Documentation

◆ IMAGE_NO_MAP

#define IMAGE_NO_MAP   ((void*)-1)

Definition at line 24 of file image_private.h.

Function Documentation

◆ elf_map_handle()

BOOL elf_map_handle ( HANDLE  handle,
struct image_file_map fmap 
)

Definition at line 582 of file elf_module.c.

583 {
584  struct elf_map_file_data emfd;
585  emfd.kind = from_handle;
586  emfd.u.handle = handle;
587  return elf_map_file(&emfd, fmap);
588 }
enum elf_map_file_data::@364 kind
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
static BOOL elf_map_file(struct elf_map_file_data *emfd, struct image_file_map *fmap)
Definition: elf_module.c:406

Referenced by image_check_debug_link().

◆ image_check_alternate()

BOOL image_check_alternate ( struct image_file_map fmap,
const struct module module 
)

Definition at line 701 of file module.c.

702 {
703  BOOL ret = FALSE;
704  BOOL found = FALSE;
705  struct image_section_map buildid_sect, debuglink_sect;
706 
707  /* if present, add the .gnu_debuglink file as an alternate to current one */
708  if (image_find_section(fmap, ".note.gnu.build-id", &buildid_sect))
709  {
710  const UINT32* note;
711 
712  found = TRUE;
713  note = (const UINT32*)image_map_section(&buildid_sect);
714  if (note != IMAGE_NO_MAP)
715  {
716  /* the usual ELF note structure: name-size desc-size type <name> <desc> */
717  if (note[2] == NOTE_GNU_BUILD_ID)
718  {
719  ret = image_locate_build_id_target(fmap, (const BYTE*)(note + 3 + ((note[0] + 3) >> 2)), note[1]);
720  }
721  }
722  image_unmap_section(&buildid_sect);
723  }
724  /* if present, add the .gnu_debuglink file as an alternate to current one */
725  if (!ret && image_find_section(fmap, ".gnu_debuglink", &debuglink_sect))
726  {
727  const char* dbg_link;
728 
729  found = TRUE;
730  dbg_link = (const char*)image_map_section(&debuglink_sect);
731  if (dbg_link != IMAGE_NO_MAP)
732  {
733  /* The content of a debug link section is:
734  * 1/ a NULL terminated string, containing the file name for the
735  * debug info
736  * 2/ padding on 4 byte boundary
737  * 3/ CRC of the linked file
738  */
739  DWORD crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
740  ret = image_locate_debug_link(module, fmap, dbg_link, crc);
741  if (!ret)
742  WARN("Couldn't load linked debug file for %s\n",
744  }
745  image_unmap_section(&debuglink_sect);
746  }
747  return found ? ret : TRUE;
748 }
WCHAR ModuleName[32]
Definition: compat.h:935
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
struct image_file_map * fmap
#define NOTE_GNU_BUILD_ID
Definition: module.c:38
static BOOL image_locate_build_id_target(struct image_file_map *fmap, const BYTE *id, unsigned idlen)
Definition: module.c:621
#define IMAGE_NO_MAP
Definition: image_private.h:24
#define FALSE
Definition: types.h:117
unsigned int UINT32
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
int note(char *format,...)
Definition: util.c:12
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static void image_unmap_section(struct image_section_map *ism)
static BOOL image_find_section(struct image_file_map *fmap, const char *name, struct image_section_map *ism)
uint32_t DWORD_PTR
Definition: typedefs.h:65
static const char * image_map_section(struct image_section_map *ism)
unsigned char BYTE
Definition: xxhash.c:193
IMAGEHLP_MODULEW64 module
static BOOL image_locate_debug_link(const struct module *module, struct image_file_map *fmap, const char *filename, DWORD crc)
Definition: module.c:543

Referenced by elf_load_debug_info_from_map(), and pe_load_debug_info().

◆ image_find_section()

static BOOL image_find_section ( struct image_file_map fmap,
const char name,
struct image_section_map ism 
)
inlinestatic

Definition at line 208 of file image_private.h.

210 {
211  while (fmap)
212  {
213  if (fmap->ops->find_section(fmap, name, ism)) return TRUE;
214  fmap = fmap->alternate;
215  }
216  ism->fmap = NULL;
217  ism->sidx = -1;
218  return FALSE;
219 }
#define TRUE
Definition: types.h:120
struct image_file_map * fmap
#define FALSE
Definition: types.h:117
#define NULL
Definition: types.h:112
Definition: name.c:38

Referenced by dwarf2_init_section(), elf_load_debug_info_from_map(), image_check_alternate(), and image_locate_build_id_target().

◆ image_get_map_rva()

static DWORD_PTR image_get_map_rva ( const struct image_section_map ism)
inlinestatic

Definition at line 240 of file image_private.h.

241 {
242  return ism->fmap ? ism->fmap->ops->get_map_rva(ism) : 0;
243 }
struct image_file_map * fmap

Referenced by dwarf2_init_section(), and dwarf2_init_zsection().

◆ image_get_map_size()

static unsigned image_get_map_size ( const struct image_section_map ism)
inlinestatic

Definition at line 245 of file image_private.h.

246 {
247  return ism->fmap ? ism->fmap->ops->get_map_size(ism) : 0;
248 }
struct image_file_map * fmap

Referenced by dwarf2_init_section(), dwarf2_init_zsection(), elf_hash_symtab(), elf_load_debug_info_from_map(), pe_load_rsym(), and pe_load_stabs().

◆ image_map_section()

static const char* image_map_section ( struct image_section_map ism)
inlinestatic

Definition at line 230 of file image_private.h.

231 {
232  return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL;
233 }
struct image_file_map * fmap
#define NULL
Definition: types.h:112

Referenced by dwarf2_init_section(), dwarf2_init_zsection(), elf_hash_symtab(), elf_load_debug_info_from_map(), image_check_alternate(), image_locate_build_id_target(), pe_load_rsym(), and pe_load_stabs().

◆ image_unmap_file()

static void image_unmap_file ( struct image_file_map fmap)
inlinestatic

Definition at line 221 of file image_private.h.

222 {
223  while (fmap)
224  {
225  fmap->ops->unmap_file(fmap);
226  fmap = fmap->alternate;
227  }
228 }
struct image_file_map * fmap

Referenced by elf_fetch_file_info(), elf_load_file(), elf_module_remove(), image_locate_build_id_target(), pe_load_native_module(), and pe_module_remove().

◆ image_unmap_section()

static void image_unmap_section ( struct image_section_map ism)
inlinestatic

Definition at line 235 of file image_private.h.

236 {
237  if (ism->fmap) ism->fmap->ops->unmap_section(ism);
238 }
struct image_file_map * fmap

Referenced by dwarf2_init_zsection(), dwarf2_parse(), elf_hash_symtab(), elf_load_debug_info_from_map(), image_check_alternate(), image_locate_build_id_target(), pe_load_rsym(), and pe_load_stabs().

◆ pe_map_file()

BOOL pe_map_file ( HANDLE  file,
struct image_file_map fmap,
enum module_type  mt 
)

Definition at line 241 of file pe_module.c.

242 {
243  void* mapping;
244 
245  fmap->modtype = mt;
246  fmap->ops = &pe_file_map_ops;
247  fmap->alternate = NULL;
248  fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
249  if (fmap->u.pe.hMap == 0) return FALSE;
250  fmap->u.pe.full_count = 0;
251  fmap->u.pe.full_map = NULL;
252  if (!(mapping = pe_map_full(fmap, NULL))) goto error;
253 
254  switch (mt)
255  {
256  case DMT_PE:
257  {
258  IMAGE_NT_HEADERS* nthdr;
260  unsigned i;
261 
262  if (!(nthdr = RtlImageNtHeader(mapping))) goto error;
263  memcpy(&fmap->u.pe.ntheader, nthdr, sizeof(fmap->u.pe.ntheader));
264  switch (nthdr->OptionalHeader.Magic)
265  {
266  case 0x10b: fmap->addr_size = 32; break;
267  case 0x20b: fmap->addr_size = 64; break;
268  default: return FALSE;
269  }
270 
271  fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature));
273  ((char*)&nthdr->OptionalHeader + nthdr->FileHeader.SizeOfOptionalHeader);
274  fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0,
275  nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0]));
276  if (!fmap->u.pe.sect) goto error;
277  for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++)
278  {
279  memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER));
280  fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP;
281  }
283  {
285 
287  {
288  /* FIXME ugly: should rather map the relevant content instead of copying it */
289  const char* src = (const char*)mapping +
291  nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL);
292  char* dst;
293  DWORD sz = *(DWORD*)src;
294 
295  if ((dst = HeapAlloc(GetProcessHeap(), 0, sz)))
296  memcpy(dst, src, sz);
297  fmap->u.pe.strtable = dst;
298  }
299  else
300  {
301  WARN("Bad coff table... wipping out\n");
302  /* we have bad information here, wipe it out */
303  fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable = 0;
304  fmap->u.pe.ntheader.FileHeader.NumberOfSymbols = 0;
305  fmap->u.pe.strtable = NULL;
306  }
307  }
308  else fmap->u.pe.strtable = NULL;
309  }
310  break;
311  default: assert(0); goto error;
312  }
314 
315  return TRUE;
316 error:
318  CloseHandle(fmap->u.pe.hMap);
319  return FALSE;
320 }
static const struct image_file_map_ops pe_file_map_ops
Definition: pe_module.c:207
static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS *nthdr, const void *mapping, DWORD64 sz)
Definition: pe_module.c:223
#define CloseHandle
Definition: compat.h:598
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define error(str)
Definition: mkdosfs.c:1605
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
struct image_file_map * fmap
#define assert(x)
Definition: debug.h:53
static void * pe_map_full(struct image_file_map *fmap, IMAGE_NT_HEADERS **nth)
Definition: pe_module.c:46
Definition: parser.c:55
static IMAGE_SECTION_HEADER section
Definition: loader.c:152
#define IMAGE_NO_MAP
Definition: image_private.h:24
#define FALSE
Definition: types.h:117
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DWORD NumberOfSymbols
Definition: ntddk_ex.h:126
static void pe_unmap_full(struct image_file_map *fmap)
Definition: pe_module.c:61
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:603
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
#define GetFileSizeEx
Definition: compat.h:616
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const char builtin_signature[]
Definition: pe_module.c:44
GLenum GLenum dst
Definition: glext.h:6340
DWORD PointerToSymbolTable
Definition: ntddk_ex.h:125
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define RtlImageNtHeader
Definition: compat.h:665
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
LONGLONG QuadPart
Definition: typedefs.h:114
Definition: fci.c:126

Referenced by image_check_debug_link(), pe_load_native_module(), and search_builtin_pe().