-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqemu.sh
131 lines (111 loc) · 4.15 KB
/
qemu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
set -ex
main() {
local version=2.10.0
local arch=$1 \
os=$2 \
td=$(mktemp -d)
local dependencies=(
autoconf
automake
bzip2
curl
g++
libglib2.0-dev
libtool
make
patch
pkg-config
zlib1g-dev
)
apt-get update
local purge_list=()
for dep in ${dependencies[@]}; do
if ! dpkg -L $dep; then
apt-get install --no-install-recommends -y $dep
purge_list+=( $dep )
fi
done
pushd $td
curl -L http://wiki.qemu-project.org/download/qemu-$version.tar.bz2 | \
tar --strip-components=1 -xj
# Allow qemu to run android (bionic libc) binaries
# https://lists.nongnu.org/archive/html/qemu-trivial/2017-10/msg00025.html
# https://lists.nongnu.org/archive/html/qemu-trivial/2017-10/msg00023.html
if [[ "$os" == "android" ]]; then
patch -p1 <<'EOF'
diff -ur qemu-2.10.0/linux-user/elfload.c qemu-2.10.0.new/linux-user/elfload.c
--- qemu-2.10.0/linux-user/elfload.c 2017-09-27 11:27:13.866595788 -0300
+++ qemu-2.10.0.new/linux-user/elfload.c 2017-09-27 11:58:30.662613425 -0300
@@ -1354,7 +1354,7 @@
~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1))
#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1))
-#define DLINFO_ITEMS 14
+#define DLINFO_ITEMS 15
static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)
{
@@ -1782,6 +1782,7 @@
NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP);
NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK));
NEW_AUX_ENT(AT_RANDOM, (abi_ulong) u_rand_bytes);
+ NEW_AUX_ENT(AT_SECURE, (abi_ulong) (getuid() != geteuid() || getgid() != getegid()));
#ifdef ELF_HWCAP2
NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2);
diff -ur qemu-2.10.0/linux-user/ioctls.h qemu-2.10.0.new/linux-user/ioctls.h
--- qemu-2.10.0/linux-user/ioctls.h 2017-09-27 11:27:13.858595669 -0300
+++ qemu-2.10.0.new/linux-user/ioctls.h 2017-09-27 11:43:40.613299859 -0300
@@ -173,6 +173,11 @@
IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval)))
IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec)))
+ IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RNDADDTOENTCNT, IOC_W, MK_PTR(TYPE_INT))
+ IOCTL(RNDZAPENTCNT, 0, TYPE_NULL)
+ IOCTL(RNDCLEARPOOL, 0, TYPE_NULL)
+
IOCTL(CDROMPAUSE, 0, TYPE_NULL)
IOCTL(CDROMSTART, 0, TYPE_NULL)
IOCTL(CDROMSTOP, 0, TYPE_NULL)
diff -ur qemu-2.10.0/linux-user/syscall.c qemu-2.10.0.new/linux-user/syscall.c
--- qemu-2.10.0/linux-user/syscall.c 2017-09-27 11:27:13.862595729 -0300
+++ qemu-2.10.0.new/linux-user/syscall.c 2017-09-27 11:44:26.133987660 -0300
@@ -59,6 +59,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/errqueue.h>
+#include <linux/random.h>
#include "qemu-common.h"
#ifdef CONFIG_TIMERFD
#include <sys/timerfd.h>
diff -ur qemu-2.10.0/linux-user/syscall_defs.h qemu-2.10.0.new/linux-user/syscall_defs.h
--- qemu-2.10.0/linux-user/syscall_defs.h 2017-09-27 11:27:13.862595729 -0300
+++ qemu-2.10.0.new/linux-user/syscall_defs.h 2017-09-27 11:46:09.303545817 -0300
@@ -1060,6 +1060,13 @@ struct target_pollfd {
#define TARGET_SIOCGIWNAME 0x8B01 /* get name == wireless protocol */
+/* From <linux/random.h> */
+
+#define TARGET_RNDGETENTCNT TARGET_IOR('R', 0x00, int)
+#define TARGET_RNDADDTOENTCNT TARGET_IOW('R', 0x01, int)
+#define TARGET_RNDZAPENTCNT TARGET_IO('R', 0x04)
+#define TARGET_RNDCLEARPOOL TARGET_IO('R', 0x06)
+
/* From <linux/fs.h> */
#define TARGET_BLKROSET TARGET_IO(0x12,93) /* set device read-only (0 = read-write) */
EOF
fi
./configure \
--disable-kvm \
--disable-vnc \
--enable-user \
--static \
--target-list=$arch-linux-user
nice make -j$(nproc)
make install
# HACK the binfmt_misc interpreter we'll use expects the QEMU binary to be
# in /usr/bin. Create an appropriate symlink
ln -s /usr/local/bin/qemu-$arch /usr/bin/qemu-$arch-static
# Clean up
apt-get purge --auto-remove -y ${purge_list[@]}
popd
rm -rf $td
rm $0
}
main "${@}"