12c633af4SJohn Birrell /*- 28eb20f36SRui Paulo * Copyright (c) 2010 The FreeBSD Foundation 32c633af4SJohn Birrell * Copyright (c) 2008 John Birrell (jb@freebsd.org) 42c633af4SJohn Birrell * All rights reserved. 52c633af4SJohn Birrell * 68eb20f36SRui Paulo * Portions of this software were developed by Rui Paulo under sponsorship 78eb20f36SRui Paulo * from the FreeBSD Foundation. 88eb20f36SRui Paulo * 92c633af4SJohn Birrell * Redistribution and use in source and binary forms, with or without 102c633af4SJohn Birrell * modification, are permitted provided that the following conditions 112c633af4SJohn Birrell * are met: 122c633af4SJohn Birrell * 1. Redistributions of source code must retain the above copyright 132c633af4SJohn Birrell * notice, this list of conditions and the following disclaimer. 142c633af4SJohn Birrell * 2. Redistributions in binary form must reproduce the above copyright 152c633af4SJohn Birrell * notice, this list of conditions and the following disclaimer in the 162c633af4SJohn Birrell * documentation and/or other materials provided with the distribution. 172c633af4SJohn Birrell * 182c633af4SJohn Birrell * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 192c633af4SJohn Birrell * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202c633af4SJohn Birrell * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212c633af4SJohn Birrell * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 222c633af4SJohn Birrell * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232c633af4SJohn Birrell * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 242c633af4SJohn Birrell * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 252c633af4SJohn Birrell * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 262c633af4SJohn Birrell * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 272c633af4SJohn Birrell * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282c633af4SJohn Birrell * SUCH DAMAGE. 292c633af4SJohn Birrell * 302c633af4SJohn Birrell * $FreeBSD$ 312c633af4SJohn Birrell */ 322c633af4SJohn Birrell 332c633af4SJohn Birrell #ifndef _LIBPROC_H_ 342c633af4SJohn Birrell #define _LIBPROC_H_ 352c633af4SJohn Birrell 362c633af4SJohn Birrell #include <gelf.h> 378eb20f36SRui Paulo #include <rtld_db.h> 388eb20f36SRui Paulo #include <limits.h> 392c633af4SJohn Birrell 4041da933cSMark Johnston struct ctf_file; 412c633af4SJohn Birrell struct proc_handle; 422c633af4SJohn Birrell 43820e0679SCraig Rodrigues typedef void (*proc_child_func)(void *); 44820e0679SCraig Rodrigues 452c633af4SJohn Birrell /* Values returned by proc_state(). */ 462c633af4SJohn Birrell #define PS_IDLE 1 472c633af4SJohn Birrell #define PS_STOP 2 482c633af4SJohn Birrell #define PS_RUN 3 492c633af4SJohn Birrell #define PS_UNDEAD 4 502c633af4SJohn Birrell #define PS_DEAD 5 512c633af4SJohn Birrell #define PS_LOST 6 522c633af4SJohn Birrell 538eb20f36SRui Paulo /* Reason values for proc_detach(). */ 548eb20f36SRui Paulo #define PRELEASE_HANG 1 558eb20f36SRui Paulo #define PRELEASE_KILL 2 568eb20f36SRui Paulo 572c633af4SJohn Birrell typedef struct prmap { 582c633af4SJohn Birrell uintptr_t pr_vaddr; /* Virtual address. */ 598eb20f36SRui Paulo size_t pr_size; /* Mapping size in bytes */ 608eb20f36SRui Paulo size_t pr_offset; /* Mapping offset in object */ 618eb20f36SRui Paulo char pr_mapname[PATH_MAX]; /* Mapping filename */ 628eb20f36SRui Paulo uint8_t pr_mflags; /* Protection flags */ 638eb20f36SRui Paulo #define MA_READ 0x01 648eb20f36SRui Paulo #define MA_WRITE 0x02 658eb20f36SRui Paulo #define MA_EXEC 0x04 668eb20f36SRui Paulo #define MA_COW 0x08 678eb20f36SRui Paulo #define MA_NEEDS_COPY 0x10 688eb20f36SRui Paulo #define MA_NOCOREDUMP 0x20 692c633af4SJohn Birrell } prmap_t; 702c633af4SJohn Birrell 7141da933cSMark Johnston typedef struct prsyminfo { 7241da933cSMark Johnston u_int prs_lmid; /* Map id. */ 7341da933cSMark Johnston u_int prs_id; /* Symbol id. */ 7441da933cSMark Johnston } prsyminfo_t; 7541da933cSMark Johnston 768eb20f36SRui Paulo typedef int proc_map_f(void *, const prmap_t *, const char *); 778eb20f36SRui Paulo typedef int proc_sym_f(void *, const GElf_Sym *, const char *); 788eb20f36SRui Paulo 798eb20f36SRui Paulo /* Values for ELF sections */ 808eb20f36SRui Paulo #define PR_SYMTAB 1 818eb20f36SRui Paulo #define PR_DYNSYM 2 828eb20f36SRui Paulo 838eb20f36SRui Paulo /* Values for the 'mask' parameter in the iteration functions */ 848eb20f36SRui Paulo #define BIND_LOCAL 0x0001 858eb20f36SRui Paulo #define BIND_GLOBAL 0x0002 868eb20f36SRui Paulo #define BIND_WEAK 0x0004 878eb20f36SRui Paulo #define BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK) 888eb20f36SRui Paulo #define TYPE_NOTYPE 0x0100 898eb20f36SRui Paulo #define TYPE_OBJECT 0x0200 908eb20f36SRui Paulo #define TYPE_FUNC 0x0400 918eb20f36SRui Paulo #define TYPE_SECTION 0x0800 928eb20f36SRui Paulo #define TYPE_FILE 0x1000 938eb20f36SRui Paulo #define TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|\ 948eb20f36SRui Paulo TYPE_FILE) 958eb20f36SRui Paulo 968eb20f36SRui Paulo typedef enum { 978eb20f36SRui Paulo REG_PC, 988eb20f36SRui Paulo REG_SP, 998eb20f36SRui Paulo REG_RVAL1, 1008eb20f36SRui Paulo REG_RVAL2 1018eb20f36SRui Paulo } proc_reg_t; 1028eb20f36SRui Paulo 1038eb20f36SRui Paulo #define SIG2STR_MAX 8 1048eb20f36SRui Paulo 1058eb20f36SRui Paulo typedef struct lwpstatus { 1068eb20f36SRui Paulo int pr_why; 1078eb20f36SRui Paulo #define PR_REQUESTED 1 1088eb20f36SRui Paulo #define PR_FAULTED 2 1098eb20f36SRui Paulo #define PR_SYSENTRY 3 1108eb20f36SRui Paulo #define PR_SYSEXIT 4 11192f92525SMark Johnston #define PR_SIGNALLED 5 1128eb20f36SRui Paulo int pr_what; 1138eb20f36SRui Paulo #define FLTBPT -1 1148eb20f36SRui Paulo } lwpstatus_t; 1158eb20f36SRui Paulo 1164808a678SMark Johnston #define PR_MODEL_ILP32 1 1174808a678SMark Johnston #define PR_MODEL_LP64 2 1184808a678SMark Johnston 1192c633af4SJohn Birrell /* Function prototype definitions. */ 1202c633af4SJohn Birrell __BEGIN_DECLS 1212c633af4SJohn Birrell 1228eb20f36SRui Paulo prmap_t *proc_addr2map(struct proc_handle *, uintptr_t); 1238eb20f36SRui Paulo prmap_t *proc_name2map(struct proc_handle *, const char *); 1242c633af4SJohn Birrell char *proc_objname(struct proc_handle *, uintptr_t, char *, size_t); 1258eb20f36SRui Paulo prmap_t *proc_obj2map(struct proc_handle *, const char *); 1268eb20f36SRui Paulo int proc_iter_objs(struct proc_handle *, proc_map_f *, void *); 1278eb20f36SRui Paulo int proc_iter_symbyaddr(struct proc_handle *, const char *, int, 1288eb20f36SRui Paulo int, proc_sym_f *, void *); 1292c633af4SJohn Birrell int proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *); 1302c633af4SJohn Birrell int proc_attach(pid_t pid, int flags, struct proc_handle **pphdl); 1312c633af4SJohn Birrell int proc_continue(struct proc_handle *); 1322c633af4SJohn Birrell int proc_clearflags(struct proc_handle *, int); 133820e0679SCraig Rodrigues int proc_create(const char *, char * const *, proc_child_func *, void *, 134820e0679SCraig Rodrigues struct proc_handle **); 1358eb20f36SRui Paulo int proc_detach(struct proc_handle *, int); 1362c633af4SJohn Birrell int proc_getflags(struct proc_handle *); 13741da933cSMark Johnston int proc_name2sym(struct proc_handle *, const char *, const char *, 13841da933cSMark Johnston GElf_Sym *, prsyminfo_t *); 13941da933cSMark Johnston struct ctf_file *proc_name2ctf(struct proc_handle *, const char *); 1402c633af4SJohn Birrell int proc_setflags(struct proc_handle *, int); 1412c633af4SJohn Birrell int proc_state(struct proc_handle *); 1424808a678SMark Johnston int proc_getmodel(struct proc_handle *); 1432c633af4SJohn Birrell pid_t proc_getpid(struct proc_handle *); 1448eb20f36SRui Paulo int proc_wstatus(struct proc_handle *); 1458eb20f36SRui Paulo int proc_getwstat(struct proc_handle *); 1468eb20f36SRui Paulo char * proc_signame(int, char *, size_t); 1474c74b245SRui Paulo int proc_read(struct proc_handle *, void *, size_t, size_t); 14841da933cSMark Johnston const lwpstatus_t *proc_getlwpstatus(struct proc_handle *); 1492c633af4SJohn Birrell void proc_free(struct proc_handle *); 1508eb20f36SRui Paulo rd_agent_t *proc_rdagent(struct proc_handle *); 1518eb20f36SRui Paulo void proc_updatesyms(struct proc_handle *); 1528eb20f36SRui Paulo int proc_bkptset(struct proc_handle *, uintptr_t, unsigned long *); 1538eb20f36SRui Paulo int proc_bkptdel(struct proc_handle *, uintptr_t, unsigned long); 1548eb20f36SRui Paulo void proc_bkptregadj(unsigned long *); 1558eb20f36SRui Paulo int proc_bkptexec(struct proc_handle *, unsigned long); 1568eb20f36SRui Paulo int proc_regget(struct proc_handle *, proc_reg_t, unsigned long *); 1578eb20f36SRui Paulo int proc_regset(struct proc_handle *, proc_reg_t, unsigned long); 1582c633af4SJohn Birrell 1592c633af4SJohn Birrell __END_DECLS 1602c633af4SJohn Birrell 161*fcf9fc10SMark Johnston #endif /* _LIBPROC_H_ */ 162