Psymtab.c revision d51e90740114c60620c0febffd4d3ce6e280a107
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <strings.h>
#include <memory.h>
#include <errno.h>
#include <dirent.h>
#include <signal.h>
#include <limits.h>
#include <libgen.h>
#include <zone.h>
#include <sys/systeminfo.h>
#include <sys/sysmacros.h>
#include "libproc.h"
#include "Pcontrol.h"
#include "Putil.h"
#include "Psymtab_machelf.h"
Lmid_t, const char *);
#ifdef _LP64
#endif
#define DATA_TYPES \
typedef enum {
} pr_order_t;
static int
{
if (a > b)
return (1);
if (a < b)
return (-1);
return (0);
}
/*
* This function creates a list of addresses for a load object's sections.
* The list is in ascending address order and alternates start address
* then end address for each section we're interested in. The function
* returns a pointer to the list, which must be freed by the caller.
*/
static uintptr_t *
{
return (NULL);
sizeof (phdr)) {
return (NULL);
}
continue;
addr += ehdr_start;
unordered = 1;
}
#ifdef _LP64
} else {
return (NULL);
sizeof (phdr)) {
return (NULL);
}
continue;
addr += ehdr_start;
unordered = 1;
}
#endif
}
if (unordered)
*n = naddrs;
return (addrs);
}
/*
* Allocation function for a new file_info_t
*/
static file_info_t *
{
map_info_t *mp;
uint_t i, j;
return (NULL);
P->num_files++;
/*
* To figure out which map_info_t instances correspond to the mappings
* for this load object we try to obtain the start and end address
* for each section of our in-memory ELF image. If successful, we
* walk down the list of addresses and the list of map_info_t
* instances in lock step to correctly find the mappings that
* correspond to this load object.
*/
return (fptr);
i = j = 0;
}
i++;
} else {
mp++;
j++;
}
}
return (fptr);
}
/*
* Deallocation function for a file_info_t
*/
static void
{
}
}
if (fptr->file_lname)
}
if (fptr->file_saddrs)
P->num_files--;
}
}
/*
* Deallocation function for a map_info_t
*/
static void
{
file_info_free(P, fptr);
}
}
P->nauxv = 0;
}
}
/*
* Call-back function for librtld_db to iterate through all of its shared
* libraries. We use this to get the load object names for the mappings.
*/
static int
{
struct ps_prochandle *P = cd;
dprintf("map_iter: base address doesn't match any mapping\n");
return (1); /* Base address does not match any mapping */
}
dprintf("map_iter: failed to allocate a new file_info_t\n");
return (1); /* Failed to allocate a new file_info_t */
}
dprintf("map_iter: failed to allocate rd_loadobj_t\n");
file_info_free(P, fptr);
return (1); /* Failed to allocate rd_loadobj_t */
}
if (fptr->file_lname) {
}
} else {
dprintf("map_iter: failed to read string at %p\n",
(void *)lop->rl_nameaddr);
}
dprintf("loaded rd object %s lmid %lx\n",
return (1);
}
static void
{
return; /* Failed to allocate a new file_info_t */
file_info_free(P, fptr);
return; /* Failed to allocate rd_loadobj_t */
}
}
static void
load_static_maps(struct ps_prochandle *P)
{
/*
* Construct the map for the a.out.
*/
/*
* If the dynamic linker exists for this process,
* construct the map for it.
*/
}
/*
* Go through all the address space mappings, validating or updating
* the information already gathered, or gathering new information.
*
* This function is only called when we suspect that the mappings have changed
* because this is the first time we're calling it or because of rtld activity.
*/
void
Pupdate_maps(struct ps_prochandle *P)
{
int mapfd;
int i;
return;
Preadauxvec(P);
procfs_path, (int)P->pid);
if (mapfd >= 0)
Preset_maps(P); /* utter failure; destroy tables */
return;
}
return;
/*
* We try to merge any file information we may have for existing
* mappings, to avoid having to rebuild the file info.
*/
oldmapcount = P->map_count;
if (oldmapcount == 0) {
/*
* We've exhausted all the old mappings. Every new
* mapping should be added.
*/
/*
* This mapping matches exactly. Copy over the old
* mapping, taking care to get the latest flags.
* Make sure the associated file_info_t is updated
* appropriately.
*/
oldmapcount--;
mptr++;
/*
* The old mapping doesn't exist any more, remove it
* from the list.
*/
map_info_free(P, mptr);
oldmapcount--;
i--;
newp--;
pmap--;
mptr++;
} else {
/*
* This is a new mapping, add it directly.
*/
}
}
/*
* Free any old maps
*/
while (oldmapcount) {
map_info_free(P, mptr);
oldmapcount--;
mptr++;
}
P->info_valid = 1;
/*
* Consult librtld_db to get the load object
* names for all of the shared libraries.
*/
}
/*
* Update all of the mappings and rtld_db as if by Pupdate_maps(), and then
* forcibly cache all of the symbol tables associated with all object files.
*/
void
Pupdate_syms(struct ps_prochandle *P)
{
int i;
Pupdate_maps(P);
Pbuild_file_symtab(P, fptr);
(void) Pbuild_file_ctf(P, fptr);
}
}
/*
* Return the librtld_db agent handle for the victim process.
* The handle will become invalid at the next successful exec() and the
* client (caller of proc_rd_agent()) must not use it beyond that point.
* If the process is already dead, we've already tried our best to
* create the agent during core file initialization.
*/
Prd_agent(struct ps_prochandle *P)
{
Pupdate_maps(P);
if (P->num_files == 0)
load_static_maps(P);
}
return (P->rap);
}
/*
* Return the prmap_t structure containing 'addr', but only if it
* is in the dynamic linker's link map and is the text section.
*/
const prmap_t *
{
if (!P->info_valid)
Pupdate_maps(P);
return (pmp);
}
return (NULL);
}
/*
* Return the prmap_t structure containing 'addr' (no restrictions on
* the type of mapping).
*/
const prmap_t *
{
if (!P->info_valid)
Pupdate_maps(P);
return (NULL);
}
/*
* Convert a full or partial load object name to the prmap_t for its
* corresponding primary text mapping.
*/
const prmap_t *
{
if (name == PR_OBJ_EVERY)
return (NULL); /* A reasonable mistake */
return (NULL);
}
const prmap_t *
{
}
const rd_loadobj_t *
{
if (!P->info_valid)
Pupdate_maps(P);
return (NULL);
/*
* By building the symbol table, we implicitly bring the PLT
* information up to date in the load object.
*/
(void) build_map_symtab(P, mptr);
}
const rd_loadobj_t *
{
if (name == PR_OBJ_EVERY)
return (NULL);
return (NULL);
/*
* By building the symbol table, we implicitly bring the PLT
* information up to date in the load object.
*/
(void) build_map_symtab(P, mptr);
}
const rd_loadobj_t *
{
}
{
int err;
Pbuild_file_symtab(P, fptr);
if (fptr->file_ctf_size == 0)
return (NULL);
return (NULL);
/*
* The buffer may alread be allocated if this is a core file that
* contained CTF data for this file.
*/
dprintf("failed to allocate ctf buffer\n");
return (NULL);
}
fptr->file_ctf_size) {
dprintf("failed to read ctf data\n");
return (NULL);
}
}
ctdata.cts_offset = 0;
return (NULL);
}
dprintf("loaded %lu bytes of CTF data for %s\n",
}
{
if (!P->info_valid)
Pupdate_maps(P);
return (NULL);
return (Pbuild_file_ctf(P, fptr));
}
{
if (name == PR_OBJ_EVERY)
return (NULL);
return (NULL);
return (Pbuild_file_ctf(P, fptr));
}
{
}
/*
* If we're not a core file, re-read the /proc/<pid>/auxv file and store
* its contents in P->auxv. In the case of a core file, we either
* initialized P->auxv in Pcore() from the NT_AUXV, or we don't have an
* auxv because the note was missing.
*/
void
Preadauxvec(struct ps_prochandle *P)
{
char auxfile[64];
int fd;
return; /* Already read during Pgrab_core() */
return; /* No aux vec for Pgrab_file() */
P->nauxv = 0;
}
procfs_path, (int)P->pid);
return;
} else {
}
}
}
/*
* Return a requested element from the process's aux vector.
* Return -1 on failure (this is adequate for our purposes).
*/
long
{
Preadauxvec(P);
return (-1);
}
return (-1);
}
/*
* Return a pointer to our internal copy of the process's aux vector.
* The caller should not hold on to this pointer across any libproc calls.
*/
const auxv_t *
Pgetauxvec(struct ps_prochandle *P)
{
Preadauxvec(P);
return (&empty);
return (P->auxv);
}
/*
* Return 1 if the given mapping corresponds to the given file_info_t's
* load object; return 0 otherwise.
*/
static int
{
uint_t i;
/*
* We can get for free the start address of the text and data
* sections of the load object. Start by seeing if the mapping
* encloses either of these.
*/
return (1);
/*
* It's still possible that this mapping correponds to the load
* object. Consider the example of a mapping whose start and end
* addresses correspond to those of the load object's text section.
* If the mapping splits, e.g. as a result of a segment demotion,
* then although both mappings are still backed by the same section,
* only one will be seen to enclose that section's start address.
* Thus, to be rigorous, we ask not whether this mapping encloses
* the start of a section, but whether there exists a section that
* encloses the start of this mapping.
*
* If we don't already have the section addresses, and we successfully
* get them, then we cache them in case we come here again.
*/
return (0);
/* Does this section enclose the start of the mapping? */
return (1);
}
return (0);
}
/*
* Find or build the symbol table for the given mapping.
*/
static file_info_t *
{
uint_t i;
Pbuild_file_symtab(P, fptr);
return (fptr);
}
return (NULL);
/*
* Attempt to find a matching file.
* (A file can be mapped at several different addresses.)
*/
Pbuild_file_symtab(P, fptr);
return (fptr);
}
}
/*
* If we need to create a new file_info structure, iterate
* through the load objects in order to attempt to connect
* this new file with its primary text mapping. We again
* need to handle ld.so as a special case because we need
* to be able to bootstrap librtld_db.
*/
return (NULL);
else
(void) Prd_agent(P);
} else {
}
/*
* If librtld_db wasn't able to help us connect the file to a primary
* text mapping, set file_map to the current mapping because we require
* fptr->file_map to be set in Pbuild_file_symtab. librtld_db may be
* unaware of what's going on in the rare case that a legitimate ELF
* file has been mmap(2)ed into the process address space *without*
* the use of dlopen(3x).
*/
Pbuild_file_symtab(P, fptr);
return (fptr);
}
static int
{
return (-1);
#ifdef _BIG_ENDIAN
#else
#endif
return (-1);
sizeof (shdr0))
return (-1);
}
return (0);
}
static int
{
uint_t i;
for (i = 0; i < phnum; i++) {
return (-1);
return (0);
}
return (-1);
}
#ifdef _LP64
static int
{
return (-1);
#ifdef _BIG_ENDIAN
#else
#endif
return (-1);
sizeof (shdr0))
return (-1);
}
return (0);
}
static int
{
uint_t i;
for (i = 0; i < phnum; i++) {
return (-1);
return (0);
}
return (-1);
}
#endif /* _LP64 */
/*
* The text segment for each load object contains the elf header and
* program headers. We can use this information to determine if the
* file that corresponds to the load object is the same file that
* was loaded into the process's address space. There can be a discrepency
* if a file is recompiled after the process is started or if the target
* represents a core file from a differently configured system -- two
* common examples. The DT_CHECKSUM entry in the dynamic section
* provides an easy method of comparison. It is important to note that
* the dynamic section usually lives in the data segment, but the meta
* data we use to find the dynamic section lives in the text segment so
* if either of those segments is absent we can't proceed.
*
* We're looking through the elf file for several items: the symbol tables
* (both dynsym and symtab), the procedure linkage table (PLT) base,
* size, and relocation base, and the CTF information. Most of this can
* be recovered from the loaded image of the file itself, the exceptions
* being the symtab and CTF data.
*
* First we try to open the file that we think corresponds to the load
* object, if the DT_CHECKSUM values match, we're all set, and can simply
* recover all the information we need from the file. If the values of
* DT_CHECKSUM don't match, or if we can't access the file for whatever
* reasaon, we fake up a elf file to use in its stead. If we can't read
* the elf data in the process's address space, we fall back to using
* the file even though it may give inaccurate information.
*
* The elf file that we fake up has to consist of sections for the
* dynsym, the PLT and the dynamic section. Note that in the case of a
* core file, we'll get the CTF data in the file_info_t later on from
* a section embedded the core file (if it's present).
*
* file_differs() conservatively looks for mismatched files, identifying
* a match when there is any ambiguity (since that's the legacy behavior).
*/
static int
{
return (0);
return (0);
/*
* First, we find the checksum value in the elf file.
*/
goto found_shdr;
}
return (0);
return (0);
#ifdef _LP64
#endif
else
return (0);
for (i = 0; i < ndyn; i++) {
goto found_cksum;
}
/*
* The in-memory ELF has no DT_CHECKSUM section, but we will report it
* as matching the file anyhow.
*/
return (0);
/*
* Get the base of the text mapping that corresponds to this file.
*/
return (0);
return (0);
return (0);
}
}
return (0);
dprintf("image cksum value is %llx\n",
#ifdef _LP64
return (0);
return (0);
return (0);
}
}
return (0);
dprintf("image cksum value is %llx\n",
#endif /* _LP64 */
}
return (0);
}
/*
* Read data from the specified process and construct an in memory
* image of an ELF file that represents it well enough to let
* us probe it for information.
*/
static Elf *
{
return (NULL);
return (NULL);
return (NULL);
#ifdef _LP64
} else {
return (NULL);
#endif
}
return (elf);
}
/*
* We wouldn't need these if qsort(3C) took an argument for the callback...
*/
static char *sort_strs;
int
{
return (-1);
return (1);
/*
* Prefer the function to the non-function.
*/
return (-1);
return (1);
}
/*
* Prefer the weak or strong global symbol to the local symbol.
*/
return (-1);
return (1);
}
/*
* Prefer the symbol that doesn't begin with a '$' since compilers and
* other symbol generators often use it as a prefix.
*/
if (*bname == '$')
return (-1);
if (*aname == '$')
return (1);
/*
* Prefer the name with fewer leading underscores in the name.
*/
aname++;
bname++;
}
if (*bname == '_')
return (-1);
if (*aname == '_')
return (1);
/*
* Prefer the symbol with the smaller size.
*/
return (-1);
return (1);
/*
* All other factors being equal, fall back to lexicographic order.
*/
}
static int
{
}
static int
{
}
/*
* Given a symbol index, look up the corresponding symbol from the
* given symbol table.
*
* This function allows the caller to treat the symbol table as a single
* logical entity even though there may be 2 actual ELF symbol tables
* involved. See the comments in Pcontrol.h for details.
*/
static GElf_Sym *
{
/* If index is in range of primary symtab, look it up there */
}
/* Not in primary: Look it up in the auxiliary symtab */
}
void
{
return;
dprintf("optimize_symtab: failed to malloc symbol array");
return;
}
/*
* First record all the symbols into a table and count up the ones
* that we're interested in. We mark symbols as invalid by setting
* the st_name to an illegal value.
*/
count++;
else
}
/*
* Allocate sufficient space for both tables and populate them
* with the same symbols we just counted.
*/
"optimize_symtab: failed to malloc symbol index arrays");
}
return;
}
}
/*
* Sort the two tables according to the appropriate criteria.
*/
(void) mutex_lock(&sort_mtx);
(void) mutex_unlock(&sort_mtx);
}
/*
* Build the symbol table for the given mapped file.
*/
void
{
char objectfile[PATH_MAX];
uint_t i;
GElf_Sym s;
struct {
const char *c_name;
return; /* We've already processed this file */
/*
* Mark the file_info struct as having the symbol table initialized
* even if we fail below. We tried once; we don't try again.
*/
dprintf("libproc ELF version is more recent than libelf\n");
return;
}
/*
* If we're a not live, we can't open files from the /proc
* object directory; we have only the mapping and file names
* to guide us. We prefer the file_lname, but need to handle
* the case of it being NULL in order to bootstrap: we first
* come here during rd_new() when the only information we have
* is interpreter name associated with the AT_BASE mapping.
*/
} else {
}
/*
* Open the object file, create the elf file, and then get the elf
* header and .shstrtab data buffer so we can process sections by
* name. If anything goes wrong try to fake up an elf file from
* the in-core elf image.
*/
dprintf("Pbuild_file_symtab: failed to open %s: %s\n",
dprintf("failed to fake up ELF file\n");
return;
}
dprintf("failed to process ELF file %s: %s\n",
dprintf("failed to fake up ELF file\n");
goto bad;
}
/*
* Before we get too excited about this elf file, we'll check
* its checksum value against the value we have in memory. If
* they don't agree, we try to fake up a new elf file and
* proceed with that instead.
*/
dprintf("ELF file %s (%lx) doesn't match in-core image\n",
dprintf("failed to fake up ELF file\n");
} else {
dprintf("switched to faked up ELF file\n");
}
}
goto bad;
}
/*
* Iterate through each section, caching its section header, data
* pointer, and name. We use this for handling sh_link values below.
*/
dprintf("Pbuild_file_symtab: Failed to get section "
"header\n");
goto bad; /* Failed to get section header */
}
dprintf("Pbuild_file_symtab: Failed to get section "
"data\n");
goto bad; /* Failed to get section data */
}
dprintf("Pbuild_file_symtab: corrupt section name");
goto bad; /* Corrupt section name */
}
}
/*
* Now iterate through the section cache in order to locate info
* for the .symtab, .dynsym, .SUNW_ldynsym, .dynamic, .plt,
* and .SUNW_ctf sections:
*/
/*
* It's possible that the we already got the symbol
* table from the core file itself. Either the file
* differs in which case our faked up elf file will
* only contain the dynsym (not the symtab) or the
* file matches in which case we'll just be replacing
* the symbol table we pulled out of the core file
* with an equivalent one. In either case, this
* check isn't essential, but it's a good idea.
*/
dprintf("Symbol table found for %s\n",
} else {
dprintf("Symbol table already there for %s\n",
}
/* .SUNW_ldynsym section is auxiliary to .dynsym */
dprintf(".SUNW_ldynsym symbol table"
" found for %s\n", objectfile);
} else {
dprintf(".SUNW_ldynsym symbol table already"
" there for %s\n", objectfile);
}
/*
* Skip over bogus CTF sections so they don't come back
* to haunt us later.
*/
dprintf("Bad sh_link %d for "
continue;
}
}
}
/*
* At this point, we've found all the symbol tables we're ever going
* to find: the ones in the loop above and possibly the symtab that
* was included in the core file. Before we perform any lookups, we
* create sorted versions to optimize for lookups.
*/
/*
* Fill in the base address of the text mapping for shared libraries.
* This allows us to translate symbols before librtld_db is ready.
*/
dprintf("setting file_dyn_base for %s to %lx\n",
}
/*
* Record the CTF section information in the file info structure.
*/
}
goto done; /* Nothing else to do if no load object info */
/*
* If the object is a shared library and we have a different rl_base
* value, reset file_dyn_base according to librtld_db's information.
*/
dprintf("resetting file_dyn_base for %s to %lx\n",
}
/*
* Fill in the PLT information for this file if a PLT symbol is found.
*/
/*
* Bring the load object up to date; it is the only way the
* user has to access the PLT data. The PLT information in the
* rd_loadobj_t is not set in the call to map_iter() (the
* callback for rd_loadobj_iter) where we set file_lo.
*/
dprintf("PLT found at %p, size = %lu\n",
}
/*
* Fill in the PLT information.
*/
GElf_Dyn d;
for (i = 0; i < ndyn; i++) {
dprintf("DT_JMPREL is %p\n",
fptr->file_jmp_rel =
break;
}
}
dprintf("_DYNAMIC found at %p, %lu entries, DT_JMPREL = %p\n",
}
done:
return;
bad:
}
}
/*
* Given a process virtual address, return the map_info_t containing it.
* If none found, return NULL.
*/
{
int lo = 0;
int mid;
map_info_t *mp;
/* check that addr is in [vaddr, vaddr + size) */
return (mp);
else
}
return (NULL);
}
/*
* Return the map_info_t for the executable file.
* If not found, return NULL.
*/
static map_info_t *
exec_map(struct ps_prochandle *P)
{
uint_t i;
continue;
return (mptr);
continue;
}
/* This is a poor way to test for text space */
continue;
}
return (mptr);
}
}
return (mold);
}
/*
* Given a shared object name, return the map_info_t for it. If no matching
* object is found, return NULL. Normally, the link maps contain the full
* take one of the following forms:
*
* 2. An exact basename match: "libc.so.1"
* 3. An initial basename match up to a '.' suffix: "libc.so" or "libc"
* 4. The literal string "a.out" is an alias for the executable mapping
*
* The third case is a convenience for callers and may not be necessary.
*
* As the exact same object name may be loaded on different link maps (see
* dlmopen(3DL)), we also allow the caller to resolve the object name by
* specifying a particular link map id. If lmid is PR_LMID_EVERY, the
* first matching name will be returned, regardless of the link map id.
*/
static map_info_t *
{
map_info_t *mp;
uint_t i;
/*
* If we have no rtld_db, then always treat a request as one for all
* link maps.
*/
/*
* First pass: look for exact matches of the entire pathname or
* basename (cases 1 and 2 above):
*/
continue;
if (lmid != PR_LMID_EVERY &&
continue;
/*
* If we match, return the primary text mapping; otherwise
* just return the mapping we matched.
*/
}
/*
* Second pass: look for partial matches (case 3 above):
*/
continue;
if (lmid != PR_LMID_EVERY &&
continue;
/*
* If we match, return the primary text mapping; otherwise
* just return the mapping we matched.
*/
}
/*
* One last check: we allow "a.out" to always alias the executable,
* assuming this name was not in use for something else.
*/
return (P->map_exec);
return (NULL);
}
static map_info_t *
{
if (!P->info_valid)
Pupdate_maps(P);
if (name == PR_OBJ_EXEC)
else if (name == PR_OBJ_LDSO)
else
return (mptr);
}
/*
* When two symbols are found by address, decide which one is to be preferred.
*/
static GElf_Sym *
{
/*
* Prefer the non-NULL symbol.
*/
return (sym2);
return (sym1);
/*
* Defer to the sort ordering...
*/
}
/*
* Look up a symbol by address in the specified symbol table.
* Adjustment to 'addr' must already have been made for the
* offset of the symbol if this is a dynamic library symbol table.
*/
static GElf_Sym *
{
return (NULL);
min = 0;
/*
* We can't return when we've found a match, we have to continue
* searching for the closest matching symbol.
*/
oid = i;
found = 1;
}
else
}
if (!found)
return (NULL);
/*
* There may be many symbols with identical values so we walk
* backward in the byaddr table to find the best match.
*/
do {
i = oid;
if (omid == 0)
break;
*idp = i;
return (symp);
}
/*
* Look up a symbol by name in the specified symbol table.
*/
static GElf_Sym *
{
return (NULL);
min = 0;
*idp = i;
return (symp);
}
if (cmp < 0)
else
}
return (NULL);
}
/*
* Search the process symbol tables looking for a symbol whose
* value to value+size contain the address specified by addr.
* Return values are:
* sym_name_buffer containing the symbol name
* GElf_Sym symbol table entry
* prsyminfo_t ancillary symbol information
* Returns 0 on success, -1 on failure.
*/
int
struct ps_prochandle *P,
char *sym_name_buffer, /* buffer for the symbol name */
{
char *name;
(void) Prd_agent(P);
return (-1);
/*
* Adjust the address by the load object base address in
* case the address turns out to be in a shared library.
*/
/*
* Search both symbol tables, symtab first, then dynsym.
*/
return (-1);
if (bufsize > 0) {
}
}
return (0);
}
int
{
}
/*
* Search the process symbol tables looking for a symbol whose name matches the
* specified name and whose object and link map optionally match the specified
* parameters. On success, the function returns 0 and fills in the GElf_Sym
* symbol table entry. On failure, -1 is returned.
*/
int
struct ps_prochandle *P,
const char *oname, /* load object name */
const char *sname, /* symbol name */
{
int cnt;
int rv = -1;
if (oname == PR_OBJ_EVERY) {
/* create all the file_info_t's for all the mappings */
(void) Prd_agent(P);
} else {
cnt = 1;
return (-1);
}
/*
* Iterate through the loaded object files and look for the symbol
* name in the .symtab and .dynsym of each. If we encounter a match
* with SHN_UNDEF, keep looking in hopes of finding a better match.
* This means that a name such as "puts" will match the puts function
* in libc instead of matching the puts PLT entry in the a.out file.
*/
Pbuild_file_symtab(P, fptr);
continue;
continue;
}
}
} else {
continue;
}
return (0);
if (rv != 0) {
rv = 0;
}
}
if (rv == 0) {
}
return (rv);
}
/*
* Search the process symbol tables looking for a symbol whose name matches the
* specified name, but without any restriction on the link map id.
*/
int
{
}
/*
* Iterate over the process's address space mappings.
*/
int
{
char *object_name;
int rc = 0;
int i;
/* create all the file_info_t's for all the mappings */
(void) Prd_agent(P);
object_name = NULL;
else
return (rc);
}
return (0);
}
/*
* Iterate over the process's mapped objects.
*/
int
{
int rc = 0;
(void) Prd_agent(P); /* create file_info_t's for all the mappings */
Pupdate_maps(P);
continue;
return (rc);
}
return (0);
}
/*
* Given a virtual address, return the name of the underlying
* mapped object (file), as provided by the dynamic linker.
* Return NULL on failure (no underlying shared library).
*/
char *
{
/* create all the file_info_t's for all the mappings */
(void) Prd_agent(P);
return (buffer);
}
return (NULL);
}
/*
* Given a virtual address, return the link map id of the underlying mapped
* object (file), as provided by the dynamic linker. Return -1 on failure.
*/
int
{
/* create all the file_info_t's for all the mappings */
(void) Prd_agent(P);
return (0);
}
return (-1);
}
/*
* Given an object name and optional lmid, iterate over the object's symbols.
* If which == PR_SYMTAB, search the normal symbol table.
* If which == PR_DYNSYM, search the dynamic symbol table.
*/
static int
{
const char *strs;
int rv;
return (-1);
return (-1);
/*
* Search the specified symbol table.
*/
switch (which) {
case PR_SYMTAB:
break;
case PR_DYNSYM:
break;
default:
return (-1);
}
switch (order) {
case PRO_NATURAL:
break;
case PRO_BYNAME:
break;
case PRO_BYADDR:
break;
default:
return (-1);
}
return (-1);
rv = 0;
for (i = 0; i < count; i++) {
continue;
/*
* In case you haven't already guessed, this relies on
* the bitmask used in <libproc.h> for encoding symbol
* type and binding matching the order of STB and STT
* breaking binary compatibility, so I think this is
* reasonably fair game.
*/
continue;
} else
continue; /* Invalid type or binding */
/*
* If symbol's type is STT_SECTION, then try to lookup
* the name of the corresponding section.
*/
break;
}
}
return (rv);
}
int
{
}
int
{
}
int
Psymbol_iter(struct ps_prochandle *P,
{
}
int
Psymbol_iter_by_addr(struct ps_prochandle *P,
{
}
int
Psymbol_iter_by_name(struct ps_prochandle *P,
{
}
/*
* Get the platform string from the core file if we have it;
* just perform the system call for the caller if this is a live process.
*/
char *
{
return (NULL);
}
return (NULL);
}
s[n - 1] = '\0';
return (NULL);
return (s);
}
/*
* Get the uname(2) information from the core file if we have it;
* just perform the system call for the caller if this is a live process.
*/
int
{
return (-1);
}
return (-1);
}
return (0);
}
return (uname(u));
}
/*
* Get the zone name from the core file if we have it; look up the
* name based on the zone id if this is a live process.
*/
char *
{
return (NULL);
}
return (NULL);
}
} else {
return (NULL);
s[n - 1] = '\0';
}
return (s);
}
/*
* Called from Pcreate(), Pgrab(), and Pfgrab_core() to initialize
* the symbol table heads in the new ps_prochandle.
*/
void
Pinitsym(struct ps_prochandle *P)
{
P->num_files = 0;
}
/*
* Called from Prelease() to destroy the symbol tables.
* Must be called by the client after an exec() in the victim process.
*/
void
Preset_maps(struct ps_prochandle *P)
{
int i;
}
}
P->nauxv = 0;
}
for (i = 0; i < P->map_count; i++)
map_info_free(P, &P->mappings[i]);
}
P->info_valid = 0;
}
typedef struct getenv_data {
char *buf;
const char *search;
/*ARGSUSED*/
static int
const char *nameval)
{
getenv_data_t *d = data;
return (0);
return (1);
}
return (0);
}
char *
{
return (buf);
}
}
return (NULL);
}
/* number of argument or environment pointers to read all at once */
#define NARG 100
int
{
int ret;
/*
* Attempt to find the "_environ" variable in the process.
* Failing that, use the original value provided by Ppsinfo().
*/
return (-1);
else
}
}
buflen = 128;
ret = 0;
for (;;) {
ret = -1;
break;
}
int i;
ret = -1;
break;
}
for (i = 0; i < NARG; i++)
}
nenv = 0;
}
break;
/*
* Attempt to read the string from the process.
*/
if (ret <= 0) {
/*
* Bail if we have a corrupted environment
*/
return (-1);
buflen *= 2;
goto again;
} else {
}
break;
}
return (ret);
}