um: make personality(PER_LINUX32) work on x86_64
PATCH 1/1 um: make personality(PER_LINUX32) work on x86_64
Without this patch:
#!/usr/bin/python3
import ctypes
import os
personality = ctypes.CDLL(None).personality
personality.restype = ctypes.c_int
personality.argtypes = [ctypes.c_ulong]
PER_LINUX32=8
personality(PER_LINUX32)
print(os.uname().machine)
returns:
x86_64
instead of the desired:
i686
--- arch/um/include/asm/Kbuild | 1 - arch/um/include/asm/compat.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 arch/um/include/asm/compat.h
arch/um/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 generic-y += bpf_perf_event.h generic-y += bug.h -generic-y += compat.h generic-y += current.h generic-y += device.h generic-y += dma-mapping.h
arch/um/include/asm/compat.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_COMPAT_H +#define __UM_COMPAT_H + +#include <asm-generic/compat.h> + +#if defined(CONFIG_UML_X86 ) && defined(CONFIG_64BIT ) +/* From arch/x86/include/asm/compat.h */ +#define COMPAT_UTS_MACHINE "i686\0\0" +#endif + +#endif
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Johannes Berg
maintainerQuoted 6 lines · Maciej Żenczykowski
Without this patch:
#!/usr/bin/python3
import ctypes
import os
personality = ctypes.CDLL(None).personality
personality.restype = ctypes.c_int
Quoted 9 lines
personality.argtypes = [ctypes.c_ulong]
PER_LINUX32=8
personality(PER_LINUX32)
print(os.uname().machine)
returns:
x86_64
instead of the desired:
i686
But ... why should it work? UML has no 32-bit compat support anyway.
johannes
Quoted 18 lines · Johannes Berg
Quoted 6 lines · Maciej Żenczykowski
Without this patch:
#!/usr/bin/python3
import ctypes
import os
personality = ctypes.CDLL(None).personality
personality.restype = ctypes.c_intQuoted 9 lines
personality.argtypes = [ctypes.c_ulong]
PER_LINUX32=8
personality(PER_LINUX32)
print(os.uname().machine)
returns:
x86_64
instead of the desired:
i686
Quoted 1 line
But ... why should it work? UML has no 32-bit compat support anyway.
Well, that's certainly a fair point.
On 'native' x86_64 this works even for 64-bit processes though. I wonder if that, in itself, is a feature or a bug...
In my case I was writing some debug code (to print the environment some test code is running in, since I think it was failing due to running 32-bit code in PER_LINUX32 on 64-bit arm) and testing (the test code) on x86_64 UML. I was surprised to discover the difference in UML vs my host desktop.
Quoted 1 line
johannes
--
Maciej Żenczykowski, Kernel Networking Developer @ Google
Johannes Berg
maintainerQuoted 25 lines · Maciej Żenczykowski
Quoted 18 lines · Johannes Berg
Quoted 6 lines · Maciej Żenczykowski
Without this patch:
#!/usr/bin/python3
import ctypes
import os
personality = ctypes.CDLL(None).personality
personality.restype = ctypes.c_intQuoted 9 lines
personality.argtypes = [ctypes.c_ulong]
PER_LINUX32=8
personality(PER_LINUX32)
print(os.uname().machine)
returns:
x86_64
instead of the desired:
i686Quoted 1 line
But ... why should it work? UML has no 32-bit compat support anyway.
Well, that's certainly a fair point.
On 'native'x86_64this works even for 64-bit processes though. I wonder if that, in itself, is a feature or a bug...
Quoted 6 lines
In my case I was writing some debug code (to print the environment some test code is running in, since I think it was failing due to running 32-bit code in
PER_LINUX32on 64-bit arm) and testing (the test code) onx86_64UML. I was surprised to discover the difference in UML vs my host desktop.
Alright, I have no idea. This doesn't really seem to do anything else, so I'm not sure what the point is... It _was_ introduced for compat though, but obviously the binary doesn't suddenly change to a 32-bit binary when you do this :)
Maybe the x86 maintainers have any other comments?
johannes