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