Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include <stdbool.h>
5 :
6 : #include "macro.h"
7 :
8 : enum {
9 : VIRTUALIZATION_NONE = 0,
10 :
11 : VIRTUALIZATION_VM_FIRST,
12 : VIRTUALIZATION_KVM = VIRTUALIZATION_VM_FIRST,
13 : VIRTUALIZATION_QEMU,
14 : VIRTUALIZATION_BOCHS,
15 : VIRTUALIZATION_XEN,
16 : VIRTUALIZATION_UML,
17 : VIRTUALIZATION_VMWARE,
18 : VIRTUALIZATION_ORACLE,
19 : VIRTUALIZATION_MICROSOFT,
20 : VIRTUALIZATION_ZVM,
21 : VIRTUALIZATION_PARALLELS,
22 : VIRTUALIZATION_BHYVE,
23 : VIRTUALIZATION_QNX,
24 : VIRTUALIZATION_ACRN,
25 : VIRTUALIZATION_VM_OTHER,
26 : VIRTUALIZATION_VM_LAST = VIRTUALIZATION_VM_OTHER,
27 :
28 : VIRTUALIZATION_CONTAINER_FIRST,
29 : VIRTUALIZATION_SYSTEMD_NSPAWN = VIRTUALIZATION_CONTAINER_FIRST,
30 : VIRTUALIZATION_LXC_LIBVIRT,
31 : VIRTUALIZATION_LXC,
32 : VIRTUALIZATION_OPENVZ,
33 : VIRTUALIZATION_DOCKER,
34 : VIRTUALIZATION_PODMAN,
35 : VIRTUALIZATION_RKT,
36 : VIRTUALIZATION_WSL,
37 : VIRTUALIZATION_CONTAINER_OTHER,
38 : VIRTUALIZATION_CONTAINER_LAST = VIRTUALIZATION_CONTAINER_OTHER,
39 :
40 : _VIRTUALIZATION_MAX,
41 : _VIRTUALIZATION_INVALID = -1
42 : };
43 :
44 2 : static inline bool VIRTUALIZATION_IS_VM(int x) {
45 2 : return x >= VIRTUALIZATION_VM_FIRST && x <= VIRTUALIZATION_VM_LAST;
46 : }
47 :
48 3 : static inline bool VIRTUALIZATION_IS_CONTAINER(int x) {
49 3 : return x >= VIRTUALIZATION_CONTAINER_FIRST && x <= VIRTUALIZATION_CONTAINER_LAST;
50 : }
51 :
52 : int detect_vm(void);
53 : int detect_container(void);
54 : int detect_virtualization(void);
55 :
56 : int running_in_userns(void);
57 : int running_in_chroot(void);
58 :
59 : const char *virtualization_to_string(int v) _const_;
60 : int virtualization_from_string(const char *s) _pure_;
|