Skip to content

Commit 2e86c95

Browse files
committed
src: move syscall wrappers to new file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent c2fa3c6 commit 2e86c95

4 files changed

Lines changed: 266 additions & 176 deletions

File tree

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ EXTRA_DIST = COPYING COPYING.libcrun README.md NEWS SECURITY.md rpm/crun.spec au
164164
src/libcrun/scheduler.h src/libcrun/mempolicy.h src/libcrun/status.h src/libcrun/terminal.h \
165165
src/libcrun/mount_flags.h src/libcrun/intelrdt.h src/libcrun/ring_buffer.h src/libcrun/string_map.h \
166166
src/libcrun/net_device.h \
167+
src/libcrun/syscalls.h \
167168
crun.1.md crun.1 libcrun.lds \
168169
krun.1.md krun.1 \
169170
lua/luacrun.rockspec

src/libcrun/linux.c

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <yajl/yajl_gen.h>
7575

7676
#include "mount_flags.h"
77+
#include "syscalls.h"
7778

7879
#define YAJL_STR(x) ((const unsigned char *) (x))
7980

@@ -239,156 +240,6 @@ libcrun_find_namespace (const char *name)
239240
return -1;
240241
}
241242

242-
#ifndef __aligned_u64
243-
# define __aligned_u64 uint64_t __attribute__ ((aligned (8)))
244-
#endif
245-
246-
#ifndef CLONE_INTO_CGROUP
247-
# define CLONE_INTO_CGROUP 0x200000000ULL
248-
#endif
249-
250-
struct _clone3_args
251-
{
252-
__aligned_u64 flags;
253-
__aligned_u64 pidfd;
254-
__aligned_u64 child_tid;
255-
__aligned_u64 parent_tid;
256-
__aligned_u64 exit_signal;
257-
__aligned_u64 stack;
258-
__aligned_u64 stack_size;
259-
__aligned_u64 tls;
260-
__aligned_u64 set_tid;
261-
__aligned_u64 set_tid_size;
262-
__aligned_u64 cgroup;
263-
};
264-
265-
static int
266-
syscall_getcwd (char *path, size_t len)
267-
{
268-
return (int) syscall (__NR_getcwd, path, len);
269-
}
270-
271-
static int
272-
syscall_clone3 (struct _clone3_args *args)
273-
{
274-
#ifdef __NR_clone3
275-
return (int) syscall (__NR_clone3, args, sizeof (*args));
276-
#else
277-
(void) args;
278-
errno = ENOSYS;
279-
return -1;
280-
#endif
281-
}
282-
283-
static int
284-
syscall_fsopen (const char *fs_name, unsigned int flags)
285-
{
286-
#if defined __NR_fsopen
287-
return (int) syscall (__NR_fsopen, fs_name, flags);
288-
#else
289-
(void) fs_name;
290-
(void) flags;
291-
errno = ENOSYS;
292-
return -1;
293-
#endif
294-
}
295-
296-
static int
297-
syscall_fsmount (int fsfd, unsigned int flags, unsigned int attr_flags)
298-
{
299-
#if defined __NR_fsmount
300-
return (int) syscall (__NR_fsmount, fsfd, flags, attr_flags);
301-
#else
302-
(void) fsfd;
303-
(void) flags;
304-
(void) attr_flags;
305-
errno = ENOSYS;
306-
return -1;
307-
#endif
308-
}
309-
310-
static int
311-
syscall_fsconfig (int fsfd, unsigned int cmd, const char *key, const void *val, int aux)
312-
{
313-
#if defined __NR_fsconfig
314-
return (int) syscall (__NR_fsconfig, fsfd, cmd, key, val, aux);
315-
#else
316-
(void) fsfd;
317-
(void) cmd;
318-
(void) key;
319-
(void) val;
320-
(void) aux;
321-
errno = ENOSYS;
322-
return -1;
323-
#endif
324-
}
325-
326-
static int
327-
syscall_move_mount (int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned int flags)
328-
329-
{
330-
#if defined __NR_move_mount
331-
return (int) syscall (__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
332-
#else
333-
(void) from_dfd;
334-
(void) from_pathname;
335-
(void) to_dfd;
336-
(void) to_pathname;
337-
(void) flags;
338-
errno = ENOSYS;
339-
return -1;
340-
#endif
341-
}
342-
343-
/* ignore this being unused - it's (currently) only unused if not building with systemd,
344-
but conditioning the definition of syscall_open_tree on HAVE_SYSTEMD seems pretty silly */
345-
__attribute__ ((unused)) static int
346-
syscall_open_tree (int dfd, const char *pathname, unsigned int flags)
347-
348-
{
349-
#if defined __NR_open_tree
350-
return (int) syscall (__NR_open_tree, dfd, pathname, flags);
351-
#else
352-
(void) dfd;
353-
(void) pathname;
354-
(void) flags;
355-
errno = ENOSYS;
356-
return -1;
357-
#endif
358-
}
359-
360-
struct mount_attr_s
361-
{
362-
uint64_t attr_set;
363-
uint64_t attr_clr;
364-
uint64_t propagation;
365-
uint64_t userns_fd;
366-
};
367-
368-
#ifndef MOUNT_ATTR_RDONLY
369-
# define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
370-
#endif
371-
372-
#ifndef MOUNT_ATTR_IDMAP
373-
# define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
374-
#endif
375-
376-
static int
377-
syscall_mount_setattr (int dfd, const char *path, unsigned int flags,
378-
struct mount_attr_s *attr)
379-
{
380-
#ifdef __NR_mount_setattr
381-
return (int) syscall (__NR_mount_setattr, dfd, path, flags, attr, sizeof (*attr));
382-
#else
383-
(void) dfd;
384-
(void) path;
385-
(void) flags;
386-
(void) attr;
387-
errno = ENOSYS;
388-
return -1;
389-
#endif
390-
}
391-
392243
static int
393244
syscall_keyctl_join (const char *name)
394245
{
@@ -1023,9 +874,6 @@ fsopen_mount (const char *type, const char *labeltype, const char *label)
1023874
return syscall_fsmount (fsfd, FSMOUNT_CLOEXEC, 0);
1024875
#else
1025876
(void) type;
1026-
(void) syscall_fsopen;
1027-
(void) syscall_fsconfig;
1028-
(void) syscall_fsmount;
1029877
errno = ENOSYS;
1030878
return -1;
1031879
#endif

0 commit comments

Comments
 (0)