2 * This file is part of ltrace.
3 * Copyright (C) 2012 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2006 Paul Gilliam, IBM Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
33 LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */
34 LS_TOPLT_EXEC, /* PLT for this symbol is executable. */
38 unsigned int target_address_hash(const void *key);
39 int target_address_cmp(const void *key1, const void *key2);
41 /* For handling -l. */
42 struct library_exported_name {
43 struct library_exported_name *next;
48 struct library_symbol {
49 struct library_symbol *next;
52 arch_addr_t enter_addr;
56 /* This is relevant for PLT symbols. Latent PLT symbols are
57 * those that don't match any of the -e rules, but that might
58 * potentially become active if a library implementing them
59 * appears that matches a -l rule. Ltrace core is responsible
60 * for clearing latent flag. */
63 /* Delayed symbols are those for which a breakpoint shouldn't
64 * be enabled yet. They are similar to latent symbols, but
65 * backend is responsible for clearing the delayed flag. See
66 * proc_activate_delayed_symbol. */
69 struct arch_library_symbol_data arch;
72 /* Init LIBSYM. NAME will be freed when LIBSYM is destroyed if
73 * OWN_NAME. ARCH has to be initialized by a separate call. */
74 int library_symbol_init(struct library_symbol *libsym,
75 arch_addr_t addr, const char *name, int own_name,
76 enum toplt type_of_plt);
78 /* Copy library symbol SYM into the area pointed-to by RETP. Return 0
79 * on success or a negative value on failure. */
80 int library_symbol_clone(struct library_symbol *retp,
81 struct library_symbol *sym);
83 /* Destroy library symbol. This essentially just frees name if it's
84 * owned. It doesn't free the memory associated with SYM pointer
85 * itself. Returns 0 on success or a negative value in case of an
86 * error (which would be an out of memory condition). */
87 void library_symbol_destroy(struct library_symbol *sym);
89 /* Compare two library symbols. Returns a negative value, 0, or a
90 * positive value, much like strcmp. The function compares symbol
91 * addresses, and if those are equal, it compares symbol names. If
92 * those are equal, too, the symbols are considered equal. */
93 int library_symbol_cmp(struct library_symbol *a, struct library_symbol *b);
95 /* Set a name for library symbol. This frees the old name, if
97 void library_symbol_set_name(struct library_symbol *libsym,
98 const char *name, int own_name);
100 /* A function that can be used as library_each_symbol callback. Looks
101 * for a symbol SYM for which library_symbol_cmp(SYM, STANDARD)
103 enum callback_status library_symbol_equal_cb(struct library_symbol *libsym,
106 /* A function that can be used as library_each_symbol callback. Looks
107 * for a symbol SYM for which strcmp(SYM->name, NAME) == 0. */
108 enum callback_status library_symbol_named_cb(struct library_symbol *libsym,
111 /* A function that can be used as library_each_symbol callback. Looks
112 * for a delayed symbol. */
113 enum callback_status library_symbol_delayed_cb(struct library_symbol *libsym,
121 /* XXX we might consider sharing libraries across processes. Things
122 * like libc will be opened by every single process, no point cloning
123 * these everywhere. But for now, keep the ownership structure
126 struct library *next;
128 /* Unique key. Two library objects are considered equal, if
129 * they have the same key. */
132 /* Address where the library is mapped. */
135 /* Absolute address of the entry point. Useful for main
136 * binary, though I suppose the value might be useful for the
137 * dynamic linker, too (in case we ever want to do early
138 * process tracing). */
141 /* Address of PT_DYNAMIC segment. */
142 arch_addr_t dyn_addr;
144 /* Symbols associated with the library. This includes a
145 * symbols that don't have a breakpoint attached (yet). */
146 struct library_symbol *symbols;
148 /* List of names that this library implements, and that match
149 * -l filter. Each time a new library is mapped, its list of
150 * exports is examined, and corresponding PLT slots are
152 struct library_exported_name *exported_names;
155 const char *pathname;
157 enum library_type type;
160 char own_pathname : 1;
162 struct arch_library_data arch;
166 void library_init(struct library *lib, enum library_type type);
168 /* Initialize RETP to a library identical to LIB. Symbols are not
169 * shared, but copied over. Returns 0 on success and a negative value
170 * in case of failure. */
171 int library_clone(struct library *retp, struct library *lib);
173 /* Destroy library. Doesn't free LIB itself. Symbols are destroyed
175 void library_destroy(struct library *lib);
177 /* Set library soname. Frees the old name if necessary. */
178 void library_set_soname(struct library *lib,
179 const char *new_name, int own_name);
181 /* Set library pathname. Frees the old name if necessary. */
182 void library_set_pathname(struct library *lib,
183 const char *new_name, int own_name);
185 /* Iterate through list of symbols of library LIB. See callback.h for
186 * notes on this interface. */
187 struct library_symbol *library_each_symbol
188 (struct library *lib, struct library_symbol *start_after,
189 enum callback_status (*cb)(struct library_symbol *, void *),
192 /* Add a new symbol SYM to LIB. SYM is assumed owned, we need to
193 * overwrite SYM->next. */
194 void library_add_symbol(struct library *lib, struct library_symbol *sym);
196 /* A function that can be used as proc_each_library callback. Looks
197 * for a library with the name passed in DATA. PROC is ignored. */
198 enum callback_status library_named_cb(struct Process *proc,
199 struct library *lib, void *name);
201 /* A function that can be used as proc_each_library callback. Looks
202 * for a library with given base.
204 * NOTE: The key is passed as a POINTER to arch_addr_t (that
205 * because in general, arch_addr_t doesn't fit in void*). */
206 enum callback_status library_with_key_cb(struct Process *proc,
207 struct library *lib, void *keyp);
209 /* XXX this should really be in backend.h (as on pmachata/revamp
210 * branch), or, on this branch, in common.h. But we need
211 * arch_addr_t (which should also be in backend.h, I reckon), so
212 * stuff it here for the time being. */
213 /* This function is implemented in the back end. It is called for all
214 * raw addresses as read from symbol tables etc. If necessary on
215 * given architecture, this function should translate the address
216 * according to .opd or other indirection mechanism. Returns 0 on
217 * success and a negative value on failure. */
219 int arch_translate_address(struct ltelf *lte,
220 arch_addr_t addr, arch_addr_t *ret);
221 /* This is the same function as arch_translate_address, except it's
222 * used at the point that we don't have ELF available anymore. */
223 int arch_translate_address_dyn(struct Process *proc,
224 arch_addr_t addr, arch_addr_t *ret);
226 #endif /* _LIBRARY_H_ */