• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2014 The ChromiumOS Authors
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #if defined(__i386__) || defined(__x86_64__)
7 #include <asm/prctl.h>
8 #endif /* __i386__ || __x86_64__ */
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <linux/fd.h>
12 #include <linux/fs.h>
13 #include <linux/loop.h>
14 #include <linux/mman.h>
15 #include <linux/net.h>
16 #include <linux/prctl.h>
17 #include <linux/random.h>
18 #include <linux/sched.h>
19 #include <linux/serial.h>
20 #include <linux/sockios.h>
21 #include <linux/termios.h>
22 #include <signal.h>
23 #include <stddef.h>
24 #include <sys/mman.h>
25 #include <sys/resource.h>
26 #include <sys/socket.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 
30 #include "arch.h"
31 
32 /* These defines use C structures that are not defined in the same headers which
33  * cause our CPP logic to fail w/undefined identifiers.  Remove them to avoid
34  * build errors on such broken systems.
35  */
36 #undef BLKTRACESETUP
37 #undef FS_IOC_FIEMAP
38 
39 /* The old glibc bundled with the Android host toolchain is missing some ioctl
40  * definitions used by minijail policy in crosvm and other projects. Locally
41  * define them below.
42  * This UAPI is taken from sanitized bionic headers.
43  */
44 
45 /* <linux/fs.h> */
46 #if !defined(FS_IOC_FSGETXATTR) && !defined(FS_IOC_FSSETXATTR)
47 struct fsxattr {
48 	__u32 fsx_xflags;
49 	__u32 fsx_extsize;
50 	__u32 fsx_nextents;
51 	__u32 fsx_projid;
52 	__u32 fsx_cowextsize;
53 	unsigned char fsx_pad[8];
54 };
55 #define FS_IOC_FSGETXATTR _IOR('X', 31, struct fsxattr)
56 #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)
57 #endif /* !FS_IOC_FSGETXATTR && !FS_IOC_FSSETXATTR */
58 
59 /* <linux/fscrypt.h> */
60 #if !defined(FS_IOC_SET_ENCRYPTION_POLICY) &&                                  \
61     !defined(FS_IOC_GET_ENCRYPTION_POLICY)
62 #define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
63 struct fscrypt_policy_v1 {
64 	__u8 version;
65 	__u8 contents_encryption_mode;
66 	__u8 filenames_encryption_mode;
67 	__u8 flags;
68 	__u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
69 };
70 #define fscrypt_policy		     fscrypt_policy_v1
71 #define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy)
72 #define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy)
73 #endif /* !FS_IOC_SET_ENCRYPTION_POLICY && !FS_IOC_GET_ENCRYPTION_POLICY */
74 #if !defined(FS_IOC_GET_ENCRYPTION_POLICY_EX)
75 #define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9])
76 #endif
77 
78 #if !defined(MADV_FREE)
79 #define MADV_FREE 8
80 #endif
81