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