1 /* vi: set sw=4 ts=4: */
3 * linux32/linux64 allows for changing uname emulation.
5 * Copyright 2002 Andi Kleen, SuSE Labs.
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 //config:config SETARCH
10 //config: bool "setarch (3.4 kb)"
12 //config: select PLATFORM_LINUX
14 //config: The linux32 utility is used to create a 32bit environment for the
15 //config: specified program (usually a shell). It only makes sense to have
16 //config: this util on a system that supports both 64bit and 32bit userland
17 //config: (like amd64/x86, ppc64/ppc, sparc64/sparc, etc...).
19 //config:config LINUX32
20 //config: bool "linux32 (3.2 kb)"
22 //config: select PLATFORM_LINUX
24 //config: Alias to "setarch linux32".
26 //config:config LINUX64
27 //config: bool "linux64 (3.2 kb)"
29 //config: select PLATFORM_LINUX
31 //config: Alias to "setarch linux64".
33 //applet:IF_SETARCH(APPLET_NOEXEC(setarch, setarch, BB_DIR_BIN, BB_SUID_DROP, setarch))
34 // APPLET_NOEXEC:name main location suid_type help
35 //applet:IF_LINUX32(APPLET_NOEXEC(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32))
36 //applet:IF_LINUX64(APPLET_NOEXEC(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64))
38 //kbuild:lib-$(CONFIG_SETARCH) += setarch.o
39 //kbuild:lib-$(CONFIG_LINUX32) += setarch.o
40 //kbuild:lib-$(CONFIG_LINUX64) += setarch.o
42 //usage:#define setarch_trivial_usage
43 //usage: "PERSONALITY [-R] PROG ARGS"
44 //usage:#define setarch_full_usage "\n\n"
45 //usage: "PERSONALITY may be:"
46 //usage: "\n"" linux32 Set 32bit uname emulation"
47 //usage: "\n"" linux64 Set 64bit uname emulation"
49 //usage: "\n"" -R Disable address space randomization"
51 //usage:#define linux32_trivial_usage NOUSAGE_STR
52 //usage:#define linux32_full_usage ""
54 //usage:#define linux64_trivial_usage NOUSAGE_STR
55 //usage:#define linux64_full_usage ""
58 #include <sys/personality.h>
60 #ifndef ADDR_NO_RANDOMIZE
61 # define ADDR_NO_RANDOMIZE 0x0040000
64 int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
65 int setarch_main(int argc UNUSED_PARAM, char **argv)
70 /* Figure out what personality we are supposed to switch to ...
71 * we can be invoked as either:
72 * argv[0],argv[1] == "setarch","personality"
73 * argv[0] == "personality"
75 if (ENABLE_SETARCH && applet_name[0] == 's'
76 && argv[1] && is_prefixed_with(argv[1], "linux")
79 applet_name = argv[0];
81 if ((!ENABLE_SETARCH && !ENABLE_LINUX32) || applet_name[5] == '6')
85 if ((!ENABLE_SETARCH && !ENABLE_LINUX64) || applet_name[5] == '3')
91 opts = getopt32(argv, "+R"); /* '+': stop at first non-option */
93 pers |= ADDR_NO_RANDOMIZE;
95 /* Try to set personality */
96 if (personality(pers) < 0)
97 bb_perror_msg_and_die("personality(0x%lx)", pers);
101 (--argv)[0] = (char*)"/bin/sh";
103 /* Try to execute the program */
104 BB_EXECVP_or_die(argv);