1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1988 AT&T 24*0Sstevel@tonic-gate * All Rights Reserved 25*0Sstevel@tonic-gate * 26*0Sstevel@tonic-gate * 27*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate /* 33*0Sstevel@tonic-gate * SPARC specific setup routine - relocate ld.so's symbols, setup its 34*0Sstevel@tonic-gate * environment, map in loadable sections of the executable. 35*0Sstevel@tonic-gate * 36*0Sstevel@tonic-gate * Takes base address ld.so was loaded at, address of ld.so's dynamic 37*0Sstevel@tonic-gate * structure, address of process environment pointers, address of auxiliary 38*0Sstevel@tonic-gate * vector and * argv[0] (process name). 39*0Sstevel@tonic-gate * If errors occur, send process signal - otherwise 40*0Sstevel@tonic-gate * return executable's entry point to the bootstrap routine. 41*0Sstevel@tonic-gate */ 42*0Sstevel@tonic-gate #include "_synonyms.h" 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #include <signal.h> 45*0Sstevel@tonic-gate #include <stdlib.h> 46*0Sstevel@tonic-gate #include <fcntl.h> 47*0Sstevel@tonic-gate #include <stdio.h> 48*0Sstevel@tonic-gate #include <sys/auxv.h> 49*0Sstevel@tonic-gate #include <sys/types.h> 50*0Sstevel@tonic-gate #include <sys/stat.h> 51*0Sstevel@tonic-gate #include <link.h> 52*0Sstevel@tonic-gate #include <dlfcn.h> 53*0Sstevel@tonic-gate #include "_rtld.h" 54*0Sstevel@tonic-gate #include "_audit.h" 55*0Sstevel@tonic-gate #include "msg.h" 56*0Sstevel@tonic-gate #ifdef A_OUT 57*0Sstevel@tonic-gate #include "_a.out.h" 58*0Sstevel@tonic-gate #endif /* A_OUT */ 59*0Sstevel@tonic-gate #include "debug.h" 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate extern int _end; 62*0Sstevel@tonic-gate extern int _etext; 63*0Sstevel@tonic-gate extern void _init(void); 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate /* VARARGS */ 67*0Sstevel@tonic-gate unsigned long 68*0Sstevel@tonic-gate _setup(Boot * ebp, Dyn * ld_dyn) 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate unsigned long reladdr, relacount, ld_base = 0; 71*0Sstevel@tonic-gate unsigned long relaent = 0; 72*0Sstevel@tonic-gate unsigned long strtab, soname, interp_base = 0; 73*0Sstevel@tonic-gate char *_rt_name, **_envp, **_argv; 74*0Sstevel@tonic-gate int _syspagsz = 0, fd = -1, dz_fd = FD_UNAVAIL; 75*0Sstevel@tonic-gate uint_t _flags = 0, hwcap_1 = 0; 76*0Sstevel@tonic-gate Dyn * dyn_ptr; 77*0Sstevel@tonic-gate Phdr * phdr = 0; 78*0Sstevel@tonic-gate Rt_map * lmp; 79*0Sstevel@tonic-gate auxv_t *auxv, *_auxv; 80*0Sstevel@tonic-gate uid_t uid = -1, euid = -1; 81*0Sstevel@tonic-gate gid_t gid = -1, egid = -1; 82*0Sstevel@tonic-gate char *_platform = 0, *_execname = 0; 83*0Sstevel@tonic-gate int auxflags = -1; 84*0Sstevel@tonic-gate #ifdef A_OUT 85*0Sstevel@tonic-gate void * aoutdyn = 0; 86*0Sstevel@tonic-gate #endif /* A_OUT */ 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate /* 89*0Sstevel@tonic-gate * Scan the bootstrap structure to pick up the basics. 90*0Sstevel@tonic-gate */ 91*0Sstevel@tonic-gate for (; ebp->eb_tag != EB_NULL; ebp++) 92*0Sstevel@tonic-gate switch (ebp->eb_tag) { 93*0Sstevel@tonic-gate case EB_DYNAMIC: 94*0Sstevel@tonic-gate #ifdef A_OUT 95*0Sstevel@tonic-gate aoutdyn = (struct link_dynamic *)ebp->eb_un.eb_val; 96*0Sstevel@tonic-gate #endif /* A_OUT */ 97*0Sstevel@tonic-gate break; 98*0Sstevel@tonic-gate case EB_LDSO_BASE: 99*0Sstevel@tonic-gate ld_base = (unsigned long)ebp->eb_un.eb_val; 100*0Sstevel@tonic-gate break; 101*0Sstevel@tonic-gate case EB_ARGV: 102*0Sstevel@tonic-gate _argv = (char **)ebp->eb_un.eb_ptr; 103*0Sstevel@tonic-gate break; 104*0Sstevel@tonic-gate case EB_ENVP: 105*0Sstevel@tonic-gate _envp = (char **)ebp->eb_un.eb_ptr; 106*0Sstevel@tonic-gate break; 107*0Sstevel@tonic-gate case EB_AUXV: 108*0Sstevel@tonic-gate _auxv = (auxv_t *)ebp->eb_un.eb_ptr; 109*0Sstevel@tonic-gate break; 110*0Sstevel@tonic-gate case EB_DEVZERO: 111*0Sstevel@tonic-gate dz_fd = (int)ebp->eb_un.eb_val; 112*0Sstevel@tonic-gate break; 113*0Sstevel@tonic-gate case EB_PAGESIZE: 114*0Sstevel@tonic-gate _syspagsz = (int)ebp->eb_un.eb_val; 115*0Sstevel@tonic-gate break; 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* 119*0Sstevel@tonic-gate * Search the aux. vector for the information passed by exec. 120*0Sstevel@tonic-gate */ 121*0Sstevel@tonic-gate for (auxv = _auxv; auxv->a_type != AT_NULL; auxv++) { 122*0Sstevel@tonic-gate switch (auxv->a_type) { 123*0Sstevel@tonic-gate case AT_EXECFD: 124*0Sstevel@tonic-gate /* this is the old exec that passes a file descriptor */ 125*0Sstevel@tonic-gate fd = (int)auxv->a_un.a_val; 126*0Sstevel@tonic-gate break; 127*0Sstevel@tonic-gate case AT_FLAGS: 128*0Sstevel@tonic-gate /* processor flags (MAU available, etc) */ 129*0Sstevel@tonic-gate _flags = auxv->a_un.a_val; 130*0Sstevel@tonic-gate break; 131*0Sstevel@tonic-gate case AT_PAGESZ: 132*0Sstevel@tonic-gate /* system page size */ 133*0Sstevel@tonic-gate _syspagsz = (int)auxv->a_un.a_val; 134*0Sstevel@tonic-gate break; 135*0Sstevel@tonic-gate case AT_PHDR: 136*0Sstevel@tonic-gate /* address of the segment table */ 137*0Sstevel@tonic-gate phdr = (Phdr *)auxv->a_un.a_ptr; 138*0Sstevel@tonic-gate break; 139*0Sstevel@tonic-gate case AT_BASE: 140*0Sstevel@tonic-gate /* interpreter base address */ 141*0Sstevel@tonic-gate if (ld_base == 0) 142*0Sstevel@tonic-gate ld_base = auxv->a_un.a_val; 143*0Sstevel@tonic-gate interp_base = auxv->a_un.a_val; 144*0Sstevel@tonic-gate break; 145*0Sstevel@tonic-gate case AT_SUN_UID: 146*0Sstevel@tonic-gate /* effective user id for the executable */ 147*0Sstevel@tonic-gate euid = (uid_t)auxv->a_un.a_val; 148*0Sstevel@tonic-gate break; 149*0Sstevel@tonic-gate case AT_SUN_RUID: 150*0Sstevel@tonic-gate /* real user id for the executable */ 151*0Sstevel@tonic-gate uid = (uid_t)auxv->a_un.a_val; 152*0Sstevel@tonic-gate break; 153*0Sstevel@tonic-gate case AT_SUN_GID: 154*0Sstevel@tonic-gate /* effective group id for the executable */ 155*0Sstevel@tonic-gate egid = (gid_t)auxv->a_un.a_val; 156*0Sstevel@tonic-gate break; 157*0Sstevel@tonic-gate case AT_SUN_RGID: 158*0Sstevel@tonic-gate /* real group id for the executable */ 159*0Sstevel@tonic-gate gid = (gid_t)auxv->a_un.a_val; 160*0Sstevel@tonic-gate break; 161*0Sstevel@tonic-gate #ifdef AT_SUN_PLATFORM /* Defined on SunOS 5.5 & greater. */ 162*0Sstevel@tonic-gate case AT_SUN_PLATFORM: 163*0Sstevel@tonic-gate /* platform name */ 164*0Sstevel@tonic-gate _platform = auxv->a_un.a_ptr; 165*0Sstevel@tonic-gate break; 166*0Sstevel@tonic-gate #endif 167*0Sstevel@tonic-gate #ifdef AT_SUN_EXECNAME /* Defined on SunOS 5.6 & greater. */ 168*0Sstevel@tonic-gate case AT_SUN_EXECNAME: 169*0Sstevel@tonic-gate /* full pathname of execed object */ 170*0Sstevel@tonic-gate _execname = auxv->a_un.a_ptr; 171*0Sstevel@tonic-gate break; 172*0Sstevel@tonic-gate #endif 173*0Sstevel@tonic-gate #ifdef AT_SUN_AUXFLAGS /* At the behest of PSARC 2002/188 */ 174*0Sstevel@tonic-gate case AT_SUN_AUXFLAGS: 175*0Sstevel@tonic-gate auxflags = (int)auxv->a_un.a_val; 176*0Sstevel@tonic-gate break; 177*0Sstevel@tonic-gate #endif 178*0Sstevel@tonic-gate #ifdef AT_SUN_HWCAP /* Hardware capabilities */ 179*0Sstevel@tonic-gate case AT_SUN_HWCAP: 180*0Sstevel@tonic-gate hwcap_1 = (uint_t)auxv->a_un.a_val; 181*0Sstevel@tonic-gate break; 182*0Sstevel@tonic-gate #endif 183*0Sstevel@tonic-gate } 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate /* 187*0Sstevel@tonic-gate * Get needed info from ld.so's dynamic structure. 188*0Sstevel@tonic-gate */ 189*0Sstevel@tonic-gate /* LINTED */ 190*0Sstevel@tonic-gate dyn_ptr = (Dyn *)((char *)ld_dyn + ld_base); 191*0Sstevel@tonic-gate for (ld_dyn = dyn_ptr; ld_dyn->d_tag != DT_NULL; ld_dyn++) { 192*0Sstevel@tonic-gate switch (ld_dyn->d_tag) { 193*0Sstevel@tonic-gate case DT_RELA: 194*0Sstevel@tonic-gate reladdr = ld_dyn->d_un.d_ptr + ld_base; 195*0Sstevel@tonic-gate break; 196*0Sstevel@tonic-gate case DT_RELACOUNT: 197*0Sstevel@tonic-gate relacount = ld_dyn->d_un.d_val; 198*0Sstevel@tonic-gate break; 199*0Sstevel@tonic-gate case DT_RELAENT: 200*0Sstevel@tonic-gate relaent = ld_dyn->d_un.d_val; 201*0Sstevel@tonic-gate break; 202*0Sstevel@tonic-gate case DT_STRTAB: 203*0Sstevel@tonic-gate strtab = ld_dyn->d_un.d_ptr + ld_base; 204*0Sstevel@tonic-gate break; 205*0Sstevel@tonic-gate case DT_SONAME: 206*0Sstevel@tonic-gate soname = ld_dyn->d_un.d_val; 207*0Sstevel@tonic-gate break; 208*0Sstevel@tonic-gate } 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate _rt_name = (char *)strtab + soname; 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate /* 213*0Sstevel@tonic-gate * If we don't have a RELAENT, just assume 214*0Sstevel@tonic-gate * the size. 215*0Sstevel@tonic-gate */ 216*0Sstevel@tonic-gate if (relaent == 0) 217*0Sstevel@tonic-gate relaent = sizeof (Rela); 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* 220*0Sstevel@tonic-gate * Because ld.so.1 is built with -Bsymbolic there should only be 221*0Sstevel@tonic-gate * RELATIVE and JMPSLOT relocations. Process all relatives first. 222*0Sstevel@tonic-gate */ 223*0Sstevel@tonic-gate for (; relacount; relacount--) { 224*0Sstevel@tonic-gate ulong_t roffset; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate roffset = ((Rela *)reladdr)->r_offset + ld_base; 227*0Sstevel@tonic-gate *((ulong_t *)roffset) = ld_base + 228*0Sstevel@tonic-gate (long)(((Rela *)reladdr)->r_addend); 229*0Sstevel@tonic-gate reladdr += relaent; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate /* 233*0Sstevel@tonic-gate * Continue with generic startup processing. 234*0Sstevel@tonic-gate */ 235*0Sstevel@tonic-gate if ((lmp = setup((unsigned long)_envp, (unsigned long)_auxv, _flags, 236*0Sstevel@tonic-gate _platform, _syspagsz, _rt_name, dyn_ptr, ld_base, interp_base, 237*0Sstevel@tonic-gate fd, phdr, _execname, _argv, dz_fd, uid, euid, gid, egid, 238*0Sstevel@tonic-gate #ifdef A_OUT 239*0Sstevel@tonic-gate aoutdyn, auxflags, hwcap_1)) == (Rt_map *)0) { 240*0Sstevel@tonic-gate #else 241*0Sstevel@tonic-gate NULL, auxflags, hwcap_1)) == NULL) { 242*0Sstevel@tonic-gate #endif /* A_OUT */ 243*0Sstevel@tonic-gate rtldexit(&lml_main, 1); 244*0Sstevel@tonic-gate } 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate return (LM_ENTRY_PT(lmp)()); 247*0Sstevel@tonic-gate } 248