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