xref: /onnv-gate/usr/src/head/rtld_db.h (revision 6830:296b2ea3c777)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52712Snn35248  * Common Development and Distribution License (the "License").
62712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6830Sedp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23376Swesolows  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_RTLD_DB_H
270Sstevel@tonic-gate #define	_RTLD_DB_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/lwp.h>
382712Snn35248 #include <sys/elf.h>
390Sstevel@tonic-gate #include <link.h>
400Sstevel@tonic-gate #include <proc_service.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * librtld_db interface versions
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate #define	RD_VERSION1	1
470Sstevel@tonic-gate #define	RD_VERSION2	2
480Sstevel@tonic-gate #define	RD_VERSION3	3
490Sstevel@tonic-gate #define	RD_VERSION4	4
500Sstevel@tonic-gate #define	RD_VERSION	RD_VERSION4
510Sstevel@tonic-gate 
520Sstevel@tonic-gate typedef enum {
530Sstevel@tonic-gate 	RD_ERR,		/* generic */
540Sstevel@tonic-gate 	RD_OK,		/* generic "call" succeeded */
550Sstevel@tonic-gate 	RD_NOCAPAB,	/* capability not available */
560Sstevel@tonic-gate 	RD_DBERR,	/* import service failed */
570Sstevel@tonic-gate 	RD_NOBASE,	/* 5.x: aux tag AT_BASE not found */
580Sstevel@tonic-gate 	RD_NODYNAM,	/* symbol 'DYNAMIC' not found */
590Sstevel@tonic-gate 	RD_NOMAPS	/* link-maps are not yet available */
600Sstevel@tonic-gate } rd_err_e;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * ways that the event notification can take place:
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate typedef enum {
670Sstevel@tonic-gate 	RD_NOTIFY_BPT,		/* set break-point at address */
680Sstevel@tonic-gate 	RD_NOTIFY_AUTOBPT,	/* 4.x compat. not used in 5.x */
690Sstevel@tonic-gate 	RD_NOTIFY_SYSCALL	/* watch for syscall */
700Sstevel@tonic-gate } rd_notify_e;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * information on ways that the event notification can take place:
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate typedef struct rd_notify {
760Sstevel@tonic-gate 	rd_notify_e	type;
770Sstevel@tonic-gate 	union {
780Sstevel@tonic-gate 		psaddr_t	bptaddr;	/* break point address */
790Sstevel@tonic-gate 		long		syscallno;	/* system call id */
800Sstevel@tonic-gate 	} u;
810Sstevel@tonic-gate } rd_notify_t;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * information about event instance:
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate typedef enum {
870Sstevel@tonic-gate 	RD_NOSTATE = 0,		/* no state information */
880Sstevel@tonic-gate 	RD_CONSISTENT,		/* link-maps are stable */
890Sstevel@tonic-gate 	RD_ADD,			/* currently adding object to link-maps */
900Sstevel@tonic-gate 	RD_DELETE		/* currently deleteing object from link-maps */
910Sstevel@tonic-gate } rd_state_e;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate typedef struct rd_event_msg {
940Sstevel@tonic-gate 	rd_event_e	type;
950Sstevel@tonic-gate 	union {
960Sstevel@tonic-gate 		rd_state_e	state;	/* for DLACTIVITY */
970Sstevel@tonic-gate 	} u;
980Sstevel@tonic-gate } rd_event_msg_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * iteration over load objects
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate typedef struct rd_loadobj {
1050Sstevel@tonic-gate 	psaddr_t	rl_nameaddr;	/* address of the name in user space */
1060Sstevel@tonic-gate 	unsigned	rl_flags;
1070Sstevel@tonic-gate 	psaddr_t	rl_base;	/* base of address of code */
1080Sstevel@tonic-gate 	psaddr_t	rl_data_base;	/* base of address of data */
1090Sstevel@tonic-gate 	Lmid_t		rl_lmident;	/* ident of link map */
1100Sstevel@tonic-gate 	psaddr_t	rl_refnameaddr;	/* reference name of filter in user */
1110Sstevel@tonic-gate 					/* space.  If non null object is a */
1120Sstevel@tonic-gate 					/* filter. */
1130Sstevel@tonic-gate 	psaddr_t	rl_plt_base;	/* These fields are present for 4.x */
1140Sstevel@tonic-gate 	unsigned	rl_plt_size;	/* compatibility and are not */
1150Sstevel@tonic-gate 					/* currently used  in SunOS5.x */
1160Sstevel@tonic-gate 	psaddr_t	rl_bend;	/* end of image (text+data+bss) */
1170Sstevel@tonic-gate 	psaddr_t	rl_padstart;	/* start of padding */
1180Sstevel@tonic-gate 	psaddr_t	rl_padend;	/* end of image after padding */
1190Sstevel@tonic-gate 	psaddr_t	rl_dynamic;	/* points to the DYNAMIC section */
1200Sstevel@tonic-gate 					/* in the target process */
1210Sstevel@tonic-gate 	unsigned long	rl_tlsmodid;	/* module ID for TLS references */
1220Sstevel@tonic-gate } rd_loadobj_t;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate  * Values for rl_flags
1260Sstevel@tonic-gate  */
1270Sstevel@tonic-gate #define	RD_FLG_MEM_OBJECT	0x0001	/* Identifies this object as */
1280Sstevel@tonic-gate 					/* originating from a relocatable */
1290Sstevel@tonic-gate 					/* module which was dynamically */
1300Sstevel@tonic-gate 					/* loaded */
1310Sstevel@tonic-gate 
1322712Snn35248 /*
1332712Snn35248  * Commands for rd_ctl()
1342712Snn35248  */
1352712Snn35248 #define	RD_CTL_SET_HELPPATH	0x01	/* Set the path used to find helpers */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate typedef struct rd_agent rd_agent_t;
1380Sstevel@tonic-gate #ifdef __STDC__
1390Sstevel@tonic-gate typedef int rl_iter_f(const rd_loadobj_t *, void *);
1400Sstevel@tonic-gate #else
1410Sstevel@tonic-gate typedef int rl_iter_f();
1420Sstevel@tonic-gate #endif
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate  * PLT skipping
1470Sstevel@tonic-gate  */
1480Sstevel@tonic-gate typedef enum {
1490Sstevel@tonic-gate     RD_RESOLVE_NONE,		/* don't do anything special */
1500Sstevel@tonic-gate     RD_RESOLVE_STEP,		/* step 'pi_nstep' instructions */
1510Sstevel@tonic-gate     RD_RESOLVE_TARGET,		/* resolved target is in 'pi_target' */
1520Sstevel@tonic-gate     RD_RESOLVE_TARGET_STEP	/* put a bpt on target, then step nstep times */
1530Sstevel@tonic-gate } rd_skip_e;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate typedef struct rd_plt_info {
1570Sstevel@tonic-gate 	rd_skip_e	pi_skip_method;
1580Sstevel@tonic-gate 	long		pi_nstep;
1590Sstevel@tonic-gate 	psaddr_t	pi_target;
1600Sstevel@tonic-gate 	psaddr_t	pi_baddr;
1610Sstevel@tonic-gate 	unsigned int	pi_flags;
1620Sstevel@tonic-gate } rd_plt_info_t;
1630Sstevel@tonic-gate 
1642712Snn35248 
1652712Snn35248 /*
1660Sstevel@tonic-gate  * Values for pi_flags
1670Sstevel@tonic-gate  */
1680Sstevel@tonic-gate #define	RD_FLG_PI_PLTBOUND	0x0001	/* Indicates that the PLT */
1690Sstevel@tonic-gate 					/* has been bound - and that */
170376Swesolows 					/* pi_baddr will contain its */
1710Sstevel@tonic-gate 					/* destination address */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate struct	ps_prochandle;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * librtld_db.so entry points
1770Sstevel@tonic-gate  */
1780Sstevel@tonic-gate #ifdef __STDC__
1790Sstevel@tonic-gate extern void		rd_delete(rd_agent_t *);
180376Swesolows extern char		*rd_errstr(rd_err_e rderr);
1810Sstevel@tonic-gate extern rd_err_e		rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *);
1820Sstevel@tonic-gate extern rd_err_e		rd_event_enable(rd_agent_t *, int);
1830Sstevel@tonic-gate extern rd_err_e		rd_event_getmsg(rd_agent_t *, rd_event_msg_t *);
1840Sstevel@tonic-gate extern rd_err_e		rd_init(int);
1852712Snn35248 extern rd_err_e		rd_ctl(int, void *);
1860Sstevel@tonic-gate extern rd_err_e		rd_loadobj_iter(rd_agent_t *, rl_iter_f *,
1870Sstevel@tonic-gate 				void *);
1880Sstevel@tonic-gate extern void		rd_log(const int);
189376Swesolows extern rd_agent_t	*rd_new(struct ps_prochandle *);
1900Sstevel@tonic-gate extern rd_err_e		rd_objpad_enable(struct rd_agent *, size_t);
1910Sstevel@tonic-gate extern rd_err_e		rd_plt_resolution(rd_agent_t *, psaddr_t, lwpid_t,
1920Sstevel@tonic-gate 				psaddr_t, rd_plt_info_t *);
193*6830Sedp extern rd_err_e		rd_get_dyns(rd_agent_t *, psaddr_t, void **, size_t *);
1940Sstevel@tonic-gate extern rd_err_e		rd_reset(struct rd_agent *);
195*6830Sedp #else /* !__STDC__ */
1960Sstevel@tonic-gate extern void		rd_delete();
197376Swesolows extern char		*rd_errstr();
1980Sstevel@tonic-gate extern rd_err_e		rd_event_addr();
1990Sstevel@tonic-gate extern rd_err_e		rd_event_enable();
2000Sstevel@tonic-gate extern rd_err_e		rd_event_getmsg();
2010Sstevel@tonic-gate extern rd_err_e		rd_init();
2022712Snn35248 extern rd_err_e		rd_ctl();
2030Sstevel@tonic-gate extern rd_err_e		rd_loadobj_iter();
2040Sstevel@tonic-gate extern void		rd_log();
205376Swesolows extern rd_agent_t	*rd_new();
2060Sstevel@tonic-gate extern rd_err_e		rd_objpad_enable();
2070Sstevel@tonic-gate extern rd_err_e		rd_plt_resolution();
208*6830Sedp extern rd_err_e		rd_get_dyns();
2090Sstevel@tonic-gate extern rd_err_e		rd_reset();
210*6830Sedp #endif /* !__STDC__ */
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #ifdef	__cplusplus
2130Sstevel@tonic-gate }
2140Sstevel@tonic-gate #endif
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate #endif	/* _RTLD_DB_H */
217