xref: /titanic_51/usr/src/cmd/sgs/libconv/common/arch.c (revision 45462bf898cce4257293567d9170f6cf79d0ea1d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*45462bf8Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include	<stdio.h>
297c478bd9Sstevel@tonic-gate #include	<unistd.h>
307c478bd9Sstevel@tonic-gate #include	<string.h>
317c478bd9Sstevel@tonic-gate #include	<sys/systeminfo.h>
327c478bd9Sstevel@tonic-gate #include	"_conv.h"
337c478bd9Sstevel@tonic-gate #include	"arch_msg.h"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Determine if the 32-bit or 64-bit kernel is running.
377c478bd9Sstevel@tonic-gate  * Return the corresponding EI_CLASS constant.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate int
405aefb655Srie conv_sys_eclass(void)
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 	/*
457c478bd9Sstevel@tonic-gate 	 * SI_ISALIST will return -1 on pre-2.6 machines,
467c478bd9Sstevel@tonic-gate 	 * which is fine - it can't be a 64-bit kernel.
477c478bd9Sstevel@tonic-gate 	 */
487c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_ISALIST, buf, BUFSIZ) == -1)
497c478bd9Sstevel@tonic-gate 		return (ELFCLASS32);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	if ((strstr(buf, MSG_ORIG(MSG_ARCH_SPARCV9)) != NULL) ||
527c478bd9Sstevel@tonic-gate 	    (strstr(buf, MSG_ORIG(MSG_ARCH_AMD64)) != NULL))
537c478bd9Sstevel@tonic-gate 		return (ELFCLASS64);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	return (ELFCLASS32);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #if	defined(_LP64)
597c478bd9Sstevel@tonic-gate /* ARGSUSED */
607010c12aSrie uchar_t
617c478bd9Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
627c478bd9Sstevel@tonic-gate {
635aefb655Srie 	/* 64-bit version does nothing */
647010c12aSrie 	return (ELFCLASS64);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #else
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Wrapper for isaexec(3c) that allows disabling 64-bit counterpart execution
717c478bd9Sstevel@tonic-gate  * via setting LD_NOEXEC64=yes.
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  * The only callers are 32-bit sgs applications.  These applications determine
747c478bd9Sstevel@tonic-gate  * whether a 64-bit counterpart is available via this routine, and if not,
757c478bd9Sstevel@tonic-gate  * control is passed back to the caller, who will then complete execution.
767c478bd9Sstevel@tonic-gate  * Note, isaexec() will eventually fall through to looking for a 32-bit
777c478bd9Sstevel@tonic-gate  * counterpart (ie. sparcv7, or sparc), but as none of the callers provide these
787c478bd9Sstevel@tonic-gate  * counterparts, we simply return to the caller.
797c478bd9Sstevel@tonic-gate  */
807010c12aSrie uchar_t
817c478bd9Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
827c478bd9Sstevel@tonic-gate {
83*45462bf8Sab196087 	const char	*str;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/*
867c478bd9Sstevel@tonic-gate 	 * LD_NOEXEC_64 defined in the environment prevents the isaexec() call.
877c478bd9Sstevel@tonic-gate 	 * This is used by the test suite to test 32-bit support libraries.
887c478bd9Sstevel@tonic-gate 	 */
897c478bd9Sstevel@tonic-gate 	if (((str = getenv(MSG_ORIG(MSG_LD_NOEXEC64))) != NULL) && *str)
907010c12aSrie 		return (ELFCLASS32);
917c478bd9Sstevel@tonic-gate 
92*45462bf8Sab196087 	if ((str = getexecname()) != NULL)
93*45462bf8Sab196087 		(void) isaexec(str, argv, envp);
947010c12aSrie 	return (ELFCLASS32);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate #endif
97