1cb314988SRui Paulo /* 2cb314988SRui Paulo * Copyright (c) 2010 The FreeBSD Foundation 3cb314988SRui Paulo * All rights reserved. 4cb314988SRui Paulo * 5cb314988SRui Paulo * This software was developed by Rui Paulo under sponsorship from the 6cb314988SRui Paulo * FreeBSD Foundation. 7cb314988SRui Paulo * 8cb314988SRui Paulo * Redistribution and use in source and binary forms, with or without 9cb314988SRui Paulo * modification, are permitted provided that the following conditions 10cb314988SRui Paulo * are met: 11cb314988SRui Paulo * 1. Redistributions of source code must retain the above copyright 12cb314988SRui Paulo * notice, this list of conditions and the following disclaimer. 13cb314988SRui Paulo * 2. Redistributions in binary form must reproduce the above copyright 14cb314988SRui Paulo * notice, this list of conditions and the following disclaimer in the 15cb314988SRui Paulo * documentation and/or other materials provided with the distribution. 16cb314988SRui Paulo * 17cb314988SRui Paulo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18cb314988SRui Paulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19cb314988SRui Paulo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20cb314988SRui Paulo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21cb314988SRui Paulo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22cb314988SRui Paulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23cb314988SRui Paulo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24cb314988SRui Paulo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25cb314988SRui Paulo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26cb314988SRui Paulo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27cb314988SRui Paulo * SUCH DAMAGE. 28cb314988SRui Paulo * 29cb314988SRui Paulo * $FreeBSD$ 30cb314988SRui Paulo */ 31cb314988SRui Paulo 32cb314988SRui Paulo #ifndef _RTLD_DB_H_ 33cb314988SRui Paulo #define _RTLD_DB_H_ 34cb314988SRui Paulo 35cb314988SRui Paulo #include <sys/param.h> 36cb314988SRui Paulo 37cb314988SRui Paulo #define RD_VERSION 1 38cb314988SRui Paulo 39cb314988SRui Paulo typedef enum { 40cb314988SRui Paulo RD_OK, 41cb314988SRui Paulo RD_ERR, 42cb314988SRui Paulo RD_DBERR, 43cb314988SRui Paulo RD_NOCAPAB, 44cb314988SRui Paulo RD_NODYNAM, 45cb314988SRui Paulo RD_NOBASE, 46cb314988SRui Paulo RD_NOMAPS 47cb314988SRui Paulo } rd_err_e; 48cb314988SRui Paulo 49*a7e13d50SMark Johnston /* XXX struct rd_agent should be private. */ 50*a7e13d50SMark Johnston struct procstat; 51*a7e13d50SMark Johnston 52cb314988SRui Paulo typedef struct rd_agent { 53cb314988SRui Paulo struct proc_handle *rda_php; 54*a7e13d50SMark Johnston 55b252f278SMark Johnston uintptr_t rda_dlactivity_addr; 56b252f278SMark Johnston uintptr_t rda_preinit_addr; 57b252f278SMark Johnston uintptr_t rda_postinit_addr; 58*a7e13d50SMark Johnston 59*a7e13d50SMark Johnston struct procstat *rda_procstat; 60cb314988SRui Paulo } rd_agent_t; 61cb314988SRui Paulo 62cb314988SRui Paulo typedef struct rd_loadobj { 63cb314988SRui Paulo uintptr_t rdl_saddr; /* start address */ 64cb314988SRui Paulo uintptr_t rdl_eaddr; /* end address */ 65cb314988SRui Paulo uint32_t rdl_offset; 66cb314988SRui Paulo uint8_t rdl_prot; 67cb314988SRui Paulo #define RD_RDL_R 0x01 68cb314988SRui Paulo #define RD_RDL_W 0x02 69cb314988SRui Paulo #define RD_RDL_X 0x04 70cb314988SRui Paulo enum { 71cb314988SRui Paulo RDL_TYPE_NONE = 0, 72cb314988SRui Paulo RDL_TYPE_DEF, 73cb314988SRui Paulo RDL_TYPE_VNODE, 74cb314988SRui Paulo RDL_TYPE_SWAP, 75cb314988SRui Paulo RDL_TYPE_DEV, 76cb314988SRui Paulo /* XXX some types missing */ 77cb314988SRui Paulo RDL_TYPE_UNKNOWN = 255 78cb314988SRui Paulo } rdl_type; 79cb314988SRui Paulo unsigned char rdl_path[PATH_MAX]; 80cb314988SRui Paulo } rd_loadobj_t; 81cb314988SRui Paulo 82cb314988SRui Paulo typedef enum { 83cb314988SRui Paulo RD_NONE = 0, 84cb314988SRui Paulo RD_PREINIT, 85cb314988SRui Paulo RD_POSTINIT, 86cb314988SRui Paulo RD_DLACTIVITY 87cb314988SRui Paulo } rd_event_e; 88cb314988SRui Paulo 89cb314988SRui Paulo typedef enum { 90cb314988SRui Paulo RD_NOTIFY_BPT, 91cb314988SRui Paulo RD_NOTIFY_AUTOBPT, 92cb314988SRui Paulo RD_NOTIFY_SYSCALL 93cb314988SRui Paulo } rd_notify_e; 94cb314988SRui Paulo 95cb314988SRui Paulo typedef struct rd_notify { 96cb314988SRui Paulo rd_notify_e type; 97cb314988SRui Paulo union { 98cb314988SRui Paulo uintptr_t bptaddr; 99cb314988SRui Paulo long syscallno; 100cb314988SRui Paulo } u; 101cb314988SRui Paulo } rd_notify_t; 102cb314988SRui Paulo 103cb314988SRui Paulo typedef enum { 104cb314988SRui Paulo RD_NOSTATE = 0, 105cb314988SRui Paulo RD_CONSISTENT, 106cb314988SRui Paulo RD_ADD, 107cb314988SRui Paulo RD_DELETE 108cb314988SRui Paulo } rd_state_e; 109cb314988SRui Paulo 110cb314988SRui Paulo typedef struct rd_event_msg { 111cb314988SRui Paulo rd_event_e type; 112cb314988SRui Paulo union { 113cb314988SRui Paulo rd_state_e state; 114cb314988SRui Paulo } u; 115cb314988SRui Paulo } rd_event_msg_t; 116cb314988SRui Paulo 117cb314988SRui Paulo typedef enum { 118cb314988SRui Paulo RD_RESOLVE_NONE, 119cb314988SRui Paulo RD_RESOLVE_STEP, 120cb314988SRui Paulo RD_RESOLVE_TARGET, 121cb314988SRui Paulo RD_RESOLVE_TARGET_STEP 122cb314988SRui Paulo } rd_skip_e; 123cb314988SRui Paulo 124cb314988SRui Paulo typedef struct rd_plt_info { 125cb314988SRui Paulo rd_skip_e pi_skip_method; 126cb314988SRui Paulo long pi_nstep; 127cb314988SRui Paulo uintptr_t pi_target; 128cb314988SRui Paulo uintptr_t pi_baddr; 129cb314988SRui Paulo unsigned int pi_flags; 130cb314988SRui Paulo } rd_plt_info_t; 131cb314988SRui Paulo 132cb314988SRui Paulo #define RD_FLG_PI_PLTBOUND 0x0001 133cb314988SRui Paulo 134cb314988SRui Paulo __BEGIN_DECLS 135cb314988SRui Paulo 136cb314988SRui Paulo struct proc_handle; 137cb314988SRui Paulo void rd_delete(rd_agent_t *); 138cb314988SRui Paulo const char *rd_errstr(rd_err_e); 139cb314988SRui Paulo rd_err_e rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *); 140cb314988SRui Paulo rd_err_e rd_event_enable(rd_agent_t *, int); 141cb314988SRui Paulo rd_err_e rd_event_getmsg(rd_agent_t *, rd_event_msg_t *); 142cb314988SRui Paulo rd_err_e rd_init(int); 143cb314988SRui Paulo typedef int rl_iter_f(const rd_loadobj_t *, void *); 144cb314988SRui Paulo rd_err_e rd_loadobj_iter(rd_agent_t *, rl_iter_f *, void *); 145cb314988SRui Paulo void rd_log(const int); 146cb314988SRui Paulo rd_agent_t *rd_new(struct proc_handle *); 147cb314988SRui Paulo rd_err_e rd_objpad_enable(rd_agent_t *, size_t); 148cb314988SRui Paulo struct proc; 149cb314988SRui Paulo rd_err_e rd_plt_resolution(rd_agent_t *, uintptr_t, struct proc *, 150cb314988SRui Paulo uintptr_t, rd_plt_info_t *); 151cb314988SRui Paulo rd_err_e rd_reset(rd_agent_t *); 152cb314988SRui Paulo 153cb314988SRui Paulo __END_DECLS 154cb314988SRui Paulo 155cb314988SRui Paulo #endif /* _RTLD_DB_H_ */ 156