xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/arch.c (revision 6569:90c99f858ba3)
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 /*
23*6569Sab196087  * Copyright 2008 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
conv_sys_eclass(void)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 */
602647Srie uchar_t
conv_check_native(char ** argv,char ** envp)610Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
620Sstevel@tonic-gate {
631618Srie 	/* 64-bit version does nothing */
642647Srie 	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  */
802647Srie uchar_t
conv_check_native(char ** argv,char ** envp)810Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
820Sstevel@tonic-gate {
83*6569Sab196087 	const 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)
902647Srie 		return (ELFCLASS32);
910Sstevel@tonic-gate 
92*6569Sab196087 	if ((str = getexecname()) != NULL)
93*6569Sab196087 		(void) isaexec(str, argv, envp);
942647Srie 	return (ELFCLASS32);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate #endif
97