-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlibrary.h
141 lines (108 loc) · 3.87 KB
/
library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* This file is part of mtrace-ng.
* Copyright (C) 2018 Stefani Seibold <[email protected]>
*
* This work was sponsored by Rohde & Schwarz GmbH & Co. KG, Munich/Germany.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _INC_LIBRARY_H
#define _INC_LIBRARY_H
#include <stdint.h>
#include "forward.h"
#include "sysdep.h"
#include "list.h"
#include "mtelf.h"
#include "rbtree.h"
#define LIBTYPE_LIB 0
#define LIBTYPE_MAIN 1
#define LIBTYPE_LOADER 2
struct library_symbol {
struct list_head list;
struct libref *libref;
const struct function *func;
arch_addr_t addr;
};
struct libref {
/* Unique dynamic entry address */
arch_addr_t dyn;
/* base address assign by the loader */
unsigned long bias;
/* Absolute address of the entry point. Useful for main
* binary, though I suppose the value might be useful for the
* dynamic linker, too (in case we ever want to do early
* process tracing). */
arch_addr_t entry;
const char *filename;
/* executable segment */
unsigned long txt_vaddr;
unsigned long txt_size;
unsigned long txt_offset;
/* mapped image */
void *mmap_addr;
unsigned long mmap_offset;
unsigned long mmap_size;
/* global-pointer */
arch_addr_t pltgot;
unsigned long eh_hdr_offset;
unsigned long eh_hdr_vaddr;
void *fde_tab;
unsigned long fde_count;
unsigned int type;
#ifdef __arm__
void *exidx_data;
unsigned long exidx_len;
#endif
unsigned int refcnt;
/* Symbols associated with the library. This includes a
* symbols that don't have a breakpoint attached (yet). */
struct list_head sym_list;
};
struct library {
/* link list of libraries associated with the task */
struct list_head list;
/* red/black tree of libraries associated with the task */
struct rb_node rb_node;
/* pointer to the real library refernce */
struct libref *libref;
};
/* create a new symbol */
struct library_symbol *library_symbol_new(struct libref *libref, arch_addr_t addr, const struct function *func);
/* Add a library to the list of the thread leader libraries. */
struct library *library_add(struct task *leader, struct libref *libref);
/* delete a given list of libraries */
void library_delete_list(struct task *leader, struct list_head *list);
/* delete all libraries of a given leader */
void library_clear_all(struct task *leader);
/* cline all libraries of a given leader to a new task leader*/
int library_clone_all(struct task *clone, struct task *leader);
/* setup library list of a given leader */
void library_setup(struct task *leader);
/* get the pathname of the executable */
const char *library_execname(struct task *leader);
/* Iterate through list of symbols of library. */
struct library_symbol *library_find_symbol(struct libref *libref, arch_addr_t addr);
/* find a library with a given dynamic entry address */
struct library *library_find_by_dyn(struct list_head *list, arch_addr_t dyn);
/* create a library reference. */
struct libref *libref_new(unsigned int type);
/* delete a library reference. */
void libref_delete(struct libref *libref);
/* Set library filename. Frees the old name if necessary. */
void libref_set_filename(struct libref *libref, const char *new_name);
/* find library by address */
struct libref *addr2libref(struct task *leader, arch_addr_t addr);
#endif