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