Merge pull request #2698 from poettering/personality

Personality fixes
This commit is contained in:
Martin Pitt
2016-02-23 08:19:20 +01:00
8 changed files with 70 additions and 66 deletions
+2 -2
View File
@@ -850,6 +850,8 @@ libbasic_la_SOURCES = \
src/basic/exit-status.h \
src/basic/virt.c \
src/basic/virt.h \
src/basic/architecture.c \
src/basic/architecture.h \
src/basic/smack-util.c \
src/basic/smack-util.h \
src/basic/device-nodes.c \
@@ -963,8 +965,6 @@ libshared_la_SOURCES = \
src/shared/initreq.h \
src/shared/dns-domain.c \
src/shared/dns-domain.h \
src/shared/architecture.c \
src/shared/architecture.h \
src/shared/efivars.c \
src/shared/efivars.h \
src/shared/fstab-util.c \
+1 -1
View File
@@ -11,7 +11,7 @@ Information about build requirements are provided in the [README file](../master
Consult our [NEWS file](../master/NEWS) for information about what's new in the most recent systemd versions.
Please see our [Contribution Guidelines](../master/CONTRIBUTING.md) for more information about filing GitHub Issues and posting GitHub Pull Requests.
Please see our [Contribution Guidelines](../master/.github/CONTRIBUTING.md) for more information about filing GitHub Issues and posting GitHub Pull Requests.
When preparing patches for systemd, please follow our [Coding Style Guidelines](../master/CODING_STYLE).
+11 -8
View File
@@ -1262,14 +1262,17 @@
<varlistentry>
<term><varname>Personality=</varname></term>
<listitem><para>Controls which kernel architecture
<citerefentry project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>
shall report, when invoked by unit processes. Takes one of
<constant>x86</constant> and <constant>x86-64</constant>. This
is useful when running 32-bit services on a 64-bit host
system. If not specified, the personality is left unmodified
and thus reflects the personality of the host system's
kernel.</para></listitem>
<listitem><para>Controls which kernel architecture <citerefentry
project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry> shall report,
when invoked by unit processes. Takes one of the architecture identifiers <constant>x86</constant>,
<constant>x86-64</constant>, <constant>ppc</constant>, <constant>ppc-le</constant>, <constant>ppc64</constant>,
<constant>ppc64-le</constant>, <constant>s390</constant> or <constant>s390x</constant>. Which personality
architectures are supported depends on the system architecture. Usually the 64bit versions of the various
system architectures support their immediate 32bit personality architecture counterpart, but no others. For
example, <constant>x86-64</constant> systems support the <constant>x86-64</constant> and
<constant>x86</constant> personalities but no others. The personality feature is useful when running 32-bit
services on a 64-bit host system. If not specified, the personality is left unmodified and thus reflects the
personality of the host system's kernel.</para></listitem>
</varlistentry>
<varlistentry>
@@ -78,6 +78,7 @@ int uname_architecture(void);
# define native_architecture() ARCHITECTURE_X86_64
# define LIB_ARCH_TUPLE "x86_64-linux-gnu"
# define PROC_CPUINFO_MODEL "model name"
# define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
#elif defined(__i386__)
# define native_architecture() ARCHITECTURE_X86
# define LIB_ARCH_TUPLE "i386-linux-gnu"
@@ -86,9 +87,11 @@ int uname_architecture(void);
# if __BYTE_ORDER == __BIG_ENDIAN
# define native_architecture() ARCHITECTURE_PPC64
# define LIB_ARCH_TUPLE "ppc64-linux-gnu"
# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
# else
# define native_architecture() ARCHITECTURE_PPC64_LE
# define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
# endif
# define PROC_CPUINFO_MODEL "cpu"
#elif defined(__powerpc__)
@@ -114,6 +117,7 @@ int uname_architecture(void);
#elif defined(__s390x__)
# define native_architecture() ARCHITECTURE_S390X
# define LIB_ARCH_TUPLE "s390x-linux-gnu"
# define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
#elif defined(__s390__)
# define native_architecture() ARCHITECTURE_S390
# define LIB_ARCH_TUPLE "s390-linux-gnu"
+24 -55
View File
@@ -38,6 +38,7 @@
#endif
#include "alloc-util.h"
#include "architecture.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
@@ -674,75 +675,43 @@ bool oom_score_adjust_is_valid(int oa) {
}
unsigned long personality_from_string(const char *p) {
int architecture;
/* Parse a personality specifier. We introduce our own
* identifiers that indicate specific ABIs, rather than just
* hints regarding the register size, since we want to keep
* things open for multiple locally supported ABIs for the
* same register size. We try to reuse the ABI identifiers
* used by libseccomp. */
if (!p)
return PERSONALITY_INVALID;
#if defined(__x86_64__)
/* Parse a personality specifier. We use our own identifiers that indicate specific ABIs, rather than just
* hints regarding the register size, since we want to keep things open for multiple locally supported ABIs for
* the same register size. */
if (streq(p, "x86"))
architecture = architecture_from_string(p);
if (architecture < 0)
return PERSONALITY_INVALID;
if (architecture == native_architecture())
return PER_LINUX;
#ifdef SECONDARY_ARCHITECTURE
if (architecture == SECONDARY_ARCHITECTURE)
return PER_LINUX32;
if (streq(p, "x86-64"))
return PER_LINUX;
#elif defined(__i386__)
if (streq(p, "x86"))
return PER_LINUX;
#elif defined(__s390x__)
if (streq(p, "s390"))
return PER_LINUX32;
if (streq(p, "s390x"))
return PER_LINUX;
#elif defined(__s390__)
if (streq(p, "s390"))
return PER_LINUX;
#endif
return PERSONALITY_INVALID;
}
const char* personality_to_string(unsigned long p) {
#if defined(__x86_64__)
if (p == PER_LINUX32)
return "x86";
int architecture = _ARCHITECTURE_INVALID;
if (p == PER_LINUX)
return "x86-64";
#elif defined(__i386__)
if (p == PER_LINUX)
return "x86";
#elif defined(__s390x__)
if (p == PER_LINUX)
return "s390x";
if (p == PER_LINUX32)
return "s390";
#elif defined(__s390__)
if (p == PER_LINUX)
return "s390";
architecture = native_architecture();
#ifdef SECONDARY_ARCHITECTURE
else if (p == PER_LINUX32)
architecture = SECONDARY_ARCHITECTURE;
#endif
return NULL;
if (architecture < 0)
return NULL;
return architecture_to_string(architecture);
}
void valgrind_summary_hack(void) {
+2
View File
@@ -201,6 +201,8 @@ static int detect_vm_xen(void) {
r = read_one_line_file("/proc/xen/capabilities", &domcap);
if (r == -ENOENT)
return VIRTUALIZATION_NONE;
if (r < 0)
return r;
i = domcap;
while ((cap = strsep(&i, ",")))
+26
View File
@@ -18,12 +18,14 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/personality.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "alloc-util.h"
#include "architecture.h"
#include "log.h"
#include "macro.h"
#include "process-util.h"
@@ -128,6 +130,29 @@ static void test_pid_is_alive(void) {
assert_se(!pid_is_alive(-1));
}
static void test_personality(void) {
assert_se(personality_to_string(PER_LINUX));
assert_se(!personality_to_string(PERSONALITY_INVALID));
assert_se(streq(personality_to_string(PER_LINUX), architecture_to_string(native_architecture())));
assert_se(personality_from_string(personality_to_string(PER_LINUX)) == PER_LINUX);
assert_se(personality_from_string(architecture_to_string(native_architecture())) == PER_LINUX);
#ifdef __x86_64__
assert_se(streq_ptr(personality_to_string(PER_LINUX), "x86-64"));
assert_se(streq_ptr(personality_to_string(PER_LINUX32), "x86"));
assert_se(personality_from_string("x86-64") == PER_LINUX);
assert_se(personality_from_string("x86") == PER_LINUX32);
assert_se(personality_from_string("ia64") == PERSONALITY_INVALID);
assert_se(personality_from_string(NULL) == PERSONALITY_INVALID);
assert_se(personality_from_string(personality_to_string(PER_LINUX32)) == PER_LINUX32);
#endif
}
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -135,6 +160,7 @@ int main(int argc, char *argv[]) {
test_get_process_comm();
test_pid_is_unwaited();
test_pid_is_alive();
test_personality();
return 0;
}