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