Coverage Report

Created: 2025-12-14 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dbus-broker/src/util/syscall.h
Line
Count
Source
1
#pragma once
2
3
/*
4
 * Syscall Wrappers
5
 *
6
 * The linux syscalls are usually not directly accessible from applications,
7
 * since most standard libraries do not provide wrapper functions. This module
8
 * provides direct syscall wrappers via `syscall(3)' for a set of otherwise
9
 * unavailable syscalls.
10
 */
11
12
#include <stdlib.h>
13
#include <sys/resource.h>
14
#include <sys/syscall.h>
15
16
/**
17
 * syscall_memfd_create() - wrapper for memfd_create(2) syscall
18
 * @name:       name for memfd inode
19
 * @flags:      memfd flags
20
 *
21
 * This is a wrapper for the memfd_create(2) syscall. Currently, no user-space
22
 * wrapper is exported by any libc.
23
 *
24
 * Return: New memfd file-descriptor on success, -1 on failure.
25
 */
26
0
static inline int syscall_memfd_create(const char *name, unsigned int flags) {
27
        /* Make Travis happy. */
28
0
#if defined __NR_memfd_create
29
0
        long nr = __NR_memfd_create;
30
#elif defined __x86_64__
31
        long nr = 319;
32
#elif defined __i386__
33
        long nr = 356;
34
#else
35
#  error "__NR_memfd_create is undefined"
36
#endif
37
0
        return (int)syscall(nr, name, flags);
38
0
}
39
40
/**
41
 * syscall_pidfd_open() - wrapper for pidfd_open(2) syscall
42
 * @pid:        pid to open
43
 * @flags:      pidfd flags
44
 *
45
 * This is a wrapper for the pidfd_open(2) syscall. Only a very recent version
46
 * of glibc (2.36) exports a wrapper for this syscall, so we provide our own
47
 * for compatibility with other libc implementations.
48
 *
49
 * Return: New pidfd file-descriptor on success, -1 on failure.
50
 */
51
0
static inline int syscall_pidfd_open(pid_t pid, unsigned int flags) {
52
0
#if defined __NR_pidfd_open
53
0
        long nr = __NR_pidfd_open;
54
0
#elif defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || defined(__arm__)
55
0
        long nr = 434;
56
0
#else
57
0
#  error "__NR_pidfd_open is undefined"
58
0
#endif
59
0
        return (int)syscall(nr, pid, flags);
60
0
}