Skip to content

Commit b16bd53

Browse files
committed
seccomp-util: add parse_syscall_archs()
1 parent 29ea9f0 commit b16bd53

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/shared/seccomp-util.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include "macro.h"
3131
#include "nsflags.h"
3232
#include "seccomp-util.h"
33+
#include "set.h"
3334
#include "string-util.h"
35+
#include "strv.h"
3436
#include "util.h"
3537
#include "errno-list.h"
3638

@@ -1313,3 +1315,33 @@ int seccomp_restrict_archs(Set *archs) {
13131315

13141316
return seccomp_load(seccomp);
13151317
}
1318+
1319+
int parse_syscall_archs(char **l, Set **archs) {
1320+
_cleanup_set_free_ Set *_archs;
1321+
char **s;
1322+
int r;
1323+
1324+
assert(l);
1325+
assert(archs);
1326+
1327+
r = set_ensure_allocated(&_archs, NULL);
1328+
if (r < 0)
1329+
return r;
1330+
1331+
STRV_FOREACH(s, l) {
1332+
uint32_t a;
1333+
1334+
r = seccomp_arch_from_string(*s, &a);
1335+
if (r < 0)
1336+
return -EINVAL;
1337+
1338+
r = set_put(_archs, UINT32_TO_PTR(a + 1));
1339+
if (r < 0)
1340+
return -ENOMEM;
1341+
}
1342+
1343+
*archs = _archs;
1344+
_archs = NULL;
1345+
1346+
return 0;
1347+
}

src/shared/seccomp-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ extern const uint32_t seccomp_local_archs[];
8484
(arch) = seccomp_local_archs[++_i])
8585

8686
DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
87+
88+
int parse_syscall_archs(char **l, Set **archs);

0 commit comments

Comments
 (0)