xref: /titanic_52/usr/src/head/rtld_db.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23*ba3594baSGarrett D'Amore  *
2422872efbSedp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25159cf8a6Swesolows  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_RTLD_DB_H
297c478bd9Sstevel@tonic-gate #define	_RTLD_DB_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
379acbbeafSnn35248 #include <sys/elf.h>
387c478bd9Sstevel@tonic-gate #include <link.h>
397c478bd9Sstevel@tonic-gate #include <proc_service.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * librtld_db interface versions
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate #define	RD_VERSION1	1
467c478bd9Sstevel@tonic-gate #define	RD_VERSION2	2
477c478bd9Sstevel@tonic-gate #define	RD_VERSION3	3
487c478bd9Sstevel@tonic-gate #define	RD_VERSION4	4
497c478bd9Sstevel@tonic-gate #define	RD_VERSION	RD_VERSION4
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef enum {
527c478bd9Sstevel@tonic-gate 	RD_ERR,		/* generic */
537c478bd9Sstevel@tonic-gate 	RD_OK,		/* generic "call" succeeded */
547c478bd9Sstevel@tonic-gate 	RD_NOCAPAB,	/* capability not available */
557c478bd9Sstevel@tonic-gate 	RD_DBERR,	/* import service failed */
567c478bd9Sstevel@tonic-gate 	RD_NOBASE,	/* 5.x: aux tag AT_BASE not found */
577c478bd9Sstevel@tonic-gate 	RD_NODYNAM,	/* symbol 'DYNAMIC' not found */
587c478bd9Sstevel@tonic-gate 	RD_NOMAPS	/* link-maps are not yet available */
597c478bd9Sstevel@tonic-gate } rd_err_e;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * ways that the event notification can take place:
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate typedef enum {
667c478bd9Sstevel@tonic-gate 	RD_NOTIFY_BPT,		/* set break-point at address */
677c478bd9Sstevel@tonic-gate 	RD_NOTIFY_AUTOBPT,	/* 4.x compat. not used in 5.x */
687c478bd9Sstevel@tonic-gate 	RD_NOTIFY_SYSCALL	/* watch for syscall */
697c478bd9Sstevel@tonic-gate } rd_notify_e;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * information on ways that the event notification can take place:
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate typedef struct rd_notify {
757c478bd9Sstevel@tonic-gate 	rd_notify_e	type;
767c478bd9Sstevel@tonic-gate 	union {
777c478bd9Sstevel@tonic-gate 		psaddr_t	bptaddr;	/* break point address */
787c478bd9Sstevel@tonic-gate 		long		syscallno;	/* system call id */
797c478bd9Sstevel@tonic-gate 	} u;
807c478bd9Sstevel@tonic-gate } rd_notify_t;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * information about event instance:
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate typedef enum {
867c478bd9Sstevel@tonic-gate 	RD_NOSTATE = 0,		/* no state information */
877c478bd9Sstevel@tonic-gate 	RD_CONSISTENT,		/* link-maps are stable */
887c478bd9Sstevel@tonic-gate 	RD_ADD,			/* currently adding object to link-maps */
897c478bd9Sstevel@tonic-gate 	RD_DELETE		/* currently deleteing object from link-maps */
907c478bd9Sstevel@tonic-gate } rd_state_e;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate typedef struct rd_event_msg {
937c478bd9Sstevel@tonic-gate 	rd_event_e	type;
947c478bd9Sstevel@tonic-gate 	union {
957c478bd9Sstevel@tonic-gate 		rd_state_e	state;	/* for DLACTIVITY */
967c478bd9Sstevel@tonic-gate 	} u;
977c478bd9Sstevel@tonic-gate } rd_event_msg_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * iteration over load objects
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate typedef struct rd_loadobj {
1047c478bd9Sstevel@tonic-gate 	psaddr_t	rl_nameaddr;	/* address of the name in user space */
1057c478bd9Sstevel@tonic-gate 	unsigned	rl_flags;
1067c478bd9Sstevel@tonic-gate 	psaddr_t	rl_base;	/* base of address of code */
1077c478bd9Sstevel@tonic-gate 	psaddr_t	rl_data_base;	/* base of address of data */
1087c478bd9Sstevel@tonic-gate 	Lmid_t		rl_lmident;	/* ident of link map */
1097c478bd9Sstevel@tonic-gate 	psaddr_t	rl_refnameaddr;	/* reference name of filter in user */
1107c478bd9Sstevel@tonic-gate 					/* space.  If non null object is a */
1117c478bd9Sstevel@tonic-gate 					/* filter. */
1127c478bd9Sstevel@tonic-gate 	psaddr_t	rl_plt_base;	/* These fields are present for 4.x */
1137c478bd9Sstevel@tonic-gate 	unsigned	rl_plt_size;	/* compatibility and are not */
1147c478bd9Sstevel@tonic-gate 					/* currently used  in SunOS5.x */
1157c478bd9Sstevel@tonic-gate 	psaddr_t	rl_bend;	/* end of image (text+data+bss) */
1167c478bd9Sstevel@tonic-gate 	psaddr_t	rl_padstart;	/* start of padding */
1177c478bd9Sstevel@tonic-gate 	psaddr_t	rl_padend;	/* end of image after padding */
1187c478bd9Sstevel@tonic-gate 	psaddr_t	rl_dynamic;	/* points to the DYNAMIC section */
1197c478bd9Sstevel@tonic-gate 					/* in the target process */
1207c478bd9Sstevel@tonic-gate 	unsigned long	rl_tlsmodid;	/* module ID for TLS references */
1217c478bd9Sstevel@tonic-gate } rd_loadobj_t;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * Values for rl_flags
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate #define	RD_FLG_MEM_OBJECT	0x0001	/* Identifies this object as */
1277c478bd9Sstevel@tonic-gate 					/* originating from a relocatable */
1287c478bd9Sstevel@tonic-gate 					/* module which was dynamically */
1297c478bd9Sstevel@tonic-gate 					/* loaded */
1307c478bd9Sstevel@tonic-gate 
1319acbbeafSnn35248 /*
1329acbbeafSnn35248  * Commands for rd_ctl()
1339acbbeafSnn35248  */
1349acbbeafSnn35248 #define	RD_CTL_SET_HELPPATH	0x01	/* Set the path used to find helpers */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate typedef struct rd_agent rd_agent_t;
1377c478bd9Sstevel@tonic-gate typedef int rl_iter_f(const rd_loadobj_t *, void *);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * PLT skipping
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate typedef enum {
1447c478bd9Sstevel@tonic-gate     RD_RESOLVE_NONE,		/* don't do anything special */
1457c478bd9Sstevel@tonic-gate     RD_RESOLVE_STEP,		/* step 'pi_nstep' instructions */
1467c478bd9Sstevel@tonic-gate     RD_RESOLVE_TARGET,		/* resolved target is in 'pi_target' */
1477c478bd9Sstevel@tonic-gate     RD_RESOLVE_TARGET_STEP	/* put a bpt on target, then step nstep times */
1487c478bd9Sstevel@tonic-gate } rd_skip_e;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate typedef struct rd_plt_info {
1527c478bd9Sstevel@tonic-gate 	rd_skip_e	pi_skip_method;
1537c478bd9Sstevel@tonic-gate 	long		pi_nstep;
1547c478bd9Sstevel@tonic-gate 	psaddr_t	pi_target;
1557c478bd9Sstevel@tonic-gate 	psaddr_t	pi_baddr;
1567c478bd9Sstevel@tonic-gate 	unsigned int	pi_flags;
1577c478bd9Sstevel@tonic-gate } rd_plt_info_t;
1587c478bd9Sstevel@tonic-gate 
1599acbbeafSnn35248 
1609acbbeafSnn35248 /*
1617c478bd9Sstevel@tonic-gate  * Values for pi_flags
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate #define	RD_FLG_PI_PLTBOUND	0x0001	/* Indicates that the PLT */
1647c478bd9Sstevel@tonic-gate 					/* has been bound - and that */
165159cf8a6Swesolows 					/* pi_baddr will contain its */
1667c478bd9Sstevel@tonic-gate 					/* destination address */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate struct	ps_prochandle;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * librtld_db.so entry points
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate extern void		rd_delete(rd_agent_t *);
1747c478bd9Sstevel@tonic-gate extern char		*rd_errstr(rd_err_e rderr);
1757c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *);
1767c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_enable(rd_agent_t *, int);
1777c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_getmsg(rd_agent_t *, rd_event_msg_t *);
1787c478bd9Sstevel@tonic-gate extern rd_err_e		rd_init(int);
1799acbbeafSnn35248 extern rd_err_e		rd_ctl(int, void *);
1807c478bd9Sstevel@tonic-gate extern rd_err_e		rd_loadobj_iter(rd_agent_t *, rl_iter_f *,
1817c478bd9Sstevel@tonic-gate 				void *);
1827c478bd9Sstevel@tonic-gate extern void		rd_log(const int);
1837c478bd9Sstevel@tonic-gate extern rd_agent_t	*rd_new(struct ps_prochandle *);
1847c478bd9Sstevel@tonic-gate extern rd_err_e		rd_objpad_enable(struct rd_agent *, size_t);
1857c478bd9Sstevel@tonic-gate extern rd_err_e		rd_plt_resolution(rd_agent_t *, psaddr_t, lwpid_t,
1867c478bd9Sstevel@tonic-gate 				psaddr_t, rd_plt_info_t *);
18722872efbSedp extern rd_err_e		rd_get_dyns(rd_agent_t *, psaddr_t, void **, size_t *);
1887c478bd9Sstevel@tonic-gate extern rd_err_e		rd_reset(struct rd_agent *);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #endif	/* _RTLD_DB_H */
195