xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/arch.c (revision 2a8bcb4e)
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*45462bf8Sab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include	<stdio.h>
287c478bd9Sstevel@tonic-gate #include	<unistd.h>
297c478bd9Sstevel@tonic-gate #include	<string.h>
307c478bd9Sstevel@tonic-gate #include	<sys/systeminfo.h>
317c478bd9Sstevel@tonic-gate #include	"_conv.h"
327c478bd9Sstevel@tonic-gate #include	"arch_msg.h"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Determine if the 32-bit or 64-bit kernel is running.
367c478bd9Sstevel@tonic-gate  * Return the corresponding EI_CLASS constant.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate int
conv_sys_eclass(void)395aefb655Srie conv_sys_eclass(void)
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 	/*
447c478bd9Sstevel@tonic-gate 	 * SI_ISALIST will return -1 on pre-2.6 machines,
457c478bd9Sstevel@tonic-gate 	 * which is fine - it can't be a 64-bit kernel.
467c478bd9Sstevel@tonic-gate 	 */
477c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_ISALIST, buf, BUFSIZ) == -1)
487c478bd9Sstevel@tonic-gate 		return (ELFCLASS32);
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	if ((strstr(buf, MSG_ORIG(MSG_ARCH_SPARCV9)) != NULL) ||
517c478bd9Sstevel@tonic-gate 	    (strstr(buf, MSG_ORIG(MSG_ARCH_AMD64)) != NULL))
527c478bd9Sstevel@tonic-gate 		return (ELFCLASS64);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	return (ELFCLASS32);
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #if	defined(_LP64)
587c478bd9Sstevel@tonic-gate /* ARGSUSED */
597010c12aSrie uchar_t
conv_check_native(char ** argv,char ** envp)607c478bd9Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
617c478bd9Sstevel@tonic-gate {
625aefb655Srie 	/* 64-bit version does nothing */
637010c12aSrie 	return (ELFCLASS64);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #else
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Wrapper for isaexec(3c) that allows disabling 64-bit counterpart execution
707c478bd9Sstevel@tonic-gate  * via setting LD_NOEXEC64=yes.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * The only callers are 32-bit sgs applications.  These applications determine
737c478bd9Sstevel@tonic-gate  * whether a 64-bit counterpart is available via this routine, and if not,
747c478bd9Sstevel@tonic-gate  * control is passed back to the caller, who will then complete execution.
757c478bd9Sstevel@tonic-gate  * Note, isaexec() will eventually fall through to looking for a 32-bit
767c478bd9Sstevel@tonic-gate  * counterpart (ie. sparcv7, or sparc), but as none of the callers provide these
777c478bd9Sstevel@tonic-gate  * counterparts, we simply return to the caller.
787c478bd9Sstevel@tonic-gate  */
797010c12aSrie uchar_t
conv_check_native(char ** argv,char ** envp)807c478bd9Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
817c478bd9Sstevel@tonic-gate {
82*45462bf8Sab 	const char	*str;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/*
857c478bd9Sstevel@tonic-gate 	 * LD_NOEXEC_64 defined in the environment prevents the isaexec() call.
867c478bd9Sstevel@tonic-gate 	 * This is used by the test suite to test 32-bit support libraries.
877c478bd9Sstevel@tonic-gate 	 */
887c478bd9Sstevel@tonic-gate 	if (((str = getenv(MSG_ORIG(MSG_LD_NOEXEC64))) != NULL) && *str)
897010c12aSrie 		return (ELFCLASS32);
907c478bd9Sstevel@tonic-gate 
91*45462bf8Sab 	if ((str = getexecname()) != NULL)
92*45462bf8Sab 		(void) isaexec(str, argv, envp);
937010c12aSrie 	return (ELFCLASS32);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate #endif
96