1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #include	<stdio.h>
29*0Sstevel@tonic-gate #include	<unistd.h>
30*0Sstevel@tonic-gate #include	<string.h>
31*0Sstevel@tonic-gate #include	<sys/systeminfo.h>
32*0Sstevel@tonic-gate #include	<sys/param.h>
33*0Sstevel@tonic-gate #include	<sys/auxv.h>
34*0Sstevel@tonic-gate #include	"_conv.h"
35*0Sstevel@tonic-gate #include	"arch_msg.h"
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate  * Determine if the 32-bit or 64-bit kernel is running.
39*0Sstevel@tonic-gate  * Return the corresponding EI_CLASS constant.
40*0Sstevel@tonic-gate  */
41*0Sstevel@tonic-gate int
42*0Sstevel@tonic-gate conv_sys_eclass()
43*0Sstevel@tonic-gate {
44*0Sstevel@tonic-gate 	char buf[BUFSIZ];
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate 	/*
47*0Sstevel@tonic-gate 	 * SI_ISALIST will return -1 on pre-2.6 machines,
48*0Sstevel@tonic-gate 	 * which is fine - it can't be a 64-bit kernel.
49*0Sstevel@tonic-gate 	 */
50*0Sstevel@tonic-gate 	if (sysinfo(SI_ISALIST, buf, BUFSIZ) == -1)
51*0Sstevel@tonic-gate 		return (ELFCLASS32);
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 	if ((strstr(buf, MSG_ORIG(MSG_ARCH_SPARCV9)) != NULL) ||
54*0Sstevel@tonic-gate 	    (strstr(buf, MSG_ORIG(MSG_ARCH_AMD64)) != NULL))
55*0Sstevel@tonic-gate 		return (ELFCLASS64);
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 	return (ELFCLASS32);
58*0Sstevel@tonic-gate }
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate #if	defined(_LP64)
61*0Sstevel@tonic-gate /* ARGSUSED */
62*0Sstevel@tonic-gate void
63*0Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
64*0Sstevel@tonic-gate {
65*0Sstevel@tonic-gate 	/* ia32 & 64-bit sparc version does nothing */
66*0Sstevel@tonic-gate }
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #else
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate  * Wrapper for isaexec(3c) that allows disabling 64-bit counterpart execution
72*0Sstevel@tonic-gate  * via setting LD_NOEXEC64=yes.
73*0Sstevel@tonic-gate  *
74*0Sstevel@tonic-gate  * The only callers are 32-bit sgs applications.  These applications determine
75*0Sstevel@tonic-gate  * whether a 64-bit counterpart is available via this routine, and if not,
76*0Sstevel@tonic-gate  * control is passed back to the caller, who will then complete execution.
77*0Sstevel@tonic-gate  * Note, isaexec() will eventually fall through to looking for a 32-bit
78*0Sstevel@tonic-gate  * counterpart (ie. sparcv7, or sparc), but as none of the callers provide these
79*0Sstevel@tonic-gate  * counterparts, we simply return to the caller.
80*0Sstevel@tonic-gate  */
81*0Sstevel@tonic-gate void
82*0Sstevel@tonic-gate conv_check_native(char **argv, char **envp)
83*0Sstevel@tonic-gate {
84*0Sstevel@tonic-gate 	char	*str;
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	/*
87*0Sstevel@tonic-gate 	 * LD_NOEXEC_64 defined in the environment prevents the isaexec() call.
88*0Sstevel@tonic-gate 	 * This is used by the test suite to test 32-bit support libraries.
89*0Sstevel@tonic-gate 	 */
90*0Sstevel@tonic-gate 	if (((str = getenv(MSG_ORIG(MSG_LD_NOEXEC64))) != NULL) && *str)
91*0Sstevel@tonic-gate 		return;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	(void) isaexec(getexecname(), argv, envp);
94*0Sstevel@tonic-gate }
95*0Sstevel@tonic-gate #endif
96