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*12877SRod.Evans@Sun.COM * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _LINK_H 260Sstevel@tonic-gate #define _LINK_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/link.h> 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _ASM 310Sstevel@tonic-gate #include <libelf.h> 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <dlfcn.h> 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifndef _ASM 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * ld support library calls 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate #ifdef __STDC__ 450Sstevel@tonic-gate extern uint_t ld_version(uint_t); 462978Srie extern void ld_input_done(uint_t *); 472978Srie 480Sstevel@tonic-gate extern void ld_start(const char *, const Elf32_Half, const char *); 490Sstevel@tonic-gate extern void ld_atexit(int); 502978Srie extern void ld_open(const char **, const char **, int *, int, Elf **, 512978Srie Elf *, size_t, const Elf_Kind); 520Sstevel@tonic-gate extern void ld_file(const char *, const Elf_Kind, int, Elf *); 530Sstevel@tonic-gate extern void ld_input_section(const char *, Elf32_Shdr **, Elf32_Word, 540Sstevel@tonic-gate Elf_Data *, Elf *, uint_t *); 550Sstevel@tonic-gate extern void ld_section(const char *, Elf32_Shdr *, Elf32_Word, 560Sstevel@tonic-gate Elf_Data *, Elf *); 570Sstevel@tonic-gate 580Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE) 590Sstevel@tonic-gate extern void ld_start64(const char *, const Elf64_Half, const char *); 600Sstevel@tonic-gate extern void ld_atexit64(int); 612978Srie extern void ld_open64(const char **, const char **, int *, int, Elf **, 622978Srie Elf *, size_t, const Elf_Kind); 630Sstevel@tonic-gate extern void ld_file64(const char *, const Elf_Kind, int, Elf *); 640Sstevel@tonic-gate extern void ld_input_section64(const char *, Elf64_Shdr **, Elf64_Word, 650Sstevel@tonic-gate Elf_Data *, Elf *, uint_t *); 660Sstevel@tonic-gate extern void ld_section64(const char *, Elf64_Shdr *, Elf64_Word, 670Sstevel@tonic-gate Elf_Data *, Elf *); 680Sstevel@tonic-gate 690Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */ 700Sstevel@tonic-gate #else 710Sstevel@tonic-gate extern void ld_version(); 722978Srie extern void ld_input_done(); 732978Srie 740Sstevel@tonic-gate extern void ld_start(); 750Sstevel@tonic-gate extern void ld_atexit(); 762978Srie extern void ld_open(); 770Sstevel@tonic-gate extern void ld_file(); 780Sstevel@tonic-gate extern void ld_input_section(); 790Sstevel@tonic-gate extern void ld_section(); 800Sstevel@tonic-gate 810Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE) 820Sstevel@tonic-gate extern void ld_start64(); 830Sstevel@tonic-gate extern void ld_atexit64(); 842978Srie extern void ld_open64(); 850Sstevel@tonic-gate extern void ld_file64(); 862978Srie extern void ld_input_section64(); 870Sstevel@tonic-gate extern void ld_section64(); 880Sstevel@tonic-gate 890Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */ 900Sstevel@tonic-gate #endif /* __STDC__ */ 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* 932978Srie * ld_version() version values. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate #define LD_SUP_VNONE 0 960Sstevel@tonic-gate #define LD_SUP_VERSION1 1 970Sstevel@tonic-gate #define LD_SUP_VERSION2 2 982978Srie #define LD_SUP_VERSION3 3 992978Srie #define LD_SUP_VCURRENT LD_SUP_VERSION3 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1022978Srie * Flags passed to ld support calls. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate #define LD_SUP_DERIVED 0x1 /* derived filename */ 1050Sstevel@tonic-gate #define LD_SUP_INHERITED 0x2 /* file inherited from .so DT_NEEDED */ 1060Sstevel@tonic-gate #define LD_SUP_EXTRACTED 0x4 /* file extracted from archive */ 1070Sstevel@tonic-gate #endif 1080Sstevel@tonic-gate 1092978Srie /* 1102978Srie * Runtime link-map identifiers. 1112978Srie */ 1120Sstevel@tonic-gate #define LM_ID_BASE 0x00 1130Sstevel@tonic-gate #define LM_ID_LDSO 0x01 1146830Sedp #define LM_ID_NUM 2 1152712Snn35248 1166830Sedp #define LM_ID_BRAND 0xfd /* brand emulation linkmap objs */ 1176830Sedp #define LM_ID_NONE 0xfe /* no link map specified */ 1180Sstevel@tonic-gate #define LM_ID_NEWLM 0xff /* create a new link-map */ 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* 1212978Srie * Runtime Link-Edit Auditing. 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate #define LAV_NONE 0 1240Sstevel@tonic-gate #define LAV_VERSION1 1 1250Sstevel@tonic-gate #define LAV_VERSION2 2 1260Sstevel@tonic-gate #define LAV_VERSION3 3 1274679Srie #define LAV_VERSION4 4 128*12877SRod.Evans@Sun.COM #define LAV_VERSION5 5 129*12877SRod.Evans@Sun.COM #define LAV_CURRENT LAV_VERSION5 130*12877SRod.Evans@Sun.COM #define LAV_NUM 6 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Flags that can be or'd into the la_objopen() return code 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate #define LA_FLG_BINDTO 0x0001 /* audit symbinds TO this object */ 1360Sstevel@tonic-gate #define LA_FLG_BINDFROM 0x0002 /* audit symbinding FROM this object */ 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate /* 1390Sstevel@tonic-gate * Flags that can be or'd into the 'flags' argument of la_symbind() 1400Sstevel@tonic-gate */ 1410Sstevel@tonic-gate #define LA_SYMB_NOPLTENTER 0x0001 /* disable pltenter for this symbol */ 1420Sstevel@tonic-gate #define LA_SYMB_NOPLTEXIT 0x0002 /* disable pltexit for this symbol */ 1430Sstevel@tonic-gate #define LA_SYMB_STRUCTCALL 0x0004 /* this function call passes a */ 1440Sstevel@tonic-gate /* structure as it's return code */ 1450Sstevel@tonic-gate #define LA_SYMB_DLSYM 0x0008 /* this symbol bindings is due to */ 1460Sstevel@tonic-gate /* a call to dlsym() */ 1470Sstevel@tonic-gate #define LA_SYMB_ALTVALUE 0x0010 /* alternate symbol binding returned */ 1480Sstevel@tonic-gate /* by la_symbind() */ 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Flags that describe the object passed to la_objsearch() 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate #define LA_SER_ORIG 0x001 /* original (needed) name */ 1540Sstevel@tonic-gate #define LA_SER_LIBPATH 0x002 /* LD_LIBRARY_PATH entry prepended */ 1550Sstevel@tonic-gate #define LA_SER_RUNPATH 0x004 /* runpath entry prepended */ 1560Sstevel@tonic-gate #define LA_SER_CONFIG 0x008 /* configuration entry prepended */ 1570Sstevel@tonic-gate #define LA_SER_DEFAULT 0x040 /* default path prepended */ 1580Sstevel@tonic-gate #define LA_SER_SECURE 0x080 /* default (secure) path prepended */ 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define LA_SER_MASK 0xfff /* mask of known flags */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* 1630Sstevel@tonic-gate * Flags that describe the la_activity() 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate #define LA_ACT_CONSISTENT 0x00 /* add/deletion of objects complete */ 1660Sstevel@tonic-gate #define LA_ACT_ADD 0x01 /* objects being added */ 1670Sstevel@tonic-gate #define LA_ACT_DELETE 0x02 /* objects being deleted */ 168*12877SRod.Evans@Sun.COM #define LA_ACT_MAX 3 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #ifndef _KERNEL 1720Sstevel@tonic-gate #ifndef _ASM 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #if defined(_LP64) 1750Sstevel@tonic-gate typedef long lagreg_t; 1760Sstevel@tonic-gate #else 1770Sstevel@tonic-gate typedef int lagreg_t; 1780Sstevel@tonic-gate #endif 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate struct _la_sparc_regs { 1810Sstevel@tonic-gate lagreg_t lr_rego0; 1820Sstevel@tonic-gate lagreg_t lr_rego1; 1830Sstevel@tonic-gate lagreg_t lr_rego2; 1840Sstevel@tonic-gate lagreg_t lr_rego3; 1850Sstevel@tonic-gate lagreg_t lr_rego4; 1860Sstevel@tonic-gate lagreg_t lr_rego5; 1870Sstevel@tonic-gate lagreg_t lr_rego6; 1880Sstevel@tonic-gate lagreg_t lr_rego7; 1890Sstevel@tonic-gate }; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate #if defined(_LP64) 1920Sstevel@tonic-gate typedef struct _la_sparc_regs La_sparcv9_regs; 1930Sstevel@tonic-gate typedef struct { 1940Sstevel@tonic-gate lagreg_t lr_rsp; 1950Sstevel@tonic-gate lagreg_t lr_rbp; 1960Sstevel@tonic-gate lagreg_t lr_rdi; /* arg1 */ 1970Sstevel@tonic-gate lagreg_t lr_rsi; /* arg2 */ 1980Sstevel@tonic-gate lagreg_t lr_rdx; /* arg3 */ 1990Sstevel@tonic-gate lagreg_t lr_rcx; /* arg4 */ 2000Sstevel@tonic-gate lagreg_t lr_r8; /* arg5 */ 2010Sstevel@tonic-gate lagreg_t lr_r9; /* arg6 */ 2020Sstevel@tonic-gate } La_amd64_regs; 2030Sstevel@tonic-gate #else 2040Sstevel@tonic-gate typedef struct _la_sparc_regs La_sparcv8_regs; 2050Sstevel@tonic-gate typedef struct { 2060Sstevel@tonic-gate lagreg_t lr_esp; 2070Sstevel@tonic-gate lagreg_t lr_ebp; 2080Sstevel@tonic-gate } La_i86_regs; 2090Sstevel@tonic-gate #endif 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #if !defined(_SYS_INT_TYPES_H) 2120Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx) 2130Sstevel@tonic-gate typedef unsigned long uintptr_t; 2140Sstevel@tonic-gate #else 2150Sstevel@tonic-gate typedef unsigned int uintptr_t; 2160Sstevel@tonic-gate #endif 2170Sstevel@tonic-gate #endif 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate #ifdef __STDC__ 2210Sstevel@tonic-gate extern uint_t la_version(uint_t); 2220Sstevel@tonic-gate extern void la_activity(uintptr_t *, uint_t); 2230Sstevel@tonic-gate extern void la_preinit(uintptr_t *); 2240Sstevel@tonic-gate extern char *la_objsearch(const char *, uintptr_t *, uint_t); 2250Sstevel@tonic-gate extern uint_t la_objopen(Link_map *, Lmid_t, uintptr_t *); 2260Sstevel@tonic-gate extern uint_t la_objclose(uintptr_t *); 2270Sstevel@tonic-gate extern int la_objfilter(uintptr_t *, const char *, uintptr_t *, 2280Sstevel@tonic-gate uint_t); 2290Sstevel@tonic-gate #if defined(_LP64) 2300Sstevel@tonic-gate extern uintptr_t la_amd64_pltenter(Elf64_Sym *, uint_t, uintptr_t *, 2310Sstevel@tonic-gate uintptr_t *, La_amd64_regs *, uint_t *, 2320Sstevel@tonic-gate const char *); 2330Sstevel@tonic-gate extern uintptr_t la_symbind64(Elf64_Sym *, uint_t, uintptr_t *, 2340Sstevel@tonic-gate uintptr_t *, uint_t *, const char *); 2350Sstevel@tonic-gate extern uintptr_t la_sparcv9_pltenter(Elf64_Sym *, uint_t, uintptr_t *, 2360Sstevel@tonic-gate uintptr_t *, La_sparcv9_regs *, uint_t *, 2370Sstevel@tonic-gate const char *); 2380Sstevel@tonic-gate extern uintptr_t la_pltexit64(Elf64_Sym *, uint_t, uintptr_t *, 2390Sstevel@tonic-gate uintptr_t *, uintptr_t, const char *); 2400Sstevel@tonic-gate #else /* !defined(_LP64) */ 2410Sstevel@tonic-gate extern uintptr_t la_symbind32(Elf32_Sym *, uint_t, uintptr_t *, 2420Sstevel@tonic-gate uintptr_t *, uint_t *); 2430Sstevel@tonic-gate extern uintptr_t la_sparcv8_pltenter(Elf32_Sym *, uint_t, uintptr_t *, 2440Sstevel@tonic-gate uintptr_t *, La_sparcv8_regs *, uint_t *); 2450Sstevel@tonic-gate extern uintptr_t la_i86_pltenter(Elf32_Sym *, uint_t, uintptr_t *, 2460Sstevel@tonic-gate uintptr_t *, La_i86_regs *, uint_t *); 2470Sstevel@tonic-gate extern uintptr_t la_pltexit(Elf32_Sym *, uint_t, uintptr_t *, 2480Sstevel@tonic-gate uintptr_t *, uintptr_t); 2490Sstevel@tonic-gate #endif /* _LP64 */ 2500Sstevel@tonic-gate #else /* __STDC__ */ 2510Sstevel@tonic-gate extern uint_t la_version(); 2520Sstevel@tonic-gate extern void la_preinit(); 2530Sstevel@tonic-gate extern uint_t la_objopen(); 2540Sstevel@tonic-gate extern uint_t la_objclose(); 2550Sstevel@tonic-gate extern int la_objfilter(); 2560Sstevel@tonic-gate #if defined(_LP64) 2570Sstevel@tonic-gate extern uintptr_t la_sparcv9_pltenter(); 2580Sstevel@tonic-gate extern uintptr_t la_pltexit64(); 2590Sstevel@tonic-gate extern uintptr_t la_symbind64(); 2600Sstevel@tonic-gate #else /* _ILP32 */ 2610Sstevel@tonic-gate extern uintptr_t la_sparcv8_pltenter(); 2620Sstevel@tonic-gate extern uintptr_t la_i86_pltenter(); 2630Sstevel@tonic-gate extern uintptr_t la_pltexit(); 2640Sstevel@tonic-gate extern uintptr_t la_symbind32(); 2650Sstevel@tonic-gate #endif /* _LP64 */ 2660Sstevel@tonic-gate #endif /* __STDC__ */ 2670Sstevel@tonic-gate 26811827SRod.Evans@Sun.COM #ifdef __STDC__ 26911690SAli.Bahrami@Sun.COM /* 27011690SAli.Bahrami@Sun.COM * The ElfW() macro is a GNU/Linux feature, provided as support for 27111690SAli.Bahrami@Sun.COM * the dl_phdr_info structure used by dl_phdr_iterate(), which also 27211690SAli.Bahrami@Sun.COM * originated under Linux. Given an ELF data type, without the ElfXX_ 27311690SAli.Bahrami@Sun.COM * prefix, it supplies the appropriate prefix (Elf32_ or Elf64_) for 27411690SAli.Bahrami@Sun.COM * the ELFCLASS of the code being compiled. 27511690SAli.Bahrami@Sun.COM * 27611690SAli.Bahrami@Sun.COM * Note that ElfW() is not suitable in situations in which the ELFCLASS 27711690SAli.Bahrami@Sun.COM * of the code being compiled does not match that of the objects that 27811690SAli.Bahrami@Sun.COM * code is intended to operate on (e.g. a 32-bit link-editor building 27911690SAli.Bahrami@Sun.COM * a 64-bit object). The macros defined in <sys/machelf.h> are 28011690SAli.Bahrami@Sun.COM * recommended in such cases. 28111690SAli.Bahrami@Sun.COM */ 28211690SAli.Bahrami@Sun.COM #ifdef _LP64 28311690SAli.Bahrami@Sun.COM #define ElfW(type) Elf64_ ## type 28411690SAli.Bahrami@Sun.COM #else 28511690SAli.Bahrami@Sun.COM #define ElfW(type) Elf32_ ## type 28611690SAli.Bahrami@Sun.COM #endif 28711690SAli.Bahrami@Sun.COM 28811690SAli.Bahrami@Sun.COM /* 28911690SAli.Bahrami@Sun.COM * The callback function to dl_interate_phdr() receives a pointer 29011690SAli.Bahrami@Sun.COM * to a structure of this type. 29111690SAli.Bahrami@Sun.COM * 29211690SAli.Bahrami@Sun.COM * dlpi_addr is defined such that the address of any segment in 29311690SAli.Bahrami@Sun.COM * the program header array can be calculated as: 29411690SAli.Bahrami@Sun.COM * 29511690SAli.Bahrami@Sun.COM * addr == info->dlpi_addr + info->dlpi_phdr[x].p_vaddr; 29611690SAli.Bahrami@Sun.COM * 29711690SAli.Bahrami@Sun.COM * It is therefore 0 for ET_EXEC objects, and the base address at 29811690SAli.Bahrami@Sun.COM * which the object is mapped otherwise. 29911690SAli.Bahrami@Sun.COM */ 30011690SAli.Bahrami@Sun.COM struct dl_phdr_info { 30111690SAli.Bahrami@Sun.COM ElfW(Addr) dlpi_addr; /* Base address of object */ 30211690SAli.Bahrami@Sun.COM const char *dlpi_name; /* Null-terminated obj name */ 30311690SAli.Bahrami@Sun.COM const ElfW(Phdr) *dlpi_phdr; /* Ptr to ELF program hdr arr */ 30411690SAli.Bahrami@Sun.COM ElfW(Half) dlpi_phnum; /* # of items in dlpi_phdr[] */ 30511690SAli.Bahrami@Sun.COM 30611690SAli.Bahrami@Sun.COM /* 30711690SAli.Bahrami@Sun.COM * Note: Following members were introduced after the first version 30811690SAli.Bahrami@Sun.COM * of this structure was available. The dl_iterate_phdr() callback 30911690SAli.Bahrami@Sun.COM * function is passed a 'size' argument giving the size of the info 31011690SAli.Bahrami@Sun.COM * structure, and must compare that size to the offset of these fields 31111690SAli.Bahrami@Sun.COM * before accessing them to ensure that they are present. 31211690SAli.Bahrami@Sun.COM */ 31311690SAli.Bahrami@Sun.COM 31411690SAli.Bahrami@Sun.COM /* Incremented when a new object is mapped into the process */ 31511690SAli.Bahrami@Sun.COM u_longlong_t dlpi_adds; 31611690SAli.Bahrami@Sun.COM /* Incremented when an object is unmapped from the process */ 31711690SAli.Bahrami@Sun.COM u_longlong_t dlpi_subs; 31811690SAli.Bahrami@Sun.COM }; 31911690SAli.Bahrami@Sun.COM 32011690SAli.Bahrami@Sun.COM extern int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), 32111690SAli.Bahrami@Sun.COM void *); 32211827SRod.Evans@Sun.COM #endif /* __STDC__ */ 32311690SAli.Bahrami@Sun.COM 32411690SAli.Bahrami@Sun.COM #endif /* _ASM */ 3250Sstevel@tonic-gate #endif /* _KERNEL */ 3260Sstevel@tonic-gate 32711690SAli.Bahrami@Sun.COM 3280Sstevel@tonic-gate #ifdef __cplusplus 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate #endif 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate #endif /* _LINK_H */ 333