Line data Source code
1 : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2 :
3 : /***
4 : This file is part of systemd.
5 :
6 : Copyright 2014 Lennart Poettering
7 :
8 : systemd is free software; you can redistribute it and/or modify it
9 : under the terms of the GNU Lesser General Public License as published by
10 : the Free Software Foundation; either version 2.1 of the License, or
11 : (at your option) any later version.
12 :
13 : systemd is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : Lesser General Public License for more details.
17 :
18 : You should have received a copy of the GNU Lesser General Public License
19 : along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 : ***/
21 :
22 : #include <seccomp.h>
23 :
24 : #include "util.h"
25 : #include "seccomp-util.h"
26 :
27 0 : const char* seccomp_arch_to_string(uint32_t c) {
28 :
29 0 : if (c == SCMP_ARCH_NATIVE)
30 0 : return "native";
31 0 : if (c == SCMP_ARCH_X86)
32 0 : return "x86";
33 0 : if (c == SCMP_ARCH_X86_64)
34 0 : return "x86-64";
35 0 : if (c == SCMP_ARCH_X32)
36 0 : return "x32";
37 0 : if (c == SCMP_ARCH_ARM)
38 0 : return "arm";
39 :
40 0 : return NULL;
41 : }
42 :
43 0 : int seccomp_arch_from_string(const char *n, uint32_t *ret) {
44 0 : if (!n)
45 0 : return -EINVAL;
46 :
47 0 : assert(ret);
48 :
49 0 : if (streq(n, "native"))
50 0 : *ret = SCMP_ARCH_NATIVE;
51 0 : else if (streq(n, "x86"))
52 0 : *ret = SCMP_ARCH_X86;
53 0 : else if (streq(n, "x86-64"))
54 0 : *ret = SCMP_ARCH_X86_64;
55 0 : else if (streq(n, "x32"))
56 0 : *ret = SCMP_ARCH_X32;
57 0 : else if (streq(n, "arm"))
58 0 : *ret = SCMP_ARCH_ARM;
59 : else
60 0 : return -EINVAL;
61 :
62 0 : return 0;
63 : }
64 :
65 0 : int seccomp_add_secondary_archs(scmp_filter_ctx *c) {
66 :
67 : #if defined(__i386__) || defined(__x86_64__)
68 : int r;
69 :
70 : /* Add in all possible secondary archs we are aware of that
71 : * this kernel might support. */
72 :
73 0 : r = seccomp_arch_add(c, SCMP_ARCH_X86);
74 0 : if (r < 0 && r != -EEXIST)
75 0 : return r;
76 :
77 0 : r = seccomp_arch_add(c, SCMP_ARCH_X86_64);
78 0 : if (r < 0 && r != -EEXIST)
79 0 : return r;
80 :
81 0 : r = seccomp_arch_add(c, SCMP_ARCH_X32);
82 0 : if (r < 0 && r != -EEXIST)
83 0 : return r;
84 :
85 : #endif
86 :
87 0 : return 0;
88 :
89 : }
|