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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * i386 specific setup routine - relocate ld.so's symbols, setup its 340Sstevel@tonic-gate * environment, map in loadable sections of the executable. 350Sstevel@tonic-gate * 360Sstevel@tonic-gate * Takes base address ld.so was loaded at, address of ld.so's dynamic 370Sstevel@tonic-gate * structure, address of process environment pointers, address of auxiliary 380Sstevel@tonic-gate * vector and * argv[0] (process name). 390Sstevel@tonic-gate * If errors occur, send process signal - otherwise 400Sstevel@tonic-gate * return executable's entry point to the bootstrap routine. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate #include "_synonyms.h" 430Sstevel@tonic-gate 440Sstevel@tonic-gate #include <signal.h> 450Sstevel@tonic-gate #include <stdlib.h> 460Sstevel@tonic-gate #include <sys/auxv.h> 470Sstevel@tonic-gate #include <sys/types.h> 480Sstevel@tonic-gate #include <sys/stat.h> 490Sstevel@tonic-gate #include <link.h> 500Sstevel@tonic-gate #include <dlfcn.h> 510Sstevel@tonic-gate #include "_rtld.h" 520Sstevel@tonic-gate #include "_audit.h" 530Sstevel@tonic-gate #include "msg.h" 540Sstevel@tonic-gate #include "debug.h" 550Sstevel@tonic-gate 560Sstevel@tonic-gate extern int _end; 570Sstevel@tonic-gate extern int _etext; 580Sstevel@tonic-gate 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * Stub routine to prevent atexit_init() being extracted from libc_pic.a on 620Sstevel@tonic-gate * i386 and added to ld.so.1. We don't need it. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate void 650Sstevel@tonic-gate atexit_init() 660Sstevel@tonic-gate { 670Sstevel@tonic-gate } 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* VARARGS */ 700Sstevel@tonic-gate unsigned long 710Sstevel@tonic-gate _setup(Boot * ebp, Dyn * ld_dyn) 720Sstevel@tonic-gate { 730Sstevel@tonic-gate unsigned long reladdr, relcount, ld_base = 0; 740Sstevel@tonic-gate unsigned long relent = 0; 750Sstevel@tonic-gate unsigned long strtab, soname, interp_base = 0; 760Sstevel@tonic-gate char *_rt_name, **_envp, **_argv; 770Sstevel@tonic-gate int _syspagsz = 0, fd = -1, dz_fd = FD_UNAVAIL; 780Sstevel@tonic-gate uint_t _flags = 0, hwcap_1 = 0; 790Sstevel@tonic-gate Dyn * dyn_ptr; 800Sstevel@tonic-gate Phdr * phdr = 0; 810Sstevel@tonic-gate Rt_map * lmp; 820Sstevel@tonic-gate auxv_t *auxv, *_auxv; 830Sstevel@tonic-gate uid_t uid = -1, euid = -1; 840Sstevel@tonic-gate gid_t gid = -1, egid = -1; 850Sstevel@tonic-gate char *_platform = 0, *_execname = 0; 860Sstevel@tonic-gate int auxflags = -1; 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Scan the bootstrap structure to pick up the basics. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate for (; ebp->eb_tag != EB_NULL; ebp++) 910Sstevel@tonic-gate switch (ebp->eb_tag) { 920Sstevel@tonic-gate case EB_LDSO_BASE: 930Sstevel@tonic-gate ld_base = (unsigned long)ebp->eb_un.eb_val; 940Sstevel@tonic-gate break; 950Sstevel@tonic-gate case EB_ARGV: 960Sstevel@tonic-gate _argv = (char **)ebp->eb_un.eb_ptr; 970Sstevel@tonic-gate break; 980Sstevel@tonic-gate case EB_ENVP: 990Sstevel@tonic-gate _envp = (char **)ebp->eb_un.eb_ptr; 1000Sstevel@tonic-gate break; 1010Sstevel@tonic-gate case EB_AUXV: 1020Sstevel@tonic-gate _auxv = (auxv_t *)ebp->eb_un.eb_ptr; 1030Sstevel@tonic-gate break; 1040Sstevel@tonic-gate case EB_DEVZERO: 1050Sstevel@tonic-gate dz_fd = (int)ebp->eb_un.eb_val; 1060Sstevel@tonic-gate break; 1070Sstevel@tonic-gate case EB_PAGESIZE: 1080Sstevel@tonic-gate _syspagsz = (int)ebp->eb_un.eb_val; 1090Sstevel@tonic-gate break; 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * Search the aux. vector for the information passed by exec. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate for (auxv = _auxv; auxv->a_type != AT_NULL; auxv++) { 1160Sstevel@tonic-gate switch (auxv->a_type) { 1170Sstevel@tonic-gate case AT_EXECFD: 1180Sstevel@tonic-gate /* this is the old exec that passes a file descriptor */ 1190Sstevel@tonic-gate fd = (int)auxv->a_un.a_val; 1200Sstevel@tonic-gate break; 1210Sstevel@tonic-gate case AT_FLAGS: 1220Sstevel@tonic-gate /* processor flags (MAU available, etc) */ 1230Sstevel@tonic-gate _flags = auxv->a_un.a_val; 1240Sstevel@tonic-gate break; 1250Sstevel@tonic-gate case AT_PAGESZ: 1260Sstevel@tonic-gate /* system page size */ 1270Sstevel@tonic-gate _syspagsz = (int)auxv->a_un.a_val; 1280Sstevel@tonic-gate break; 1290Sstevel@tonic-gate case AT_PHDR: 1300Sstevel@tonic-gate /* address of the segment table */ 1310Sstevel@tonic-gate phdr = (Phdr *)auxv->a_un.a_ptr; 1320Sstevel@tonic-gate break; 1330Sstevel@tonic-gate case AT_BASE: 1340Sstevel@tonic-gate /* interpreter base address */ 1350Sstevel@tonic-gate if (ld_base == 0) 1360Sstevel@tonic-gate ld_base = auxv->a_un.a_val; 1370Sstevel@tonic-gate interp_base = auxv->a_un.a_val; 1380Sstevel@tonic-gate break; 1390Sstevel@tonic-gate case AT_SUN_UID: 1400Sstevel@tonic-gate /* effective user id for the executable */ 1410Sstevel@tonic-gate euid = (uid_t)auxv->a_un.a_val; 1420Sstevel@tonic-gate break; 1430Sstevel@tonic-gate case AT_SUN_RUID: 1440Sstevel@tonic-gate /* real user id for the executable */ 1450Sstevel@tonic-gate uid = (uid_t)auxv->a_un.a_val; 1460Sstevel@tonic-gate break; 1470Sstevel@tonic-gate case AT_SUN_GID: 1480Sstevel@tonic-gate /* effective group id for the executable */ 1490Sstevel@tonic-gate egid = (gid_t)auxv->a_un.a_val; 1500Sstevel@tonic-gate break; 1510Sstevel@tonic-gate case AT_SUN_RGID: 1520Sstevel@tonic-gate /* real group id for the executable */ 1530Sstevel@tonic-gate gid = (gid_t)auxv->a_un.a_val; 1540Sstevel@tonic-gate break; 1550Sstevel@tonic-gate #ifdef AT_SUN_PLATFORM /* Defined on SunOS 5.5 & greater. */ 1560Sstevel@tonic-gate case AT_SUN_PLATFORM: 1570Sstevel@tonic-gate /* platform name */ 1580Sstevel@tonic-gate _platform = auxv->a_un.a_ptr; 1590Sstevel@tonic-gate break; 1600Sstevel@tonic-gate #endif 1610Sstevel@tonic-gate #ifdef AT_SUN_EXECNAME /* Defined on SunOS 5.6 & greater. */ 1620Sstevel@tonic-gate case AT_SUN_EXECNAME: 1630Sstevel@tonic-gate /* full pathname of execed object */ 1640Sstevel@tonic-gate _execname = auxv->a_un.a_ptr; 1650Sstevel@tonic-gate break; 1660Sstevel@tonic-gate #endif 1670Sstevel@tonic-gate #ifdef AT_SUN_AUXFLAGS /* At the behest of PSARC 2002/188 */ 1680Sstevel@tonic-gate case AT_SUN_AUXFLAGS: 1690Sstevel@tonic-gate auxflags = (int)auxv->a_un.a_val; 1700Sstevel@tonic-gate break; 1710Sstevel@tonic-gate #endif 1720Sstevel@tonic-gate #ifdef AT_SUN_HWCAP /* Hardware capabilities */ 1730Sstevel@tonic-gate case AT_SUN_HWCAP: 1740Sstevel@tonic-gate hwcap_1 = (uint_t)auxv->a_un.a_val; 1750Sstevel@tonic-gate break; 1760Sstevel@tonic-gate #endif 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* 1810Sstevel@tonic-gate * Get needed info from ld.so's dynamic structure. 1820Sstevel@tonic-gate */ 1830Sstevel@tonic-gate /* LINTED */ 1840Sstevel@tonic-gate dyn_ptr = (Dyn *)((char *)ld_dyn + ld_base); 1850Sstevel@tonic-gate for (ld_dyn = dyn_ptr; ld_dyn->d_tag != DT_NULL; ld_dyn++) { 1860Sstevel@tonic-gate switch (ld_dyn->d_tag) { 1870Sstevel@tonic-gate case DT_REL: 1880Sstevel@tonic-gate reladdr = ld_dyn->d_un.d_ptr + ld_base; 1890Sstevel@tonic-gate break; 1900Sstevel@tonic-gate case DT_RELCOUNT: 1910Sstevel@tonic-gate relcount = ld_dyn->d_un.d_val; 1920Sstevel@tonic-gate break; 1930Sstevel@tonic-gate case DT_RELENT: 1940Sstevel@tonic-gate relent = ld_dyn->d_un.d_val; 1950Sstevel@tonic-gate break; 1960Sstevel@tonic-gate case DT_STRTAB: 1970Sstevel@tonic-gate strtab = ld_dyn->d_un.d_ptr + ld_base; 1980Sstevel@tonic-gate break; 1990Sstevel@tonic-gate case DT_SONAME: 2000Sstevel@tonic-gate soname = ld_dyn->d_un.d_val; 2010Sstevel@tonic-gate break; 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate _rt_name = (char *)strtab + soname; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * If we don't have a RELENT, just assume 2080Sstevel@tonic-gate * the size. 2090Sstevel@tonic-gate */ 2100Sstevel@tonic-gate if (relent == 0) 2110Sstevel@tonic-gate relent = sizeof (Rel); 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Relocate all symbols in ld.so. 2150Sstevel@tonic-gate * 2160Sstevel@tonic-gate * Because ld.so.1 is built with -Bsymbolic there should only be 2170Sstevel@tonic-gate * RELATIVE and JMPSLOT relocations, both of which get relative 2180Sstevel@tonic-gate * additions against them. 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate for (; relcount; relcount--) { 2210Sstevel@tonic-gate ulong_t roffset; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate roffset = ((Rel *)reladdr)->r_offset + ld_base; 2240Sstevel@tonic-gate *((ulong_t *)roffset) += ld_base; 2250Sstevel@tonic-gate reladdr += relent; 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * Initialize the dyn_plt_ent_size field. It currently contains the 2300Sstevel@tonic-gate * size of the dyn_plt_template. It still needs to be aligned and have 2310Sstevel@tonic-gate * space for the 'dyn_data' area added. 2320Sstevel@tonic-gate */ 2330Sstevel@tonic-gate dyn_plt_ent_size = ROUND(dyn_plt_ent_size, M_WORD_ALIGN) + 2340Sstevel@tonic-gate sizeof (uintptr_t) + sizeof (uintptr_t) + sizeof (ulong_t) + 2350Sstevel@tonic-gate sizeof (ulong_t) + sizeof (Sym); 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* 2380Sstevel@tonic-gate * Continue with generic startup processing. 2390Sstevel@tonic-gate */ 240*6Srie if ((lmp = setup((char **)_envp, (auxv_t *)_auxv, _flags, _platform, 241*6Srie _syspagsz, _rt_name, dyn_ptr, ld_base, interp_base, fd, phdr, 242*6Srie _execname, _argv, dz_fd, uid, euid, gid, egid, NULL, auxflags, 243*6Srie hwcap_1)) == NULL) { 2440Sstevel@tonic-gate rtldexit(&lml_main, 1); 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate return (LM_ENTRY_PT(lmp)()); 2480Sstevel@tonic-gate } 249