]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setarch: use kernel address size if possible
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 21 Dec 2022 13:42:05 +0000 (13:42 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 21 Dec 2022 16:04:51 +0000 (16:04 +0000)
If setarch is running as 32bit userspace on a 64bit kernel we should use
the kernel personality.

meson.build
sys-utils/Makemodule.am
sys-utils/setarch.c

index 38e59bd9ae288ec7bcbf42caa9c315d17063dc78..ae91338b437edeb1cefda24a341289580ae83761 100644 (file)
@@ -1439,6 +1439,7 @@ exe = executable(
   'setarch',
   setarch_sources,
   include_directories : includes,
+  link_with : [lib_common],
   install_dir : usrbin_exec_dir,
   install : true)
 exes += exe
index 22047d9bd47cba92a573b49404c6fc9ded30a8a5..a0bf6cb7b037d1224e239d52d325e5b08701c808 100644 (file)
@@ -231,6 +231,7 @@ usrbin_exec_PROGRAMS += setarch
 MANPAGES += sys-utils/setarch.8
 dist_noinst_DATA += sys-utils/setarch.8.adoc
 setarch_SOURCES = sys-utils/setarch.c
+setarch_LDADD = $(LDADD) libcommon.la
 
 SETARCH_LINKS = uname26 linux32 linux64
 
index b86be1e29da1d3d8c4d1302fd68f53690acd01e5..d6789d05e86f555853d4b4d5fc842ac58377d6a7 100644 (file)
@@ -35,6 +35,7 @@
 #include "nls.h"
 #include "c.h"
 #include "closestream.h"
+#include "sysfs.h"
 
 #ifndef HAVE_PERSONALITY
 # include <syscall.h>
@@ -232,7 +233,9 @@ static struct arch_domain *init_arch_domains(void)
                if (!strcmp(un.machine, transitions[i].target_arch))
                        break;
        if (transitions[i].perval < 0) {
-               unsigned long wrdsz = CHAR_BIT * sizeof(void *);
+               int wrdsz = sysfs_get_address_bits(NULL);
+               if (wrdsz < 0)
+                       wrdsz = CHAR_BIT * sizeof(void *);
                if (wrdsz == 32 || wrdsz == 64) {
                        /* fill up the place holder */
                        transitions[i].perval = wrdsz == 32 ? PER_LINUX32 : PER_LINUX;