xref: /freebsd/lib/librtld_db/rtld_db.h (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 
32 #ifndef _RTLD_DB_H_
33 #define _RTLD_DB_H_
34 
35 #include <sys/param.h>
36 
37 #define	RD_VERSION	1
38 
39 typedef enum {
40 	RD_OK,
41 	RD_ERR,
42 	RD_DBERR,
43 	RD_NOCAPAB,
44 	RD_NODYNAM,
45 	RD_NOBASE,
46 	RD_NOMAPS
47 } rd_err_e;
48 
49 /* XXX struct rd_agent should be private. */
50 struct procstat;
51 
52 typedef struct rd_agent {
53 	struct proc_handle *rda_php;
54 
55 	uintptr_t rda_dlactivity_addr;
56 	uintptr_t rda_preinit_addr;
57 	uintptr_t rda_postinit_addr;
58 
59 	struct procstat *rda_procstat;
60 } rd_agent_t;
61 
62 typedef struct rd_loadobj {
63 	uintptr_t	rdl_saddr;		/* start address */
64 	uintptr_t	rdl_eaddr;		/* end address */
65 	uint32_t	rdl_offset;
66 	uint8_t		rdl_prot;
67 #define RD_RDL_R	0x01
68 #define RD_RDL_W	0x02
69 #define RD_RDL_X	0x04
70 	enum {
71 		RDL_TYPE_NONE	= 0,
72 		RDL_TYPE_DEF,
73 		RDL_TYPE_VNODE,
74 		RDL_TYPE_SWAP,
75 		RDL_TYPE_DEV,
76 		/* XXX some types missing */
77 		RDL_TYPE_UNKNOWN = 255
78 	} rdl_type;
79 	unsigned char	rdl_path[PATH_MAX];
80 } rd_loadobj_t;
81 
82 typedef enum {
83 	RD_NONE = 0,
84 	RD_PREINIT,
85 	RD_POSTINIT,
86 	RD_DLACTIVITY
87 } rd_event_e;
88 
89 typedef enum {
90 	RD_NOTIFY_BPT,
91 	RD_NOTIFY_AUTOBPT,
92 	RD_NOTIFY_SYSCALL
93 } rd_notify_e;
94 
95 typedef struct rd_notify {
96 	rd_notify_e type;
97 	union {
98 		uintptr_t bptaddr;
99 		long      syscallno;
100 	} u;
101 } rd_notify_t;
102 
103 typedef enum {
104 	RD_NOSTATE = 0,
105 	RD_CONSISTENT,
106 	RD_ADD,
107 	RD_DELETE
108 } rd_state_e;
109 
110 typedef struct rd_event_msg {
111 	rd_event_e type;
112 	union {
113 		rd_state_e state;
114 	} u;
115 } rd_event_msg_t;
116 
117 typedef enum {
118 	RD_RESOLVE_NONE,
119 	RD_RESOLVE_STEP,
120 	RD_RESOLVE_TARGET,
121 	RD_RESOLVE_TARGET_STEP
122 } rd_skip_e;
123 
124 typedef struct rd_plt_info {
125 	rd_skip_e pi_skip_method;
126 	long	  pi_nstep;
127 	uintptr_t pi_target;
128 	uintptr_t pi_baddr;
129 	unsigned int pi_flags;
130 } rd_plt_info_t;
131 
132 #define RD_FLG_PI_PLTBOUND	0x0001
133 
134 __BEGIN_DECLS
135 
136 struct proc_handle;
137 void		rd_delete(rd_agent_t *);
138 const char 	*rd_errstr(rd_err_e);
139 rd_err_e	rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *);
140 rd_err_e	rd_event_enable(rd_agent_t *, int);
141 rd_err_e	rd_event_getmsg(rd_agent_t *, rd_event_msg_t *);
142 rd_err_e	rd_init(int);
143 typedef int rl_iter_f(const rd_loadobj_t *, void *);
144 rd_err_e	rd_loadobj_iter(rd_agent_t *, rl_iter_f *, void *);
145 void		rd_log(const int);
146 rd_agent_t 	*rd_new(struct proc_handle *);
147 rd_err_e	rd_objpad_enable(rd_agent_t *, size_t);
148 struct proc;
149 rd_err_e	rd_plt_resolution(rd_agent_t *, uintptr_t, struct proc *,
150 		    uintptr_t, rd_plt_info_t *);
151 rd_err_e	rd_reset(rd_agent_t *);
152 
153 __END_DECLS
154 
155 #endif /* _RTLD_DB_H_ */
156