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 5*9acbbeafSnn35248 * Common Development and Distribution License (the "License"). 6*9acbbeafSnn35248 * 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*9acbbeafSnn35248 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23159cf8a6Swesolows * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _RTLD_DB_H 277c478bd9Sstevel@tonic-gate #define _RTLD_DB_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/lwp.h> 38*9acbbeafSnn35248 #include <sys/elf.h> 397c478bd9Sstevel@tonic-gate #include <link.h> 407c478bd9Sstevel@tonic-gate #include <proc_service.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * librtld_db interface versions 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate #define RD_VERSION1 1 477c478bd9Sstevel@tonic-gate #define RD_VERSION2 2 487c478bd9Sstevel@tonic-gate #define RD_VERSION3 3 497c478bd9Sstevel@tonic-gate #define RD_VERSION4 4 507c478bd9Sstevel@tonic-gate #define RD_VERSION RD_VERSION4 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate typedef enum { 537c478bd9Sstevel@tonic-gate RD_ERR, /* generic */ 547c478bd9Sstevel@tonic-gate RD_OK, /* generic "call" succeeded */ 557c478bd9Sstevel@tonic-gate RD_NOCAPAB, /* capability not available */ 567c478bd9Sstevel@tonic-gate RD_DBERR, /* import service failed */ 577c478bd9Sstevel@tonic-gate RD_NOBASE, /* 5.x: aux tag AT_BASE not found */ 587c478bd9Sstevel@tonic-gate RD_NODYNAM, /* symbol 'DYNAMIC' not found */ 597c478bd9Sstevel@tonic-gate RD_NOMAPS /* link-maps are not yet available */ 607c478bd9Sstevel@tonic-gate } rd_err_e; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * ways that the event notification can take place: 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate typedef enum { 677c478bd9Sstevel@tonic-gate RD_NOTIFY_BPT, /* set break-point at address */ 687c478bd9Sstevel@tonic-gate RD_NOTIFY_AUTOBPT, /* 4.x compat. not used in 5.x */ 697c478bd9Sstevel@tonic-gate RD_NOTIFY_SYSCALL /* watch for syscall */ 707c478bd9Sstevel@tonic-gate } rd_notify_e; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * information on ways that the event notification can take place: 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate typedef struct rd_notify { 767c478bd9Sstevel@tonic-gate rd_notify_e type; 777c478bd9Sstevel@tonic-gate union { 787c478bd9Sstevel@tonic-gate psaddr_t bptaddr; /* break point address */ 797c478bd9Sstevel@tonic-gate long syscallno; /* system call id */ 807c478bd9Sstevel@tonic-gate } u; 817c478bd9Sstevel@tonic-gate } rd_notify_t; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * information about event instance: 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate typedef enum { 877c478bd9Sstevel@tonic-gate RD_NOSTATE = 0, /* no state information */ 887c478bd9Sstevel@tonic-gate RD_CONSISTENT, /* link-maps are stable */ 897c478bd9Sstevel@tonic-gate RD_ADD, /* currently adding object to link-maps */ 907c478bd9Sstevel@tonic-gate RD_DELETE /* currently deleteing object from link-maps */ 917c478bd9Sstevel@tonic-gate } rd_state_e; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate typedef struct rd_event_msg { 947c478bd9Sstevel@tonic-gate rd_event_e type; 957c478bd9Sstevel@tonic-gate union { 967c478bd9Sstevel@tonic-gate rd_state_e state; /* for DLACTIVITY */ 977c478bd9Sstevel@tonic-gate } u; 987c478bd9Sstevel@tonic-gate } rd_event_msg_t; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 1027c478bd9Sstevel@tonic-gate * iteration over load objects 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate typedef struct rd_loadobj { 1057c478bd9Sstevel@tonic-gate psaddr_t rl_nameaddr; /* address of the name in user space */ 1067c478bd9Sstevel@tonic-gate unsigned rl_flags; 1077c478bd9Sstevel@tonic-gate psaddr_t rl_base; /* base of address of code */ 1087c478bd9Sstevel@tonic-gate psaddr_t rl_data_base; /* base of address of data */ 1097c478bd9Sstevel@tonic-gate Lmid_t rl_lmident; /* ident of link map */ 1107c478bd9Sstevel@tonic-gate psaddr_t rl_refnameaddr; /* reference name of filter in user */ 1117c478bd9Sstevel@tonic-gate /* space. If non null object is a */ 1127c478bd9Sstevel@tonic-gate /* filter. */ 1137c478bd9Sstevel@tonic-gate psaddr_t rl_plt_base; /* These fields are present for 4.x */ 1147c478bd9Sstevel@tonic-gate unsigned rl_plt_size; /* compatibility and are not */ 1157c478bd9Sstevel@tonic-gate /* currently used in SunOS5.x */ 1167c478bd9Sstevel@tonic-gate psaddr_t rl_bend; /* end of image (text+data+bss) */ 1177c478bd9Sstevel@tonic-gate psaddr_t rl_padstart; /* start of padding */ 1187c478bd9Sstevel@tonic-gate psaddr_t rl_padend; /* end of image after padding */ 1197c478bd9Sstevel@tonic-gate psaddr_t rl_dynamic; /* points to the DYNAMIC section */ 1207c478bd9Sstevel@tonic-gate /* in the target process */ 1217c478bd9Sstevel@tonic-gate unsigned long rl_tlsmodid; /* module ID for TLS references */ 1227c478bd9Sstevel@tonic-gate } rd_loadobj_t; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * Values for rl_flags 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate #define RD_FLG_MEM_OBJECT 0x0001 /* Identifies this object as */ 1287c478bd9Sstevel@tonic-gate /* originating from a relocatable */ 1297c478bd9Sstevel@tonic-gate /* module which was dynamically */ 1307c478bd9Sstevel@tonic-gate /* loaded */ 1317c478bd9Sstevel@tonic-gate 132*9acbbeafSnn35248 /* 133*9acbbeafSnn35248 * Commands for rd_ctl() 134*9acbbeafSnn35248 */ 135*9acbbeafSnn35248 #define RD_CTL_SET_HELPPATH 0x01 /* Set the path used to find helpers */ 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate typedef struct rd_agent rd_agent_t; 1387c478bd9Sstevel@tonic-gate #ifdef __STDC__ 1397c478bd9Sstevel@tonic-gate typedef int rl_iter_f(const rd_loadobj_t *, void *); 1407c478bd9Sstevel@tonic-gate #else 1417c478bd9Sstevel@tonic-gate typedef int rl_iter_f(); 1427c478bd9Sstevel@tonic-gate #endif 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * PLT skipping 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate typedef enum { 1497c478bd9Sstevel@tonic-gate RD_RESOLVE_NONE, /* don't do anything special */ 1507c478bd9Sstevel@tonic-gate RD_RESOLVE_STEP, /* step 'pi_nstep' instructions */ 1517c478bd9Sstevel@tonic-gate RD_RESOLVE_TARGET, /* resolved target is in 'pi_target' */ 1527c478bd9Sstevel@tonic-gate RD_RESOLVE_TARGET_STEP /* put a bpt on target, then step nstep times */ 1537c478bd9Sstevel@tonic-gate } rd_skip_e; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate typedef struct rd_plt_info { 1577c478bd9Sstevel@tonic-gate rd_skip_e pi_skip_method; 1587c478bd9Sstevel@tonic-gate long pi_nstep; 1597c478bd9Sstevel@tonic-gate psaddr_t pi_target; 1607c478bd9Sstevel@tonic-gate psaddr_t pi_baddr; 1617c478bd9Sstevel@tonic-gate unsigned int pi_flags; 1627c478bd9Sstevel@tonic-gate } rd_plt_info_t; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 165*9acbbeafSnn35248 * State kept for brand helper libraries 166*9acbbeafSnn35248 */ 167*9acbbeafSnn35248 typedef struct rd_helper_ops { 168*9acbbeafSnn35248 void *(*rho_init)(struct ps_prochandle *); 169*9acbbeafSnn35248 int (*rho_loadobj_iter)(struct ps_prochandle *, rl_iter_f *cb, 170*9acbbeafSnn35248 void *client_data, void *helper_data); 171*9acbbeafSnn35248 void (*rho_fix_phdrs)(struct rd_agent *, Elf32_Dyn *, size_t, 172*9acbbeafSnn35248 psaddr_t addr); 173*9acbbeafSnn35248 } rd_helper_ops_t; 174*9acbbeafSnn35248 175*9acbbeafSnn35248 typedef struct rd_helper { 176*9acbbeafSnn35248 rd_helper_ops_t *rh_ops; 177*9acbbeafSnn35248 void *rh_data; 178*9acbbeafSnn35248 void *rh_dlhandle; 179*9acbbeafSnn35248 } rd_helper_t; 180*9acbbeafSnn35248 181*9acbbeafSnn35248 /* 182*9acbbeafSnn35248 * Brand helper libraries must name their ops vector using this macro. 183*9acbbeafSnn35248 */ 184*9acbbeafSnn35248 #define RTLD_DB_BRAND_OPS rtld_db_brand_ops 185*9acbbeafSnn35248 186*9acbbeafSnn35248 /* 1877c478bd9Sstevel@tonic-gate * Values for pi_flags 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate #define RD_FLG_PI_PLTBOUND 0x0001 /* Indicates that the PLT */ 1907c478bd9Sstevel@tonic-gate /* has been bound - and that */ 191159cf8a6Swesolows /* pi_baddr will contain its */ 1927c478bd9Sstevel@tonic-gate /* destination address */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate struct ps_prochandle; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * librtld_db.so entry points 1987c478bd9Sstevel@tonic-gate */ 1997c478bd9Sstevel@tonic-gate #ifdef __STDC__ 2007c478bd9Sstevel@tonic-gate extern void rd_delete(rd_agent_t *); 2017c478bd9Sstevel@tonic-gate extern char *rd_errstr(rd_err_e rderr); 2027c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *); 2037c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_enable(rd_agent_t *, int); 2047c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_getmsg(rd_agent_t *, rd_event_msg_t *); 2057c478bd9Sstevel@tonic-gate extern rd_err_e rd_init(int); 206*9acbbeafSnn35248 extern rd_err_e rd_ctl(int, void *); 2077c478bd9Sstevel@tonic-gate extern rd_err_e rd_loadobj_iter(rd_agent_t *, rl_iter_f *, 2087c478bd9Sstevel@tonic-gate void *); 2097c478bd9Sstevel@tonic-gate extern void rd_log(const int); 2107c478bd9Sstevel@tonic-gate extern rd_agent_t *rd_new(struct ps_prochandle *); 2117c478bd9Sstevel@tonic-gate extern rd_err_e rd_objpad_enable(struct rd_agent *, size_t); 2127c478bd9Sstevel@tonic-gate extern rd_err_e rd_plt_resolution(rd_agent_t *, psaddr_t, lwpid_t, 2137c478bd9Sstevel@tonic-gate psaddr_t, rd_plt_info_t *); 214*9acbbeafSnn35248 extern void rd_fix_phdrs(struct rd_agent *, Elf32_Dyn *, 215*9acbbeafSnn35248 size_t, uintptr_t); 2167c478bd9Sstevel@tonic-gate extern rd_err_e rd_reset(struct rd_agent *); 2177c478bd9Sstevel@tonic-gate #else 2187c478bd9Sstevel@tonic-gate extern void rd_delete(); 2197c478bd9Sstevel@tonic-gate extern char *rd_errstr(); 2207c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_addr(); 2217c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_enable(); 2227c478bd9Sstevel@tonic-gate extern rd_err_e rd_event_getmsg(); 2237c478bd9Sstevel@tonic-gate extern rd_err_e rd_init(); 224*9acbbeafSnn35248 extern rd_err_e rd_ctl(); 2257c478bd9Sstevel@tonic-gate extern rd_err_e rd_loadobj_iter(); 2267c478bd9Sstevel@tonic-gate extern void rd_log(); 2277c478bd9Sstevel@tonic-gate extern rd_agent_t *rd_new(); 2287c478bd9Sstevel@tonic-gate extern rd_err_e rd_objpad_enable(); 2297c478bd9Sstevel@tonic-gate extern rd_err_e rd_plt_resolution(); 230*9acbbeafSnn35248 extern void rd_fix_phdrs(); 2317c478bd9Sstevel@tonic-gate extern rd_err_e rd_reset(); 2327c478bd9Sstevel@tonic-gate #endif 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate #endif 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate #endif /* _RTLD_DB_H */ 239