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 402c633af4SJohn Birrell struct proc_handle; 412c633af4SJohn Birrell 42820e0679SCraig Rodrigues typedef void (*proc_child_func)(void *); 43820e0679SCraig Rodrigues 442c633af4SJohn Birrell /* Values returned by proc_state(). */ 452c633af4SJohn Birrell #define PS_IDLE 1 462c633af4SJohn Birrell #define PS_STOP 2 472c633af4SJohn Birrell #define PS_RUN 3 482c633af4SJohn Birrell #define PS_UNDEAD 4 492c633af4SJohn Birrell #define PS_DEAD 5 502c633af4SJohn Birrell #define PS_LOST 6 512c633af4SJohn Birrell 528eb20f36SRui Paulo /* Reason values for proc_detach(). */ 538eb20f36SRui Paulo #define PRELEASE_HANG 1 548eb20f36SRui Paulo #define PRELEASE_KILL 2 558eb20f36SRui Paulo 562c633af4SJohn Birrell typedef struct prmap { 572c633af4SJohn Birrell uintptr_t pr_vaddr; /* Virtual address. */ 588eb20f36SRui Paulo size_t pr_size; /* Mapping size in bytes */ 598eb20f36SRui Paulo size_t pr_offset; /* Mapping offset in object */ 608eb20f36SRui Paulo char pr_mapname[PATH_MAX]; /* Mapping filename */ 618eb20f36SRui Paulo uint8_t pr_mflags; /* Protection flags */ 628eb20f36SRui Paulo #define MA_READ 0x01 638eb20f36SRui Paulo #define MA_WRITE 0x02 648eb20f36SRui Paulo #define MA_EXEC 0x04 658eb20f36SRui Paulo #define MA_COW 0x08 668eb20f36SRui Paulo #define MA_NEEDS_COPY 0x10 678eb20f36SRui Paulo #define MA_NOCOREDUMP 0x20 682c633af4SJohn Birrell } prmap_t; 692c633af4SJohn Birrell 708eb20f36SRui Paulo typedef int proc_map_f(void *, const prmap_t *, const char *); 718eb20f36SRui Paulo typedef int proc_sym_f(void *, const GElf_Sym *, const char *); 728eb20f36SRui Paulo 738eb20f36SRui Paulo /* Values for ELF sections */ 748eb20f36SRui Paulo #define PR_SYMTAB 1 758eb20f36SRui Paulo #define PR_DYNSYM 2 768eb20f36SRui Paulo 778eb20f36SRui Paulo /* Values for the 'mask' parameter in the iteration functions */ 788eb20f36SRui Paulo #define BIND_LOCAL 0x0001 798eb20f36SRui Paulo #define BIND_GLOBAL 0x0002 808eb20f36SRui Paulo #define BIND_WEAK 0x0004 818eb20f36SRui Paulo #define BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK) 828eb20f36SRui Paulo #define TYPE_NOTYPE 0x0100 838eb20f36SRui Paulo #define TYPE_OBJECT 0x0200 848eb20f36SRui Paulo #define TYPE_FUNC 0x0400 858eb20f36SRui Paulo #define TYPE_SECTION 0x0800 868eb20f36SRui Paulo #define TYPE_FILE 0x1000 878eb20f36SRui Paulo #define TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|\ 888eb20f36SRui Paulo TYPE_FILE) 898eb20f36SRui Paulo 908eb20f36SRui Paulo typedef enum { 918eb20f36SRui Paulo REG_PC, 928eb20f36SRui Paulo REG_SP, 938eb20f36SRui Paulo REG_RVAL1, 948eb20f36SRui Paulo REG_RVAL2 958eb20f36SRui Paulo } proc_reg_t; 968eb20f36SRui Paulo 978eb20f36SRui Paulo #define SIG2STR_MAX 8 988eb20f36SRui Paulo 998eb20f36SRui Paulo typedef struct lwpstatus { 1008eb20f36SRui Paulo int pr_why; 1018eb20f36SRui Paulo #define PR_REQUESTED 1 1028eb20f36SRui Paulo #define PR_FAULTED 2 1038eb20f36SRui Paulo #define PR_SYSENTRY 3 1048eb20f36SRui Paulo #define PR_SYSEXIT 4 105*92f92525SMark Johnston #define PR_SIGNALLED 5 1068eb20f36SRui Paulo int pr_what; 1078eb20f36SRui Paulo #define FLTBPT -1 1088eb20f36SRui Paulo } lwpstatus_t; 1098eb20f36SRui Paulo 1102c633af4SJohn Birrell /* Function prototype definitions. */ 1112c633af4SJohn Birrell __BEGIN_DECLS 1122c633af4SJohn Birrell 1138eb20f36SRui Paulo prmap_t *proc_addr2map(struct proc_handle *, uintptr_t); 1148eb20f36SRui Paulo prmap_t *proc_name2map(struct proc_handle *, const char *); 1152c633af4SJohn Birrell char *proc_objname(struct proc_handle *, uintptr_t, char *, size_t); 1168eb20f36SRui Paulo prmap_t *proc_obj2map(struct proc_handle *, const char *); 1178eb20f36SRui Paulo int proc_iter_objs(struct proc_handle *, proc_map_f *, void *); 1188eb20f36SRui Paulo int proc_iter_symbyaddr(struct proc_handle *, const char *, int, 1198eb20f36SRui Paulo int, proc_sym_f *, void *); 1202c633af4SJohn Birrell int proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *); 1212c633af4SJohn Birrell int proc_attach(pid_t pid, int flags, struct proc_handle **pphdl); 1222c633af4SJohn Birrell int proc_continue(struct proc_handle *); 1232c633af4SJohn Birrell int proc_clearflags(struct proc_handle *, int); 124820e0679SCraig Rodrigues int proc_create(const char *, char * const *, proc_child_func *, void *, 125820e0679SCraig Rodrigues struct proc_handle **); 1268eb20f36SRui Paulo int proc_detach(struct proc_handle *, int); 1272c633af4SJohn Birrell int proc_getflags(struct proc_handle *); 1282c633af4SJohn Birrell int proc_name2sym(struct proc_handle *, const char *, const char *, GElf_Sym *); 1292c633af4SJohn Birrell int proc_setflags(struct proc_handle *, int); 1302c633af4SJohn Birrell int proc_state(struct proc_handle *); 1312c633af4SJohn Birrell pid_t proc_getpid(struct proc_handle *); 1328eb20f36SRui Paulo int proc_wstatus(struct proc_handle *); 1338eb20f36SRui Paulo int proc_getwstat(struct proc_handle *); 1348eb20f36SRui Paulo char * proc_signame(int, char *, size_t); 1354c74b245SRui Paulo int proc_read(struct proc_handle *, void *, size_t, size_t); 1368eb20f36SRui Paulo const lwpstatus_t * 1378eb20f36SRui Paulo proc_getlwpstatus(struct proc_handle *); 1382c633af4SJohn Birrell void proc_free(struct proc_handle *); 1398eb20f36SRui Paulo rd_agent_t *proc_rdagent(struct proc_handle *); 1408eb20f36SRui Paulo void proc_updatesyms(struct proc_handle *); 1418eb20f36SRui Paulo int proc_bkptset(struct proc_handle *, uintptr_t, unsigned long *); 1428eb20f36SRui Paulo int proc_bkptdel(struct proc_handle *, uintptr_t, unsigned long); 1438eb20f36SRui Paulo void proc_bkptregadj(unsigned long *); 1448eb20f36SRui Paulo int proc_bkptexec(struct proc_handle *, unsigned long); 1458eb20f36SRui Paulo int proc_regget(struct proc_handle *, proc_reg_t, unsigned long *); 1468eb20f36SRui Paulo int proc_regset(struct proc_handle *, proc_reg_t, unsigned long); 1472c633af4SJohn Birrell 1482c633af4SJohn Birrell __END_DECLS 1492c633af4SJohn Birrell 1502c633af4SJohn Birrell #endif /* !_LIBPROC_H_ */ 151