Alistair Delva | 3b58ccb | 2020-08-24 13:54:16 -0700 | [diff] [blame] | 1 | /* 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 Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 6 | #if defined(__i386__) || defined(__x86_64__) |
| 7 | #include <asm/prctl.h> |
Alistair Delva | 3b58ccb | 2020-08-24 13:54:16 -0700 | [diff] [blame] | 8 | #endif /* __i386__ || __x86_64__ */ |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <fcntl.h> |
Trent Begin | fc4e0a4 | 2019-10-30 15:15:45 -0600 | [diff] [blame] | 11 | #include <linux/fd.h> |
Mike Frysinger | 6f4e93d | 2018-05-23 05:05:35 -0400 | [diff] [blame] | 12 | #include <linux/fs.h> |
Trent Begin | fc4e0a4 | 2019-10-30 15:15:45 -0600 | [diff] [blame] | 13 | #include <linux/loop.h> |
Luis Hector Chavez | 998146c | 2018-07-31 09:53:29 -0700 | [diff] [blame] | 14 | #include <linux/mman.h> |
Ben Chan | 4b5aae2 | 2019-03-27 16:18:13 -0700 | [diff] [blame] | 15 | #include <linux/net.h> |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 16 | #include <linux/prctl.h> |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/serial.h> |
Ben Chan | b7c57cd | 2019-03-28 12:39:34 -0700 | [diff] [blame] | 19 | #include <linux/sockios.h> |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 20 | #include <linux/termios.h> |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 21 | #include <signal.h> |
Trent Begin | fc4e0a4 | 2019-10-30 15:15:45 -0600 | [diff] [blame] | 22 | #include <stddef.h> |
Josh Gao | 1fc3317 | 2018-01-17 15:27:34 -0800 | [diff] [blame] | 23 | #include <sys/mman.h> |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 24 | #include <sys/resource.h> |
Mike Frysinger | f3bd69a | 2018-01-18 15:50:47 -0500 | [diff] [blame] | 25 | #include <sys/socket.h> |
| 26 | #include <sys/stat.h> |
Dan Willemsen | 2acbec5 | 2017-09-14 17:28:36 -0700 | [diff] [blame] | 27 | #include <sys/types.h> |
Mike Frysinger | 6f4e93d | 2018-05-23 05:05:35 -0400 | [diff] [blame] | 28 | |
Luis Hector Chavez | f6f2625 | 2019-12-13 08:04:50 -0800 | [diff] [blame] | 29 | #include "arch.h" |
| 30 | |
Alistair Delva | 3b58ccb | 2020-08-24 13:54:16 -0700 | [diff] [blame] | 31 | /* 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 Frysinger | 6f4e93d | 2018-05-23 05:05:35 -0400 | [diff] [blame] | 35 | #undef BLKTRACESETUP |
| 36 | #undef FS_IOC_FIEMAP |
Alistair Delva | 3b58ccb | 2020-08-24 13:54:16 -0700 | [diff] [blame] | 37 | |
| 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) |
| 46 | struct 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 |
| 62 | struct 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. Moreira | 39bb48d | 2021-02-19 00:36:41 -0800 | [diff] [blame] | 73 | #if !defined(FS_IOC_GET_ENCRYPTION_POLICY_EX) |
| 74 | #define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9]) |
| 75 | #endif |