blob: 8a09adb6d38607db805c3dd6f6fa5f5c40abbdd7 [file] [log] [blame]
Alistair Delva3b58ccb2020-08-24 13:54:16 -07001/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
Dan Willemsen2acbec52017-09-14 17:28:36 -07006#if defined(__i386__) || defined(__x86_64__)
7#include <asm/prctl.h>
Alistair Delva3b58ccb2020-08-24 13:54:16 -07008#endif /* __i386__ || __x86_64__ */
Dan Willemsen2acbec52017-09-14 17:28:36 -07009#include <errno.h>
10#include <fcntl.h>
Trent Beginfc4e0a42019-10-30 15:15:45 -060011#include <linux/fd.h>
Mike Frysinger6f4e93d2018-05-23 05:05:35 -040012#include <linux/fs.h>
Trent Beginfc4e0a42019-10-30 15:15:45 -060013#include <linux/loop.h>
Luis Hector Chavez998146c2018-07-31 09:53:29 -070014#include <linux/mman.h>
Ben Chan4b5aae22019-03-27 16:18:13 -070015#include <linux/net.h>
Dan Willemsen2acbec52017-09-14 17:28:36 -070016#include <linux/prctl.h>
17#include <linux/sched.h>
18#include <linux/serial.h>
Ben Chanb7c57cd2019-03-28 12:39:34 -070019#include <linux/sockios.h>
Dan Willemsen2acbec52017-09-14 17:28:36 -070020#include <linux/termios.h>
Dan Willemsen2acbec52017-09-14 17:28:36 -070021#include <signal.h>
Trent Beginfc4e0a42019-10-30 15:15:45 -060022#include <stddef.h>
Josh Gao1fc33172018-01-17 15:27:34 -080023#include <sys/mman.h>
Dan Willemsen2acbec52017-09-14 17:28:36 -070024#include <sys/resource.h>
Mike Frysingerf3bd69a2018-01-18 15:50:47 -050025#include <sys/socket.h>
26#include <sys/stat.h>
Dan Willemsen2acbec52017-09-14 17:28:36 -070027#include <sys/types.h>
Mike Frysinger6f4e93d2018-05-23 05:05:35 -040028
Luis Hector Chavezf6f26252019-12-13 08:04:50 -080029#include "arch.h"
30
Alistair Delva3b58ccb2020-08-24 13:54:16 -070031/* These defines use C structures that are not defined in the same headers which
32 * cause our CPP logic to fail w/undefined identifiers. Remove them to avoid
33 * build errors on such broken systems.
34 */
Mike Frysinger6f4e93d2018-05-23 05:05:35 -040035#undef BLKTRACESETUP
36#undef FS_IOC_FIEMAP
Alistair Delva3b58ccb2020-08-24 13:54:16 -070037
38/* The old glibc bundled with the Android host toolchain is missing some ioctl
39 * definitions used by minijail policy in crosvm and other projects. Locally
40 * define them below.
41 * This UAPI is taken from sanitized bionic headers.
42 */
43
44/* <linux/fs.h> */
45#if !defined(FS_IOC_FSGETXATTR) && !defined(FS_IOC_FSSETXATTR)
46struct fsxattr {
47 __u32 fsx_xflags;
48 __u32 fsx_extsize;
49 __u32 fsx_nextents;
50 __u32 fsx_projid;
51 __u32 fsx_cowextsize;
52 unsigned char fsx_pad[8];
53};
54#define FS_IOC_FSGETXATTR _IOR('X', 31, struct fsxattr)
55#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)
56#endif /* !FS_IOC_FSGETXATTR && !FS_IOC_FSSETXATTR */
57
58/* <linux/fscrypt.h> */
59#if !defined(FS_IOC_SET_ENCRYPTION_POLICY) && \
60 !defined(FS_IOC_GET_ENCRYPTION_POLICY)
61#define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
62struct fscrypt_policy_v1 {
63 __u8 version;
64 __u8 contents_encryption_mode;
65 __u8 filenames_encryption_mode;
66 __u8 flags;
67 __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
68};
69#define fscrypt_policy fscrypt_policy_v1
70#define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy)
71#define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy)
72#endif /* !FS_IOC_SET_ENCRYPTION_POLICY && !FS_IOC_GET_ENCRYPTION_POLICY */
Jorge E. Moreira39bb48d2021-02-19 00:36:41 -080073#if !defined(FS_IOC_GET_ENCRYPTION_POLICY_EX)
74#define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9])
75#endif