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 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * 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 */ 211618Srie 220Sstevel@tonic-gate /* 231618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <stdio.h> 290Sstevel@tonic-gate #include <unistd.h> 300Sstevel@tonic-gate #include <string.h> 310Sstevel@tonic-gate #include <sys/systeminfo.h> 320Sstevel@tonic-gate #include "_conv.h" 330Sstevel@tonic-gate #include "arch_msg.h" 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 360Sstevel@tonic-gate * Determine if the 32-bit or 64-bit kernel is running. 370Sstevel@tonic-gate * Return the corresponding EI_CLASS constant. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate int 401618Srie conv_sys_eclass(void) 410Sstevel@tonic-gate { 420Sstevel@tonic-gate char buf[BUFSIZ]; 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * SI_ISALIST will return -1 on pre-2.6 machines, 460Sstevel@tonic-gate * which is fine - it can't be a 64-bit kernel. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate if (sysinfo(SI_ISALIST, buf, BUFSIZ) == -1) 490Sstevel@tonic-gate return (ELFCLASS32); 500Sstevel@tonic-gate 510Sstevel@tonic-gate if ((strstr(buf, MSG_ORIG(MSG_ARCH_SPARCV9)) != NULL) || 520Sstevel@tonic-gate (strstr(buf, MSG_ORIG(MSG_ARCH_AMD64)) != NULL)) 530Sstevel@tonic-gate return (ELFCLASS64); 540Sstevel@tonic-gate 550Sstevel@tonic-gate return (ELFCLASS32); 560Sstevel@tonic-gate } 570Sstevel@tonic-gate 580Sstevel@tonic-gate #if defined(_LP64) 590Sstevel@tonic-gate /* ARGSUSED */ 60*2647Srie uchar_t 610Sstevel@tonic-gate conv_check_native(char **argv, char **envp) 620Sstevel@tonic-gate { 631618Srie /* 64-bit version does nothing */ 64*2647Srie return (ELFCLASS64); 650Sstevel@tonic-gate } 660Sstevel@tonic-gate 670Sstevel@tonic-gate #else 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * Wrapper for isaexec(3c) that allows disabling 64-bit counterpart execution 710Sstevel@tonic-gate * via setting LD_NOEXEC64=yes. 720Sstevel@tonic-gate * 730Sstevel@tonic-gate * The only callers are 32-bit sgs applications. These applications determine 740Sstevel@tonic-gate * whether a 64-bit counterpart is available via this routine, and if not, 750Sstevel@tonic-gate * control is passed back to the caller, who will then complete execution. 760Sstevel@tonic-gate * Note, isaexec() will eventually fall through to looking for a 32-bit 770Sstevel@tonic-gate * counterpart (ie. sparcv7, or sparc), but as none of the callers provide these 780Sstevel@tonic-gate * counterparts, we simply return to the caller. 790Sstevel@tonic-gate */ 80*2647Srie uchar_t 810Sstevel@tonic-gate conv_check_native(char **argv, char **envp) 820Sstevel@tonic-gate { 830Sstevel@tonic-gate char *str; 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * LD_NOEXEC_64 defined in the environment prevents the isaexec() call. 870Sstevel@tonic-gate * This is used by the test suite to test 32-bit support libraries. 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate if (((str = getenv(MSG_ORIG(MSG_LD_NOEXEC64))) != NULL) && *str) 90*2647Srie return (ELFCLASS32); 910Sstevel@tonic-gate 920Sstevel@tonic-gate (void) isaexec(getexecname(), argv, envp); 93*2647Srie return (ELFCLASS32); 940Sstevel@tonic-gate } 950Sstevel@tonic-gate #endif 96