Skip to content

Commit 5147779

Browse files
committed
selftests/landlock: Add wrappers.h
Extract syscall wrappers to make them usable by standalone binaries (see next commit). Cc: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20250108154338.1129069-22-mic@digikod.net [mic: Fix comments] Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 2107c35 commit 5147779

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

tools/testing/selftests/landlock/common.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99

1010
#include <arpa/inet.h>
1111
#include <errno.h>
12-
#include <linux/landlock.h>
1312
#include <linux/securebits.h>
1413
#include <sys/capability.h>
1514
#include <sys/socket.h>
16-
#include <sys/syscall.h>
17-
#include <sys/types.h>
1815
#include <sys/un.h>
1916
#include <sys/wait.h>
2017
#include <unistd.h>
2118

2219
#include "../kselftest_harness.h"
20+
#include "wrappers.h"
2321

2422
#define TMP_DIR "tmp"
2523

@@ -30,34 +28,6 @@
3028
/* TEST_F_FORK() should not be used for new tests. */
3129
#define TEST_F_FORK(fixture_name, test_name) TEST_F(fixture_name, test_name)
3230

33-
#ifndef landlock_create_ruleset
34-
static inline int
35-
landlock_create_ruleset(const struct landlock_ruleset_attr *const attr,
36-
const size_t size, const __u32 flags)
37-
{
38-
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
39-
}
40-
#endif
41-
42-
#ifndef landlock_add_rule
43-
static inline int landlock_add_rule(const int ruleset_fd,
44-
const enum landlock_rule_type rule_type,
45-
const void *const rule_attr,
46-
const __u32 flags)
47-
{
48-
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr,
49-
flags);
50-
}
51-
#endif
52-
53-
#ifndef landlock_restrict_self
54-
static inline int landlock_restrict_self(const int ruleset_fd,
55-
const __u32 flags)
56-
{
57-
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
58-
}
59-
#endif
60-
6131
static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
6232
{
6333
cap_t cap_p;
@@ -250,11 +220,6 @@ struct service_fixture {
250220
};
251221
};
252222

253-
static pid_t __maybe_unused sys_gettid(void)
254-
{
255-
return syscall(__NR_gettid);
256-
}
257-
258223
static void __maybe_unused set_unix_address(struct service_fixture *const srv,
259224
const unsigned short index)
260225
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Syscall wrappers
4+
*
5+
* Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
6+
* Copyright © 2019-2020 ANSSI
7+
* Copyright © 2021-2025 Microsoft Corporation
8+
*/
9+
10+
#define _GNU_SOURCE
11+
#include <linux/landlock.h>
12+
#include <sys/syscall.h>
13+
#include <sys/types.h>
14+
#include <unistd.h>
15+
16+
#ifndef landlock_create_ruleset
17+
static inline int
18+
landlock_create_ruleset(const struct landlock_ruleset_attr *const attr,
19+
const size_t size, const __u32 flags)
20+
{
21+
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
22+
}
23+
#endif
24+
25+
#ifndef landlock_add_rule
26+
static inline int landlock_add_rule(const int ruleset_fd,
27+
const enum landlock_rule_type rule_type,
28+
const void *const rule_attr,
29+
const __u32 flags)
30+
{
31+
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr,
32+
flags);
33+
}
34+
#endif
35+
36+
#ifndef landlock_restrict_self
37+
static inline int landlock_restrict_self(const int ruleset_fd,
38+
const __u32 flags)
39+
{
40+
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
41+
}
42+
#endif
43+
44+
static inline pid_t sys_gettid(void)
45+
{
46+
return syscall(__NR_gettid);
47+
}

0 commit comments

Comments
 (0)