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