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