_UCD_internal.h revision edcc521a0e94bb198aa3197f1620c40f640334c1
1/* libunwind - a platform-independent unwind library
2
3This file is part of libunwind.
4
5Permission is hereby granted, free of charge, to any person obtaining
6a copy of this software and associated documentation files (the
7"Software"), to deal in the Software without restriction, including
8without limitation the rights to use, copy, modify, merge, publish,
9distribute, sublicense, and/or sell copies of the Software, and to
10permit persons to whom the Software is furnished to do so, subject to
11the following conditions:
12
13The above copyright notice and this permission notice shall be
14included in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
23
24#ifndef _UCD_internal_h
25#define _UCD_internal_h
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31#ifdef HAVE_SYS_TYPES_H
32#include <sys/types.h>
33#endif
34#ifdef HAVE_SYS_PROCFS_H
35#include <sys/procfs.h> /* struct elf_prstatus */
36#endif
37#include <errno.h>
38#include <string.h>
39#include <limits.h>
40#include <stdio.h>
41#include <stdlib.h>
42
43#include <libunwind-coredump.h>
44
45#include "libunwind_i.h"
46
47
48#if SIZEOF_OFF_T == 4
49typedef uint32_t uoff_t;
50#elif SIZEOF_OFF_T == 8
51typedef uint64_t uoff_t;
52#else
53# error Unknown size of off_t!
54#endif
55
56
57/* Similar to ELF phdrs. p_paddr element is absent,
58 * since it's always 0 in coredumps.
59 */
60struct coredump_phdr
61  {
62    uint32_t p_type;
63    uint32_t p_flags;
64    uoff_t   p_offset;
65    uoff_t   p_vaddr;
66    uoff_t   p_filesz;
67    uoff_t   p_memsz;
68    uoff_t   p_align;
69    /* Data for backing file. If backing_fd < 0, there is no file */
70    uoff_t   backing_filesize;
71    char    *backing_filename; /* for error meesages only */
72    int      backing_fd;
73  };
74
75typedef struct coredump_phdr coredump_phdr_t;
76
77#if defined(HAVE_STRUCT_ELF_PRSTATUS)
78#define PRSTATUS_STRUCT elf_prstatus
79#elif defined(HAVE_STRUCT_PRSTATUS)
80#define PRSTATUS_STRUCT prstatus
81#else
82#define PRSTATUS_STRUCT non_existent
83#endif
84
85struct UCD_info
86  {
87    int big_endian;  /* bool */
88    int coredump_fd;
89    char *coredump_filename; /* for error meesages only */
90    coredump_phdr_t *phdrs; /* array, allocated */
91    unsigned phdrs_count;
92    void *note_phdr; /* allocated or NULL */
93    struct PRSTATUS_STRUCT *prstatus; /* points inside note_phdr */
94    int n_threads;
95    struct PRSTATUS_STRUCT **threads;
96
97    struct elf_dyn_info edi;
98  };
99
100extern coredump_phdr_t * _UCD_get_elf_image(struct UCD_info *ui, unw_word_t ip);
101
102#define ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL))
103#define STRUCT_MEMBER_P(struct_p, struct_offset) ((void *) ((char*) (struct_p) + (long) (struct_offset)))
104#define STRUCT_MEMBER(member_type, struct_p, struct_offset) (*(member_type*) STRUCT_MEMBER_P ((struct_p), (struct_offset)))
105
106#endif
107