12c633af4SJohn Birrell /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35e53a4f9SPedro F. Giffuni * 42c633af4SJohn Birrell * Copyright (c) 2008 John Birrell (jb@freebsd.org) 52c633af4SJohn Birrell * All rights reserved. 62c633af4SJohn Birrell * 72c633af4SJohn Birrell * Redistribution and use in source and binary forms, with or without 82c633af4SJohn Birrell * modification, are permitted provided that the following conditions 92c633af4SJohn Birrell * are met: 102c633af4SJohn Birrell * 1. Redistributions of source code must retain the above copyright 112c633af4SJohn Birrell * notice, this list of conditions and the following disclaimer. 122c633af4SJohn Birrell * 2. Redistributions in binary form must reproduce the above copyright 132c633af4SJohn Birrell * notice, this list of conditions and the following disclaimer in the 142c633af4SJohn Birrell * documentation and/or other materials provided with the distribution. 152c633af4SJohn Birrell * 162c633af4SJohn Birrell * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 172c633af4SJohn Birrell * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 182c633af4SJohn Birrell * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 192c633af4SJohn Birrell * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 202c633af4SJohn Birrell * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 212c633af4SJohn Birrell * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 222c633af4SJohn Birrell * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 232c633af4SJohn Birrell * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 242c633af4SJohn Birrell * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 252c633af4SJohn Birrell * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 262c633af4SJohn Birrell * SUCH DAMAGE. 272c633af4SJohn Birrell * 282c633af4SJohn Birrell * $FreeBSD$ 292c633af4SJohn Birrell */ 302c633af4SJohn Birrell 31fcf9fc10SMark Johnston #ifndef __LIBPROC_H_ 32fcf9fc10SMark Johnston #define __LIBPROC_H_ 33fcf9fc10SMark Johnston 342c633af4SJohn Birrell #include <sys/types.h> 352c633af4SJohn Birrell #include <sys/ptrace.h> 36700244a2SMark Johnston 3707a9c2e6SMark Johnston #include <libelf.h> 388eb20f36SRui Paulo #include <rtld_db.h> 392c633af4SJohn Birrell 402c633af4SJohn Birrell #include "libproc.h" 412c633af4SJohn Birrell 424808a678SMark Johnston struct procstat; 434808a678SMark Johnston 44c156354fSMark Johnston struct symtab { 45c156354fSMark Johnston Elf_Data *data; 46c156354fSMark Johnston u_int nsyms; 47c156354fSMark Johnston u_int *index; 48c156354fSMark Johnston u_long stridx; 49c156354fSMark Johnston }; 50c156354fSMark Johnston 5107a9c2e6SMark Johnston struct file_info { 5207a9c2e6SMark Johnston Elf *elf; 5307a9c2e6SMark Johnston int fd; 5407a9c2e6SMark Johnston u_int refs; 55c156354fSMark Johnston GElf_Ehdr ehdr; 56c156354fSMark Johnston 57c156354fSMark Johnston /* Symbol tables, sorted by value. */ 58c156354fSMark Johnston struct symtab dynsymtab; 59c156354fSMark Johnston struct symtab symtab; 6007a9c2e6SMark Johnston }; 6107a9c2e6SMark Johnston 6207a9c2e6SMark Johnston struct map_info { 6307a9c2e6SMark Johnston prmap_t map; 6407a9c2e6SMark Johnston struct file_info *file; 6507a9c2e6SMark Johnston }; 6607a9c2e6SMark Johnston 672c633af4SJohn Birrell struct proc_handle { 68b1bb30e5SMark Johnston struct proc_handle_public public; /* Public fields. */ 692c633af4SJohn Birrell int flags; /* Process flags. */ 702c633af4SJohn Birrell int status; /* Process status (PS_*). */ 718eb20f36SRui Paulo int wstat; /* Process wait status. */ 724808a678SMark Johnston int model; /* Process data model. */ 738eb20f36SRui Paulo rd_agent_t *rdap; /* librtld_db agent */ 7407a9c2e6SMark Johnston struct map_info *mappings; /* File mappings for proc. */ 7507a9c2e6SMark Johnston size_t maparrsz; /* Map array size. */ 7607a9c2e6SMark Johnston size_t nmappings; /* Number of mappings. */ 772c73c414SMark Johnston size_t exec_map; /* Executable text mapping index. */ 7807a9c2e6SMark Johnston lwpstatus_t lwps; /* Process status. */ 794808a678SMark Johnston struct procstat *procstat; /* libprocstat handle. */ 8007a9c2e6SMark Johnston char execpath[PATH_MAX]; /* Path to program executable. */ 812c633af4SJohn Birrell }; 822c633af4SJohn Birrell 838eb20f36SRui Paulo #ifdef DEBUG 8425aecfbbSMark Johnston #define DPRINTF(...) warn(__VA_ARGS__) 8530e81f7eSMark Johnston #define DPRINTFX(...) warnx(__VA_ARGS__) 868eb20f36SRui Paulo #else 87fb15925cSMark Johnston #define DPRINTF(...) do { } while (0) 88fb15925cSMark Johnston #define DPRINTFX(...) do { } while (0) 898eb20f36SRui Paulo #endif 90fcf9fc10SMark Johnston 91fcf9fc10SMark Johnston #endif /* __LIBPROC_H_ */ 92