xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/arch.c (revision 1618:8c9a4f31d225)
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
5*1618Srie  * Common Development and Distribution License (the "License").
6*1618Srie  * 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  */
21*1618Srie 
220Sstevel@tonic-gate /*
23*1618Srie  * 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
40*1618Srie 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 */
600Sstevel@tonic-gate void
610Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
620Sstevel@tonic-gate {
63*1618Srie 	/* 64-bit version does nothing */
640Sstevel@tonic-gate }
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #else
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Wrapper for isaexec(3c) that allows disabling 64-bit counterpart execution
700Sstevel@tonic-gate  * via setting LD_NOEXEC64=yes.
710Sstevel@tonic-gate  *
720Sstevel@tonic-gate  * The only callers are 32-bit sgs applications.  These applications determine
730Sstevel@tonic-gate  * whether a 64-bit counterpart is available via this routine, and if not,
740Sstevel@tonic-gate  * control is passed back to the caller, who will then complete execution.
750Sstevel@tonic-gate  * Note, isaexec() will eventually fall through to looking for a 32-bit
760Sstevel@tonic-gate  * counterpart (ie. sparcv7, or sparc), but as none of the callers provide these
770Sstevel@tonic-gate  * counterparts, we simply return to the caller.
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate void
800Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	char	*str;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	/*
850Sstevel@tonic-gate 	 * LD_NOEXEC_64 defined in the environment prevents the isaexec() call.
860Sstevel@tonic-gate 	 * This is used by the test suite to test 32-bit support libraries.
870Sstevel@tonic-gate 	 */
880Sstevel@tonic-gate 	if (((str = getenv(MSG_ORIG(MSG_LD_NOEXEC64))) != NULL) && *str)
890Sstevel@tonic-gate 		return;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	(void) isaexec(getexecname(), argv, envp);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate #endif
94