diff --git a/tur-multilib/hangover-libqemu/0000-android-config-support.patch b/tur-multilib/hangover-libqemu/0000-android-config-support.patch new file mode 100644 index 0000000000..ce6a16623b --- /dev/null +++ b/tur-multilib/hangover-libqemu/0000-android-config-support.patch @@ -0,0 +1,53 @@ +diff -uNr qemu-5.2.0/configure qemu-5.2.0.mod/configure +--- qemu-5.2.0/configure 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/configure 2020-12-09 16:24:26.073781672 +0200 +@@ -2931,6 +2931,8 @@ + fi + + has_libgcrypt() { ++ return 0 ++ + if ! has "libgcrypt-config" + then + return 1 +@@ -3000,10 +3002,7 @@ + # Debian has removed -lgpg-error from libgcrypt-config + # as it "spreads unnecessary dependencies" which in + # turn breaks static builds... +- if test "$static" = "yes" +- then +- gcrypt_libs="$gcrypt_libs -lgpg-error" +- fi ++ gcrypt_libs="$gcrypt_libs -lgpg-error" + + # Link test to make sure the given libraries work (e.g for static). + write_c_skeleton +@@ -4097,6 +4096,7 @@ + if compile_prog "" "" ; then + signalfd=yes + fi ++signalfd=no + + # check if optreset global is declared by + optreset="no" +@@ -5973,6 +5973,7 @@ + if test "$darwin" = "yes" ; then + echo "CONFIG_DARWIN=y" >> $config_host_mak + fi ++ivshmem=no + + if test "$solaris" = "yes" ; then + echo "CONFIG_SOLARIS=y" >> $config_host_mak +@@ -6088,9 +6089,9 @@ + if test "$posix_fallocate" = "yes" ; then + echo "CONFIG_POSIX_FALLOCATE=y" >> $config_host_mak + fi +-if test "$sync_file_range" = "yes" ; then +- echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak +-fi ++#if test "$sync_file_range" = "yes" ; then ++# echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak ++#fi + if test "$fiemap" = "yes" ; then + echo "CONFIG_FIEMAP=y" >> $config_host_mak + fi diff --git a/tur-multilib/hangover-libqemu/0001-fix-hardcoded-paths.patch b/tur-multilib/hangover-libqemu/0001-fix-hardcoded-paths.patch new file mode 100644 index 0000000000..0fd9ebbc75 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0001-fix-hardcoded-paths.patch @@ -0,0 +1,183 @@ +diff -uNr qemu-5.2.0/block.c qemu-5.2.0.mod/block.c +--- qemu-5.2.0/block.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/block.c 2020-12-09 15:25:10.305910980 +0200 +@@ -763,7 +763,7 @@ + const char *tmpdir; + tmpdir = getenv("TMPDIR"); + if (!tmpdir) { +- tmpdir = "/var/tmp"; ++ tmpdir = "@TERMUX_PREFIX@/tmp"; + } + if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) { + return -EOVERFLOW; +diff -uNr qemu-5.2.0/hw/hppa/machine.c qemu-5.2.0.mod/hw/hppa/machine.c +--- qemu-5.2.0/hw/hppa/machine.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/hw/hppa/machine.c 2020-12-09 15:27:27.518908660 +0200 +@@ -100,19 +100,19 @@ + fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, ram_size); + + val = cpu_to_le64(MIN_SEABIOS_HPPA_VERSION); +- fw_cfg_add_file(fw_cfg, "/etc/firmware-min-version", ++ fw_cfg_add_file(fw_cfg, "@TERMUX_PREFIX@/etc/firmware-min-version", + g_memdup(&val, sizeof(val)), sizeof(val)); + + val = cpu_to_le64(HPPA_TLB_ENTRIES); +- fw_cfg_add_file(fw_cfg, "/etc/cpu/tlb_entries", ++ fw_cfg_add_file(fw_cfg, "@TERMUX_PREFIX@/etc/cpu/tlb_entries", + g_memdup(&val, sizeof(val)), sizeof(val)); + + val = cpu_to_le64(HPPA_BTLB_ENTRIES); +- fw_cfg_add_file(fw_cfg, "/etc/cpu/btlb_entries", ++ fw_cfg_add_file(fw_cfg, "@TERMUX_PREFIX@/etc/cpu/btlb_entries", + g_memdup(&val, sizeof(val)), sizeof(val)); + + val = cpu_to_le64(HPA_POWER_BUTTON); +- fw_cfg_add_file(fw_cfg, "/etc/power-button-addr", ++ fw_cfg_add_file(fw_cfg, "@TERMUX_PREFIX@/etc/power-button-addr", + g_memdup(&val, sizeof(val)), sizeof(val)); + + fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ms->boot_order[0]); +diff -uNr qemu-5.2.0/hw/usb/ccid-card-emulated.c qemu-5.2.0.mod/hw/usb/ccid-card-emulated.c +--- qemu-5.2.0/hw/usb/ccid-card-emulated.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/hw/usb/ccid-card-emulated.c 2020-12-09 15:28:01.551157409 +0200 +@@ -417,7 +417,7 @@ + event_notifier_cleanup(&card->notifier); + } + +-#define CERTIFICATES_DEFAULT_DB "/etc/pki/nssdb" ++#define CERTIFICATES_DEFAULT_DB "@TERMUX_PREFIX@/etc/pki/nssdb" + #define CERTIFICATES_ARGS_TEMPLATE\ + "db=\"%s\" use_hw=no soft=(,Virtual Reader,CAC,,%s,%s,%s)" + +diff -uNr qemu-5.2.0/linux-user/syscall.c qemu-5.2.0.mod/linux-user/syscall.c +--- qemu-5.2.0/linux-user/syscall.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/syscall.c 2020-12-09 15:25:10.309911009 +0200 +@@ -8045,7 +8045,7 @@ + /* create temporary file to map stat to */ + tmpdir = getenv("TMPDIR"); + if (!tmpdir) +- tmpdir = "/tmp"; ++ tmpdir = "@TERMUX_PREFIX@/tmp"; + snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); + fd = mkstemp(filename); + if (fd < 0) { +diff -uNr qemu-5.2.0/migration/exec.c qemu-5.2.0.mod/migration/exec.c +--- qemu-5.2.0/migration/exec.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/migration/exec.c 2020-12-09 15:25:10.309911009 +0200 +@@ -28,7 +28,7 @@ + void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp) + { + QIOChannel *ioc; +- const char *argv[] = { "/bin/sh", "-c", command, NULL }; ++ const char *argv[] = { "@TERMUX_PREFIX@/bin/sh", "-c", command, NULL }; + + trace_migration_exec_outgoing(command); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv, +@@ -55,7 +55,7 @@ + void exec_start_incoming_migration(const char *command, Error **errp) + { + QIOChannel *ioc; +- const char *argv[] = { "/bin/sh", "-c", command, NULL }; ++ const char *argv[] = { "@TERMUX_PREFIX@/bin/sh", "-c", command, NULL }; + + trace_migration_exec_incoming(command); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv, +diff -uNr qemu-5.2.0/net/tap.c qemu-5.2.0.mod/net/tap.c +--- qemu-5.2.0/net/tap.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/net/tap.c 2020-12-09 15:25:10.309911009 +0200 +@@ -533,7 +533,7 @@ + *parg++ = helper_cmd; + *parg++ = NULL; + +- execv("/bin/sh", args); ++ execv("@TERMUX_PREFIX@/bin/sh", args); + g_free(helper_cmd); + } else { + /* assume helper is just the executable path name */ +diff -uNr qemu-5.2.0/qemu-nbd.c qemu-5.2.0.mod/qemu-nbd.c +--- qemu-5.2.0/qemu-nbd.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/qemu-nbd.c 2020-12-09 15:25:10.313911038 +0200 +@@ -52,7 +52,6 @@ + #define HAVE_NBD_DEVICE 0 + #endif + +-#define SOCKET_PATH "/var/lock/qemu-nbd-%s" + #define QEMU_NBD_OPT_CACHE 256 + #define QEMU_NBD_OPT_AIO 257 + #define QEMU_NBD_OPT_DISCARD 258 +@@ -91,7 +90,7 @@ + " -p, --port=PORT port to listen on (default `%d')\n" + " -b, --bind=IFACE interface to bind to (default `0.0.0.0')\n" + " -k, --socket=PATH path to the unix socket\n" +-" (default '"SOCKET_PATH"')\n" ++" (default '@TERMUX_PREFIX@/tmp/nbd-%s')\n" + " -e, --shared=NUM device can be shared by NUM clients (default '1')\n" + " -t, --persistent don't exit on the last connection\n" + " -v, --verbose display extra debugging information\n" +@@ -964,7 +963,7 @@ + + if (device != NULL && sockpath == NULL) { + sockpath = g_malloc(128); +- snprintf(sockpath, 128, SOCKET_PATH, basename(device)); ++ snprintf(sockpath, 128, "@TERMUX_PREFIX@/tmp/nbd-%s", basename(device)); + } + + server = qio_net_listener_new(); +diff -uNr qemu-5.2.0/slirp/src/slirp.c qemu-5.2.0.mod/slirp/src/slirp.c +--- qemu-5.2.0/slirp/src/slirp.c 2020-12-08 19:00:58.000000000 +0200 ++++ qemu-5.2.0.mod/slirp/src/slirp.c 2020-12-09 15:25:10.313911038 +0200 +@@ -133,7 +133,7 @@ + return 0; + } + old_stat = *cached_stat; +- if (stat("/etc/resolv.conf", cached_stat) != 0) { ++ if (stat("@TERMUX_PREFIX@/etc/resolv.conf", cached_stat) != 0) { + return -1; + } + if (cached_stat->st_dev == old_stat.st_dev && +@@ -157,7 +157,7 @@ + void *tmp_addr = alloca(addrlen); + unsigned if_index; + +- f = fopen("/etc/resolv.conf", "r"); ++ f = fopen("@TERMUX_PREFIX@/etc/resolv.conf", "r"); + if (!f) + return -1; + +diff -uNr qemu-5.2.0/tcg/tcg.c qemu-5.2.0.mod/tcg/tcg.c +--- qemu-5.2.0/tcg/tcg.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/tcg/tcg.c 2020-12-09 15:25:10.313911038 +0200 +@@ -4628,7 +4628,8 @@ + /* Enable this block to be able to debug the ELF image file creation. + One can use readelf, objdump, or other inspection utilities. */ + { +- FILE *f = fopen("/tmp/qemu.jit", "w+b"); ++ FILE *f = fopen("@TERMUX_PREFIX@/tmp/qemu.jit", "w+b"); ++ + if (f) { + if (fwrite(img, img_size, 1, f) != img_size) { + /* Avoid stupid unused return value warning for fwrite. */ +diff -uNr qemu-5.2.0/util/module.c qemu-5.2.0.mod/util/module.c +--- qemu-5.2.0/util/module.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/util/module.c 2020-12-09 15:30:49.368390113 +0200 +@@ -246,7 +246,7 @@ + version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION), + G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~", + '_'); +- dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir); ++ dirs[n_dirs++] = g_strdup_printf("@TERMUX_PREFIX@/var/run/qemu/%s", version_dir); + #endif + + assert(n_dirs <= ARRAY_SIZE(dirs)); +diff -uNr qemu-5.2.0/util/qemu-sockets.c qemu-5.2.0.mod/util/qemu-sockets.c +--- qemu-5.2.0/util/qemu-sockets.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/util/qemu-sockets.c 2020-12-09 15:25:10.313911038 +0200 +@@ -900,7 +900,7 @@ + path = saddr->path; + } else { + const char *tmpdir = getenv("TMPDIR"); +- tmpdir = tmpdir ? tmpdir : "/tmp"; ++ tmpdir = tmpdir ? tmpdir : "@TERMUX_PREFIX@/tmp"; + path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir); + } + diff --git a/tur-multilib/hangover-libqemu/0002-fix-soundcard.h-location.patch b/tur-multilib/hangover-libqemu/0002-fix-soundcard.h-location.patch new file mode 100644 index 0000000000..4d453be0f6 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0002-fix-soundcard.h-location.patch @@ -0,0 +1,12 @@ +diff -uNr qemu-4.2.0/audio/ossaudio.c qemu-4.2.0.mod/audio/ossaudio.c +--- qemu-4.2.0/audio/ossaudio.c 2019-12-12 20:20:47.000000000 +0200 ++++ qemu-4.2.0.mod/audio/ossaudio.c 2019-12-15 00:04:31.280813450 +0200 +@@ -24,7 +24,7 @@ + + #include "qemu/osdep.h" + #include +-#include ++#include + #include "qemu/main-loop.h" + #include "qemu/module.h" + #include "qemu/host-utils.h" diff --git a/tur-multilib/hangover-libqemu/0003-fix-time_nsec-defs.patch b/tur-multilib/hangover-libqemu/0003-fix-time_nsec-defs.patch new file mode 100644 index 0000000000..900a7f43b7 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0003-fix-time_nsec-defs.patch @@ -0,0 +1,22 @@ +diff -uNr qemu-4.2.0/fsdev/9p-marshal.h qemu-4.2.0.mod/fsdev/9p-marshal.h +--- qemu-4.2.0/fsdev/9p-marshal.h 2019-12-12 20:20:47.000000000 +0200 ++++ qemu-4.2.0.mod/fsdev/9p-marshal.h 2019-12-15 00:09:59.586176320 +0200 +@@ -48,6 +48,18 @@ + int64_t mtime_nsec; + } V9fsIattr; + ++#ifdef st_atime_nsec ++# undef st_atime_nsec ++#endif ++ ++#ifdef st_mtime_nsec ++# undef st_mtime_nsec ++#endif ++ ++#ifdef st_ctime_nsec ++# undef st_ctime_nsec ++#endif ++ + typedef struct V9fsStatDotl { + uint64_t st_result_mask; + V9fsQID qid; diff --git a/tur-multilib/hangover-libqemu/0004-add-missing-telldir-seekdir.patch b/tur-multilib/hangover-libqemu/0004-add-missing-telldir-seekdir.patch new file mode 100644 index 0000000000..439b6d8199 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0004-add-missing-telldir-seekdir.patch @@ -0,0 +1,74 @@ +diff -uNr qemu-4.2.0/hw/9pfs/9p-local.c qemu-4.2.0.mod/hw/9pfs/9p-local.c +--- qemu-4.2.0/hw/9pfs/9p-local.c 2019-12-12 20:20:47.000000000 +0200 ++++ qemu-4.2.0.mod/hw/9pfs/9p-local.c 2019-12-15 00:12:11.073725293 +0200 +@@ -535,9 +535,23 @@ + rewinddir(fs->dir.stream); + } + ++struct DIR { ++ int fd_; ++}; ++ ++static long android_telldir(struct DIR *dirp) ++{ ++ return (long) lseek(dirp->fd_, 0, SEEK_CUR); ++} ++ ++static void android_seekdir(DIR *dirp, long loc) ++{ ++ (void) lseek(dirp->fd_, loc, SEEK_SET); ++} ++ + static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs) + { +- return telldir(fs->dir.stream); ++ return android_telldir(fs->dir.stream); + } + + static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name) +@@ -571,7 +585,7 @@ + + static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) + { +- seekdir(fs->dir.stream, off); ++ android_seekdir(fs->dir.stream, off); + } + + static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs, +diff -uNr qemu-4.2.0/hw/9pfs/9p-proxy.c qemu-4.2.0.mod/hw/9pfs/9p-proxy.c +--- qemu-4.2.0/hw/9pfs/9p-proxy.c 2019-12-12 20:20:47.000000000 +0200 ++++ qemu-4.2.0.mod/hw/9pfs/9p-proxy.c 2019-12-15 00:12:11.074725297 +0200 +@@ -675,9 +675,23 @@ + rewinddir(fs->dir.stream); + } + ++struct DIR { ++ int fd_; ++}; ++ ++static long android_telldir(struct DIR *dirp) ++{ ++ return (long) lseek(dirp->fd_, 0, SEEK_CUR); ++} ++ ++static void android_seekdir(DIR *dirp, long loc) ++{ ++ (void) lseek(dirp->fd_, loc, SEEK_SET); ++} ++ + static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs) + { +- return telldir(fs->dir.stream); ++ return android_telldir(fs->dir.stream); + } + + static struct dirent *proxy_readdir(FsContext *ctx, V9fsFidOpenState *fs) +@@ -687,7 +701,7 @@ + + static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) + { +- seekdir(fs->dir.stream, off); ++ android_seekdir(fs->dir.stream, off); + } + + static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs, diff --git a/tur-multilib/hangover-libqemu/0005-add-missing-sigorset.patch b/tur-multilib/hangover-libqemu/0005-add-missing-sigorset.patch new file mode 100644 index 0000000000..8759ff83f3 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0005-add-missing-sigorset.patch @@ -0,0 +1,31 @@ +diff -uNr qemu-4.2.0/linux-user/signal.c qemu-4.2.0.mod/linux-user/signal.c +--- qemu-4.2.0/linux-user/signal.c 2019-12-12 20:20:48.000000000 +0200 ++++ qemu-4.2.0.mod/linux-user/signal.c 2019-12-15 00:15:27.954549467 +0200 +@@ -182,6 +182,27 @@ + return atomic_xchg(&ts->signal_pending, 1); + } + ++#ifdef _NSIG_WORDS ++static int sigorset(sigset_t *dest, const sigset_t *a, const sigset_t *b) ++{ ++ int i; ++ if (!dest || !a || !b) ++ return -1; ++ for (i = 0; i < _NSIG_WORDS; i++) ++ dest->sig[i] = a->sig[i] | b->sig[i]; ++ return 0; ++} ++#else ++static int sigorset(sigset_t *dest, const sigset_t *a, const sigset_t *b) ++{ ++ int i; ++ if (!dest || !a || !b) ++ return -1; ++ *dest = *a | *b; ++ return 0; ++} ++#endif ++ + /* Wrapper for sigprocmask function + * Emulates a sigprocmask in a safe way for the guest. Note that set and oldset + * are host signal set, not guest ones. Returns -TARGET_ERESTARTSYS if diff --git a/tur-multilib/hangover-libqemu/0006-fix-sem.h-location.patch b/tur-multilib/hangover-libqemu/0006-fix-sem.h-location.patch new file mode 100644 index 0000000000..cf74f3d1ef --- /dev/null +++ b/tur-multilib/hangover-libqemu/0006-fix-sem.h-location.patch @@ -0,0 +1,12 @@ +diff -uNr qemu-4.2.0/linux-user/strace.c qemu-4.2.0.mod/linux-user/strace.c +--- qemu-4.2.0/linux-user/strace.c 2019-12-12 20:20:48.000000000 +0200 ++++ qemu-4.2.0.mod/linux-user/strace.c 2019-12-15 00:18:22.178280369 +0200 +@@ -1,7 +1,7 @@ + #include "qemu/osdep.h" + #include + #include +-#include ++#include + #include + #include + #include diff --git a/tur-multilib/hangover-libqemu/0007-fix-syscalls.patch b/tur-multilib/hangover-libqemu/0007-fix-syscalls.patch new file mode 100644 index 0000000000..b8ca76bb3e --- /dev/null +++ b/tur-multilib/hangover-libqemu/0007-fix-syscalls.patch @@ -0,0 +1,228 @@ +diff -uNr qemu-5.1.0/linux-user/elfload.c qemu-5.1.0.mod/linux-user/elfload.c +--- qemu-5.1.0/linux-user/elfload.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/linux-user/elfload.c 2020-09-05 17:01:16.823064611 +0300 +@@ -2331,7 +2331,7 @@ + abi_ulong guest_hiaddr) + { + /* In order to use host shmat, we must be able to honor SHMLBA. */ +- uintptr_t align = MAX(SHMLBA, qemu_host_page_size); ++ uintptr_t align = MAX(/* SHMLBA */ getpagesize(), qemu_host_page_size); + + if (have_guest_base) { + pgb_have_guest_base(image_name, guest_loaddr, guest_hiaddr, align); +diff -uNr qemu-5.1.0/linux-user/syscall.c qemu-5.1.0.mod/linux-user/syscall.c +--- qemu-5.1.0/linux-user/syscall.c 2020-09-05 16:58:00.063849385 +0300 ++++ qemu-5.1.0.mod/linux-user/syscall.c 2020-09-05 17:02:57.910949156 +0300 +@@ -45,7 +45,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +@@ -78,12 +78,17 @@ + #endif + + #define termios host_termios ++#define termios2 host_termios2 ++#define ktermios host_ktermios + #define winsize host_winsize + #define termio host_termio + #define sgttyb host_sgttyb /* same as target */ + #define tchars host_tchars /* same as target */ + #define ltchars host_ltchars /* same as target */ + ++#undef __ASM_GENERIC_TERMBITS_H ++#include ++ + #include + #include + #include +@@ -264,6 +269,59 @@ + #define __NR__llseek __NR_lseek + #endif + ++_syscall0(int, vhangup) ++#ifdef __NR_msgctl ++_syscall3(int, msgctl, int, msqid, int, cmd, struct msqid_ds *, buf) ++#else ++static int ++msgctl (int msqid, int cmd, struct msqid_ds *buf) ++{ ++ return syscall (__NR_ipc, IPCOP_msgctl, msqid, cmd | 0x100, 0, buf); ++} ++#endif ++ ++#ifdef __NR_semget ++_syscall3(int, semget, key_t, key, int, nsems, int, semflg) ++#else ++static int ++semget (key_t key, int nsems, int semflg) ++{ ++ return syscall (__NR_ipc, IPCOP_semget, key, nsems, semflg, NULL); ++} ++#endif ++ ++_syscall2(int, setdomainname, const char *, name, size_t, len) ++#ifdef __NR_msgget ++_syscall2(int, msgget, key_t, key, int, msgflg) ++#else ++static int ++msgget (key_t key, int msgflg) ++{ ++ return syscall(__NR_ipc, 5, IPCOP_msgget, key, msgflg, 0, NULL); ++} ++#endif ++ ++#ifdef _NSIG_WORDS ++static int sigorset(sigset_t *dest, const sigset_t *a, const sigset_t *b) ++{ ++ int i; ++ if (!dest || !a || !b) ++ return -1; ++ for (i = 0; i < _NSIG_WORDS; i++) ++ dest->sig[i] = a->sig[i] | b->sig[i]; ++ return 0; ++} ++#else ++static int sigorset(sigset_t *dest, const sigset_t *a, const sigset_t *b) ++{ ++ int i; ++ if (!dest || !a || !b) ++ return -1; ++ *dest = *a | *b; ++ return 0; ++} ++#endif ++ + /* Newer kernel ports have llseek() instead of _llseek() */ + #if defined(TARGET_NR_llseek) && !defined(TARGET_NR__llseek) + #define TARGET_NR__llseek TARGET_NR_llseek +@@ -837,6 +895,9 @@ + #ifdef TARGET_NR_mq_timedreceive + safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, + size_t, len, unsigned *, prio, const struct timespec *, timeout) ++_syscall1(int, mq_unlink, const char *, name) ++_syscall4(__kernel_mqd_t, mq_open, const char *, name, int, oflag, mode_t, mode, ++ struct mq_attr *, attr) + #endif + /* We do ioctl like this rather than via safe_syscall3 to preserve the + * "third argument might be integer or pointer or not present" behaviour of +@@ -1328,7 +1389,7 @@ + #endif + + #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) +-#include ++#include + + static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr, + abi_ulong target_mq_attr_addr) +@@ -3632,6 +3693,8 @@ + return 0; + } + ++#define semid_ds __kernel_legacy_semid_ds ++ + static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, + abi_ulong target_addr) + { +@@ -3711,6 +3774,16 @@ + abi_ulong __buf; + }; + ++#ifdef __NR_semctl ++_syscall4(int, semctl, int, semid, int, semnum, int, cmd, union semun, arg4) ++#else ++static int semctl(int semid, int semnum, int cmd, union semun arg4) ++{ ++ return syscall(__NR_ipc, IPCOP_semctl, semid, semnum, cmd | 0x100, ++ arg4.__buf); ++} ++#endif ++ + static inline abi_long target_to_host_semarray(int semid, unsigned short **host_array, + abi_ulong target_addr) + { +@@ -3841,7 +3914,7 @@ + case GETPID: + case GETNCNT: + case GETZCNT: +- ret = get_errno(semctl(semid, semnum, cmd, NULL)); ++ ret = get_errno(semctl(semid, semnum, cmd, (union semun) {.buf = NULL})); + break; + } + +@@ -3961,7 +4034,7 @@ + host_md->msg_stime = tswapal(target_md->msg_stime); + host_md->msg_rtime = tswapal(target_md->msg_rtime); + host_md->msg_ctime = tswapal(target_md->msg_ctime); +- host_md->__msg_cbytes = tswapal(target_md->__msg_cbytes); ++ host_md->msg_cbytes = tswapal(target_md->__msg_cbytes); + host_md->msg_qnum = tswapal(target_md->msg_qnum); + host_md->msg_qbytes = tswapal(target_md->msg_qbytes); + host_md->msg_lspid = tswapal(target_md->msg_lspid); +@@ -3982,7 +4055,7 @@ + target_md->msg_stime = tswapal(host_md->msg_stime); + target_md->msg_rtime = tswapal(host_md->msg_rtime); + target_md->msg_ctime = tswapal(host_md->msg_ctime); +- target_md->__msg_cbytes = tswapal(host_md->__msg_cbytes); ++ target_md->__msg_cbytes = tswapal(host_md->msg_cbytes); + target_md->msg_qnum = tswapal(host_md->msg_qnum); + target_md->msg_qbytes = tswapal(host_md->msg_qbytes); + target_md->msg_lspid = tswapal(host_md->msg_lspid); +@@ -4348,7 +4421,7 @@ + abi_ulong mmap_start; + + /* In order to use the host shmat, we need to honor host SHMLBA. */ +- mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, shmlba)); ++ mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(/* SHMLBA */ getpagesize(), shmlba)); + + if (mmap_start == -1) { + errno = ENOMEM; +@@ -5415,6 +5488,9 @@ + + #endif + ++#undef winsize ++#undef termio ++ + IOCTLEntry ioctl_entries[] = { + #define IOCTL(cmd, access, ...) \ + { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, +@@ -8185,7 +8261,7 @@ + unlock_user(p, arg1, 0); + return ret; + #endif +-#ifdef TARGET_NR_stime /* not on alpha */ ++#if 0 //def TARGET_NR_stime /* not on alpha */ + case TARGET_NR_stime: + { + struct timespec ts; +@@ -8249,7 +8325,7 @@ + } + return ret; + #endif +-#if defined(TARGET_NR_futimesat) ++#if 0 && defined(TARGET_NR_futimesat) + case TARGET_NR_futimesat: + { + struct timeval *tvp, tv[2]; +@@ -12008,7 +12084,7 @@ + /* Not implemented for now... */ + /* case TARGET_NR_mq_notify: */ + /* break; */ +- ++#if 0 + case TARGET_NR_mq_getsetattr: + { + struct mq_attr posix_mq_attr_in, posix_mq_attr_out; +@@ -12026,6 +12102,7 @@ + } + return ret; + #endif ++#endif + + #ifdef CONFIG_SPLICE + #ifdef TARGET_NR_tee diff --git a/tur-multilib/hangover-libqemu/0008-fix-struct-member-conflicts.patch b/tur-multilib/hangover-libqemu/0008-fix-struct-member-conflicts.patch new file mode 100644 index 0000000000..34ce36762c --- /dev/null +++ b/tur-multilib/hangover-libqemu/0008-fix-struct-member-conflicts.patch @@ -0,0 +1,75 @@ +diff -uNr qemu-5.2.0/linux-user/aarch64/signal.c qemu-5.2.0.mod/linux-user/aarch64/signal.c +--- qemu-5.2.0/linux-user/aarch64/signal.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/aarch64/signal.c 2020-12-11 14:04:52.426979119 +0200 +@@ -38,7 +38,7 @@ + target_stack_t tuc_stack; + target_sigset_t tuc_sigmask; + /* glibc uses a 1024-bit sigset_t */ +- char __unused[1024 / 8 - sizeof(target_sigset_t)]; ++ char __qemu_unused[1024 / 8 - sizeof(target_sigset_t)]; + /* last for future expansion */ + struct target_sigcontext tuc_mcontext; + }; +diff -uNr qemu-5.2.0/linux-user/arm/signal.c qemu-5.2.0.mod/linux-user/arm/signal.c +--- qemu-5.2.0/linux-user/arm/signal.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/arm/signal.c 2020-12-11 14:04:52.426979119 +0200 +@@ -59,7 +59,7 @@ + target_stack_t tuc_stack; + struct target_sigcontext tuc_mcontext; + target_sigset_t tuc_sigmask; /* mask last for extensibility */ +- char __unused[128 - sizeof(target_sigset_t)]; ++ char __qemu_unused[128 - sizeof(target_sigset_t)]; + abi_ulong tuc_regspace[128] __attribute__((__aligned__(8))); + }; + +diff -uNr qemu-5.2.0/linux-user/riscv/signal.c qemu-5.2.0.mod/linux-user/riscv/signal.c +--- qemu-5.2.0/linux-user/riscv/signal.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/riscv/signal.c 2020-12-11 14:05:42.471408487 +0200 +@@ -41,7 +41,7 @@ + struct target_ucontext *uc_link; + target_stack_t uc_stack; + target_sigset_t uc_sigmask; +- uint8_t __unused[1024 / 8 - sizeof(target_sigset_t)]; ++ uint8_t __qemu_unused[1024 / 8 - sizeof(target_sigset_t)]; + struct target_sigcontext uc_mcontext QEMU_ALIGNED(16); + }; + +diff -uNr qemu-5.2.0/linux-user/syscall_defs.h qemu-5.2.0.mod/linux-user/syscall_defs.h +--- qemu-5.2.0/linux-user/syscall_defs.h 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/syscall_defs.h 2020-12-11 14:04:52.430979153 +0200 +@@ -1929,7 +1929,7 @@ + abi_ulong target_st_mtime_nsec; + abi_ulong target_st_ctime; + abi_ulong target_st_ctime_nsec; +- abi_long __unused[3]; ++ abi_long __qemu_unused[3]; + }; + + #elif defined(TARGET_SH4) +@@ -2016,7 +2016,7 @@ + abi_ulong target_st_ctime; + abi_ulong target_st_ctime_nsec; + +- abi_long __unused[3]; ++ abi_long __qemu_unused[3]; + }; + #elif defined(TARGET_S390X) + struct target_stat { +@@ -2037,7 +2037,7 @@ + abi_ulong target_st_ctime_nsec; + abi_ulong st_blksize; + abi_long st_blocks; +- abi_ulong __unused[3]; ++ abi_ulong __qemu_unused[3]; + }; + #elif defined(TARGET_AARCH64) + #define TARGET_STAT_HAVE_NSEC +@@ -2060,7 +2060,7 @@ + abi_ulong target_st_mtime_nsec; + abi_long target_st_ctime; + abi_ulong target_st_ctime_nsec; +- unsigned int __unused[2]; ++ unsigned int __qemu_unused[2]; + }; + #elif defined(TARGET_XTENSA) + #define TARGET_STAT_HAVE_NSEC diff --git a/tur-multilib/hangover-libqemu/0009-fix-mman.h-defs.patch b/tur-multilib/hangover-libqemu/0009-fix-mman.h-defs.patch new file mode 100644 index 0000000000..1274337bec --- /dev/null +++ b/tur-multilib/hangover-libqemu/0009-fix-mman.h-defs.patch @@ -0,0 +1,220 @@ +diff -uNr qemu-5.1.0/accel/tcg/translate-all.c qemu-5.1.0.mod/accel/tcg/translate-all.c +--- qemu-5.1.0/accel/tcg/translate-all.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/accel/tcg/translate-all.c 2020-09-05 17:06:07.327115262 +0300 +@@ -47,6 +47,8 @@ + #include "exec/ram_addr.h" + #endif + ++#include ++ + #include "exec/cputlb.h" + #include "exec/tb-hash.h" + #include "translate-all.h" +diff -uNr qemu-5.1.0/audio/ossaudio.c qemu-5.1.0.mod/audio/ossaudio.c +--- qemu-5.1.0/audio/ossaudio.c 2020-09-05 16:58:18.803736540 +0300 ++++ qemu-5.1.0.mod/audio/ossaudio.c 2020-09-05 17:06:07.327115262 +0300 +@@ -31,6 +31,8 @@ + #include "audio.h" + #include "trace.h" + ++#include ++ + #define AUDIO_CAP "oss" + #include "audio_int.h" + +diff -uNr qemu-5.1.0/block/file-posix.c qemu-5.1.0.mod/block/file-posix.c +--- qemu-5.1.0/block/file-posix.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/block/file-posix.c 2020-09-05 17:06:07.327115262 +0300 +@@ -59,6 +59,7 @@ + #include + #endif + #ifdef __linux__ ++#include + #include + #include + #include +diff -uNr qemu-5.1.0/contrib/libvhost-user/libvhost-user.c qemu-5.1.0.mod/contrib/libvhost-user/libvhost-user.c +--- qemu-5.1.0/contrib/libvhost-user/libvhost-user.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/contrib/libvhost-user/libvhost-user.c 2020-09-05 17:06:07.327115262 +0300 +@@ -29,6 +29,7 @@ + #include "qemu/compiler.h" + + #if defined(__linux__) ++#include + #include + #include + #include +diff -uNr qemu-5.1.0/hw/vfio/common.c qemu-5.1.0.mod/hw/vfio/common.c +--- qemu-5.1.0/hw/vfio/common.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/hw/vfio/common.c 2020-09-05 17:06:07.331115270 +0300 +@@ -24,6 +24,7 @@ + #include + #endif + #include ++#include + + #include "hw/vfio/vfio-common.h" + #include "hw/vfio/vfio.h" +diff -uNr qemu-5.1.0/hw/vfio/pci-quirks.c qemu-5.1.0.mod/hw/vfio/pci-quirks.c +--- qemu-5.1.0/hw/vfio/pci-quirks.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/hw/vfio/pci-quirks.c 2020-09-05 17:07:16.623274533 +0300 +@@ -27,6 +27,8 @@ + #include "pci.h" + #include "trace.h" + ++#include ++ + /* + * List of device ids/vendor ids for which to disable + * option rom loading. This avoids the guest hangs during rom +diff -uNr qemu-5.1.0/hw/virtio/vhost-user.c qemu-5.1.0.mod/hw/virtio/vhost-user.c +--- qemu-5.1.0/hw/virtio/vhost-user.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/hw/virtio/vhost-user.c 2020-09-05 17:06:07.331115270 +0300 +@@ -32,6 +32,7 @@ + #include "standard-headers/linux/vhost_types.h" + + #ifdef CONFIG_LINUX ++#include + #include + #endif + +diff -uNr qemu-5.1.0/linux-user/elfload.c qemu-5.1.0.mod/linux-user/elfload.c +--- qemu-5.1.0/linux-user/elfload.c 2020-09-05 17:01:16.823064611 +0300 ++++ qemu-5.1.0.mod/linux-user/elfload.c 2020-09-05 17:06:07.331115270 +0300 +@@ -2,6 +2,8 @@ + #include "qemu/osdep.h" + #include + ++#include ++ + #include + #include + +diff -uNr qemu-5.1.0/linux-user/flatload.c qemu-5.1.0.mod/linux-user/flatload.c +--- qemu-5.1.0/linux-user/flatload.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/linux-user/flatload.c 2020-09-05 17:06:07.331115270 +0300 +@@ -35,6 +35,8 @@ + + #include "qemu/osdep.h" + ++#include ++ + #include "qemu.h" + #include "flat.h" + #include "target_flat.h" +diff -uNr qemu-5.1.0/linux-user/i386/cpu_loop.c qemu-5.1.0.mod/linux-user/i386/cpu_loop.c +--- qemu-5.1.0/linux-user/i386/cpu_loop.c 2020-08-11 22:17:14.000000000 +0300 ++++ qemu-5.1.0.mod/linux-user/i386/cpu_loop.c 2020-09-05 17:06:07.335115279 +0300 +@@ -22,6 +22,8 @@ + #include "qemu.h" + #include "cpu_loop-common.h" + ++#include ++ + /***********************************************************/ + /* CPUX86 core interface */ + +diff -uNr qemu-5.1.0/linux-user/mmap.c qemu-5.1.0.mod/linux-user/mmap.c +--- qemu-5.1.0/linux-user/mmap.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/linux-user/mmap.c 2020-09-05 17:06:40.807186551 +0300 +@@ -21,6 +21,8 @@ + #include "exec/log.h" + #include "qemu.h" + ++#include ++ + static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER; + static __thread int mmap_lock_count; + +diff -uNr qemu-5.1.0/linux-user/syscall.c qemu-5.1.0.mod/linux-user/syscall.c +--- qemu-5.1.0/linux-user/syscall.c 2020-09-05 17:02:57.910949156 +0300 ++++ qemu-5.1.0.mod/linux-user/syscall.c 2020-09-05 17:06:07.335115279 +0300 +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + #include + #include + #include +diff -uNr qemu-5.1.0/migration/postcopy-ram.c qemu-5.1.0.mod/migration/postcopy-ram.c +--- qemu-5.1.0/migration/postcopy-ram.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/migration/postcopy-ram.c 2020-09-05 17:06:07.335115279 +0300 +@@ -31,6 +31,8 @@ + #include "trace.h" + #include "hw/boards.h" + ++#include ++ + /* Arbitrary limit on size of each discard command, + * keeps them around ~200 bytes + */ +diff -uNr qemu-5.1.0/util/memfd.c qemu-5.1.0.mod/util/memfd.c +--- qemu-5.1.0/util/memfd.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/util/memfd.c 2020-09-05 17:06:07.335115279 +0300 +@@ -32,6 +32,7 @@ + #include "qemu/host-utils.h" + + #if defined CONFIG_LINUX && !defined CONFIG_MEMFD ++#include + #include + #include + +diff -uNr qemu-5.1.0/util/mmap-alloc.c qemu-5.1.0.mod/util/mmap-alloc.c +--- qemu-5.1.0/util/mmap-alloc.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/util/mmap-alloc.c 2020-09-05 17:06:07.335115279 +0300 +@@ -10,7 +10,7 @@ + * later. See the COPYING file in the top-level directory. + */ + +-#ifdef CONFIG_LINUX ++#ifdef __linux__ + #include + #else /* !CONFIG_LINUX */ + #define MAP_SYNC 0x0 +diff -uNr qemu-5.1.0/util/oslib-posix.c qemu-5.1.0.mod/util/oslib-posix.c +--- qemu-5.1.0/util/oslib-posix.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/util/oslib-posix.c 2020-09-05 17:06:07.335115279 +0300 +@@ -41,6 +41,7 @@ + #include "qemu/cutils.h" + + #ifdef CONFIG_LINUX ++#include + #include + #endif + +diff -uNr qemu-5.1.0/util/vfio-helpers.c qemu-5.1.0.mod/util/vfio-helpers.c +--- qemu-5.1.0/util/vfio-helpers.c 2020-08-11 22:17:15.000000000 +0300 ++++ qemu-5.1.0.mod/util/vfio-helpers.c 2020-09-05 17:06:07.335115279 +0300 +@@ -13,6 +13,7 @@ + #include "qemu/osdep.h" + #include + #include ++#include + #include "qapi/error.h" + #include "exec/ramlist.h" + #include "exec/cpu-common.h" +diff -uNr qemu-5.2.0/tests/vhost-user-bridge.c qemu-5.2.0.mod/tests/vhost-user-bridge.c +--- qemu-5.2.0/tests/vhost-user-bridge.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/tests/vhost-user-bridge.c 2020-12-09 17:31:52.039910511 +0200 +@@ -29,6 +29,8 @@ + + #define _FILE_OFFSET_BITS 64 + ++#include ++ + #include "qemu/osdep.h" + #include "qemu/atomic.h" + #include "qemu/ctype.h" +diff -uNr qemu-5.2.0/softmmu/physmem.c qemu-5.2.0.mod/softmmu/physmem.c +--- qemu-5.2.0/softmmu/physmem.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/softmmu/physmem.c 2020-12-09 17:05:25.872459520 +0200 +@@ -17,6 +17,8 @@ + * License along with this library; if not, see . + */ + ++#include ++ + #include "qemu/osdep.h" + #include "qemu-common.h" + #include "qapi/error.h" diff --git a/tur-multilib/hangover-libqemu/0010-disable-glob.h-include.patch b/tur-multilib/hangover-libqemu/0010-disable-glob.h-include.patch new file mode 100644 index 0000000000..fa66991666 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0010-disable-glob.h-include.patch @@ -0,0 +1,11 @@ +diff -uNr qemu-4.2.0/util/drm.c qemu-4.2.0.mod/util/drm.c +--- qemu-4.2.0/util/drm.c 2019-12-12 20:20:48.000000000 +0200 ++++ qemu-4.2.0.mod/util/drm.c 2019-12-15 02:18:23.537494928 +0200 +@@ -17,7 +17,6 @@ + #include "qemu/osdep.h" + #include "qemu/drm.h" + +-#include + #include + + int qemu_drm_rendernode_open(const char *rendernode) diff --git a/tur-multilib/hangover-libqemu/0011-misc-build-fixes.patch b/tur-multilib/hangover-libqemu/0011-misc-build-fixes.patch new file mode 100644 index 0000000000..86605876c2 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0011-misc-build-fixes.patch @@ -0,0 +1,54 @@ +diff -uNr qemu-5.2.0/include/qapi/util.h qemu-5.2.0.mod/include/qapi/util.h +--- qemu-5.2.0/include/qapi/util.h 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/include/qapi/util.h 2020-12-09 17:15:41.400859913 +0200 +@@ -11,6 +11,10 @@ + #ifndef QAPI_UTIL_H + #define QAPI_UTIL_H + ++#include ++ ++typedef struct Error Error; ++ + typedef struct QEnumLookup { + const char *const *array; + int size; +diff -uNr qemu-5.2.0/meson.build qemu-5.2.0.mod/meson.build +--- qemu-5.2.0/meson.build 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/meson.build 2020-12-09 17:18:04.165911853 +0200 +@@ -94,11 +94,11 @@ + + # Specify linker-script with add_project_link_arguments so that it is not placed + # within a linker --start-group/--end-group pair +-if 'CONFIG_FUZZ' in config_host +- add_project_link_arguments(['-Wl,-T,', +- (meson.current_source_dir() / 'tests/qtest/fuzz/fork_fuzz.ld')], +- native: false, language: ['c', 'cpp', 'objc']) +-endif ++#if 'CONFIG_FUZZ' in config_host ++# add_project_link_arguments(['-Wl,-T,', ++# (meson.current_source_dir() / 'tests/qtest/fuzz/fork_fuzz.ld')], ++# native: false, language: ['c', 'cpp', 'objc']) ++#endif + + add_project_arguments(config_host['QEMU_CFLAGS'].split(), + native: false, language: ['c', 'objc']) +@@ -1575,8 +1575,8 @@ + specific_ss.add_all(when: 'CONFIG_LINUX_USER', if_true: linux_user_ss) + + # needed for fuzzing binaries +-subdir('tests/qtest/libqos') +-subdir('tests/qtest/fuzz') ++#subdir('tests/qtest/libqos') ++#subdir('tests/qtest/fuzz') + + ######################## + # Library dependencies # +diff -uNr qemu-5.2.0/tests/meson.build qemu-5.2.0.mod/tests/meson.build +--- qemu-5.2.0/tests/meson.build 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/tests/meson.build 2020-12-09 17:24:07.616614694 +0200 +@@ -286,5 +286,4 @@ + endif + + subdir('qapi-schema') +-subdir('qtest') + subdir('migration') diff --git a/tur-multilib/hangover-libqemu/0012-add-missing-arch_prctl.patch b/tur-multilib/hangover-libqemu/0012-add-missing-arch_prctl.patch new file mode 100644 index 0000000000..4968a10a88 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0012-add-missing-arch_prctl.patch @@ -0,0 +1,16 @@ +--- qemu-4.2.0/tcg/i386/tcg-target.c.inc ++++ qemu-4.2.0.mod/tcg/i386/tcg-target.c.inc +@@ -1968,7 +1968,12 @@ + # if defined(__x86_64__) && defined(__linux__) + # include + # include +-int arch_prctl(int code, unsigned long addr); ++# include ++static int arch_prctl(int code, unsigned long addr) ++{ ++ return syscall(__NR_arch_prctl, code, addr); ++} ++ + static inline int setup_guest_base_seg(void) + { + if (arch_prctl(ARCH_SET_GS, guest_base) == 0) { diff --git a/tur-multilib/hangover-libqemu/0013-mmap_min_addr-fallback.patch b/tur-multilib/hangover-libqemu/0013-mmap_min_addr-fallback.patch new file mode 100644 index 0000000000..be0e65f7d8 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0013-mmap_min_addr-fallback.patch @@ -0,0 +1,17 @@ +diff -uNr qemu-5.2.0/linux-user/main.c qemu-5.2.0.mod/linux-user/main.c +--- qemu-5.2.0/linux-user/main.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/linux-user/main.c 2020-12-24 17:41:07.982481916 +0200 +@@ -770,7 +770,13 @@ + * If we're in a chroot with no /proc, fall back to 1 page. + */ + if (mmap_min_addr == 0) { ++#ifdef __ANDROID__ ++ // Go with 8 pages (32768 bytes) as default value for Android (Termux). ++ // Issue https://github.com/termux/termux-packages/issues/6172. ++ mmap_min_addr = qemu_host_page_size * 8; ++#else + mmap_min_addr = qemu_host_page_size; ++#endif + qemu_log_mask(CPU_LOG_PAGE, + "host mmap_min_addr=0x%lx (fallback)\n", + mmap_min_addr); diff --git a/tur-multilib/hangover-libqemu/0014-force-ucs2-little-endian.patch b/tur-multilib/hangover-libqemu/0014-force-ucs2-little-endian.patch new file mode 100644 index 0000000000..8e96be423c --- /dev/null +++ b/tur-multilib/hangover-libqemu/0014-force-ucs2-little-endian.patch @@ -0,0 +1,20 @@ +diff -uNr qemu-5.2.0/ui/curses.c qemu-5.2.0.mod/ui/curses.c +--- qemu-5.2.0/ui/curses.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/ui/curses.c 2021-01-30 01:29:40.987065827 +0200 +@@ -566,14 +566,14 @@ + 0x25bc + }; + +- ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2"); ++ ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2LE"); + if (ucs2_to_nativecharset == (iconv_t) -1) { + fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n", + strerror(errno)); + exit(1); + } + +- nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset); ++ nativecharset_to_ucs2 = iconv_open("UCS-2LE", local_codeset); + if (nativecharset_to_ucs2 == (iconv_t) -1) { + iconv_close(ucs2_to_nativecharset); + fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n", diff --git a/tur-multilib/hangover-libqemu/0015-9pfs-dont-chmod-mapfile.patch b/tur-multilib/hangover-libqemu/0015-9pfs-dont-chmod-mapfile.patch new file mode 100644 index 0000000000..a350707438 --- /dev/null +++ b/tur-multilib/hangover-libqemu/0015-9pfs-dont-chmod-mapfile.patch @@ -0,0 +1,12 @@ +diff -uNr qemu-5.2.0/hw/9pfs/9p-local.c qemu-5.2.0.mod/hw/9pfs/9p-local.c +--- qemu-5.2.0/hw/9pfs/9p-local.c 2020-12-08 18:59:44.000000000 +0200 ++++ qemu-5.2.0.mod/hw/9pfs/9p-local.c 2021-08-07 17:01:43.567841976 +0300 +@@ -299,8 +299,6 @@ + + map_fd = fileno(fp); + assert(map_fd != -1); +- ret = fchmod(map_fd, 0600); +- assert(ret == 0); + + if (credp->fc_uid != -1) { + uid = credp->fc_uid; diff --git a/tur-multilib/hangover-libqemu/build.sh b/tur-multilib/hangover-libqemu/build.sh new file mode 100644 index 0000000000..94775e74a8 --- /dev/null +++ b/tur-multilib/hangover-libqemu/build.sh @@ -0,0 +1,128 @@ +TERMUX_PKG_HOMEPAGE=https://github.com/AndreRH/qemu +TERMUX_PKG_DESCRIPTION="x86 and x86-64 Linux emulator library for Hangover" +TERMUX_PKG_LICENSE="custom" +TERMUX_PKG_LICENSE_FILE="LICENSE COPYING COPYING.LIB" +TERMUX_PKG_MAINTAINER="@termux-user-repository" +_COMMIT="547c80c2ab9e3165fcf29b51064f668198aae520" +_COMMIT_DATE=2023.07.30 +TERMUX_PKG_VERSION=8.17 +TERMUX_PKG_SRCURL=git+https://github.com/AndreRH/qemu +TERMUX_PKG_GIT_BRANCH="wow" +TERMUX_PKG_DEPENDS="glib, libandroid-shmem" + +# Required by configuration script, but I can't find any binary that uses it. +TERMUX_PKG_BUILD_DEPENDS="libtasn1" + +TERMUX_PKG_BLACKLISTED_ARCHES="arm, i686, x86_64" +TERMUX_PKG_BUILD_IN_SRC=true + +termux_step_get_source() { + local TMP_CHECKOUT=$TERMUX_PKG_CACHEDIR/tmp-checkout + local TMP_CHECKOUT_VERSION=$TERMUX_PKG_CACHEDIR/tmp-checkout-version + + if [ ! -f $TMP_CHECKOUT_VERSION ] || [ "$(cat $TMP_CHECKOUT_VERSION)" != "$TERMUX_PKG_VERSION" ]; then + rm -rf $TMP_CHECKOUT + git clone \ + --branch $TERMUX_PKG_GIT_BRANCH \ + ${TERMUX_PKG_SRCURL:4} \ + $TMP_CHECKOUT + + pushd $TMP_CHECKOUT + git submodule update --init --recursive + popd + + echo "$TERMUX_PKG_VERSION" > $TMP_CHECKOUT_VERSION + fi + + rm -rf $TERMUX_PKG_SRCDIR + cp -Rf $TMP_CHECKOUT $TERMUX_PKG_SRCDIR + cp -Rf $TMP_CHECKOUT/.git $TERMUX_PKG_SRCDIR/ + + cd $TERMUX_PKG_SRCDIR + + git checkout $_COMMIT + git submodule update --init --recursive + local commit_date="$(git log -1 --format=%cs | sed 's/-/./g')" + if [ "$commit_date" != "$_COMMIT_DATE" ]; then + echo -n "ERROR: The specified commit date \"$_COMMIT_DATE\"" + echo " is different from what is expected to be: \"$commit_date\"" + return 1 + fi +} + +termux_step_pre_configure() { + # Workaround for https://github.com/termux/termux-packages/issues/12261. + if [ $TERMUX_ARCH = "aarch64" ]; then + rm -f $TERMUX_PKG_BUILDDIR/_lib + mkdir -p $TERMUX_PKG_BUILDDIR/_lib + + cd $TERMUX_PKG_BUILDDIR + mkdir -p _setjmp-aarch64 + pushd _setjmp-aarch64 + mkdir -p private + local s + for s in $TERMUX_PKG_BUILDER_DIR/setjmp-aarch64/{setjmp.S,private-*.h}; do + local f=$(basename ${s}) + cp ${s} ./${f/-//} + done + $CC $CFLAGS $CPPFLAGS -I. setjmp.S -c + $AR cru $TERMUX_PKG_BUILDDIR/_lib/libandroid-setjmp.a setjmp.o + popd + + LDFLAGS+=" -L$TERMUX_PKG_BUILDDIR/_lib -l:libandroid-setjmp.a" + fi +} + +termux_step_configure() { + termux_setup_ninja + + if [ "$TERMUX_ARCH" = "i686" ]; then + LDFLAGS+=" -latomic" + fi + + CFLAGS+=" $CPPFLAGS" + CXXFLAGS+=" $CPPFLAGS" + LDFLAGS+=" -landroid-shmem -llog" + + # Note: using --disable-stack-protector since stack protector + # flags already passed by build scripts but we do not want to + # override them with what QEMU configure provides. + ./configure \ + --prefix="$TERMUX_PREFIX" \ + --cross-prefix="${TERMUX_HOST_PLATFORM}-" \ + --host-cc="gcc" \ + --cc="$CC" \ + --cxx="$CXX" \ + --objcc="$CC" \ + --disable-stack-protector \ + --enable-coroutine-pool \ + --enable-trace-backends=nop \ + --disable-werror \ + --disable-guest-agent \ + --disable-sdl \ + --disable-sdl-image \ + --disable-gtk \ + --disable-vte \ + --disable-vnc-sasl \ + --disable-xen \ + --disable-xen-pci-passthrough \ + --disable-hax \ + --disable-hvf \ + --disable-whpx \ + --disable-snappy \ + --disable-lzfse \ + --disable-seccomp \ + --disable-parallels \ + --disable-vhost-user \ + --disable-vhost-user-blk-server \ + --target-list="arm-linux-user,i386-linux-user" +} + +termux_step_make() { + make -j $TERMUX_MAKE_PROCESSES || bash +} + +termux_step_make_install() { + cp ./build/libqemu-arm.so $TERMUX_PREFIX/lib/ + cp ./build/libqemu-i386.so $TERMUX_PREFIX/lib/ +} diff --git a/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm.h b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm.h new file mode 100644 index 0000000000..b97df5c9d8 --- /dev/null +++ b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#pragma once + +/* https://github.com/android/ndk/issues/1422 */ +#if 0 +#include +#endif + +#include /* For system call numbers. */ +#define MAX_ERRNO 4095 /* For recognizing system call error returns. */ + +#define __bionic_asm_custom_entry(f) +#define __bionic_asm_custom_end(f) +#define __bionic_asm_function_type @function +#define __bionic_asm_custom_note_gnu_section() + +#if defined(__aarch64__) +#include +#elif defined(__arm__) +#include +#elif defined(__i386__) +#include +#elif defined(__riscv) +#include +#elif defined(__x86_64__) +#include +#endif + +#define ENTRY_NO_DWARF(f) \ + .text; \ + .globl f; \ + .balign __bionic_asm_align; \ + .type f, __bionic_asm_function_type; \ + f: \ + __bionic_asm_custom_entry(f); \ + +#define ENTRY(f) \ + ENTRY_NO_DWARF(f) \ + .cfi_startproc \ + +#define END_NO_DWARF(f) \ + .size f, .-f; \ + __bionic_asm_custom_end(f) \ + +#define END(f) \ + .cfi_endproc; \ + END_NO_DWARF(f) \ + +/* Like ENTRY, but with hidden visibility. */ +#define ENTRY_PRIVATE(f) \ + ENTRY(f); \ + .hidden f \ + +/* Like ENTRY_NO_DWARF, but with hidden visibility. */ +#define ENTRY_PRIVATE_NO_DWARF(f) \ + ENTRY_NO_DWARF(f); \ + .hidden f \ + +#define __BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(f) \ + .weak f; \ + +#define ALIAS_SYMBOL(alias, original) \ + .globl alias; \ + .equ alias, original + +#define NOTE_GNU_PROPERTY() \ + __bionic_asm_custom_note_gnu_section() diff --git a/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm_arm64.h b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm_arm64.h new file mode 100644 index 0000000000..ffc7181447 --- /dev/null +++ b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_asm_arm64.h @@ -0,0 +1,79 @@ +/* $OpenBSD: asm.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */ +/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt Exp $ */ + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#pragma once + +#define __bionic_asm_align 16 + +#undef __bionic_asm_function_type +#define __bionic_asm_function_type %function + +#if defined(__ARM_FEATURE_BTI_DEFAULT) +#define __bionic_asm_aarch64_feature_bti (1 << 0) +#undef __bionic_asm_custom_entry +#define __bionic_asm_custom_entry(f) bti c +#else +#define __bionic_asm_aarch64_feature_bti 0 +#endif + +#if defined(__ARM_FEATURE_PAC_DEFAULT) +#define __bionic_asm_aarch64_feature_pac (1 << 1) +#else +#define __bionic_asm_aarch64_feature_pac 0 +#endif + +#undef __bionic_asm_custom_note_gnu_section +#define __bionic_asm_custom_note_gnu_section() \ + .pushsection .note.gnu.property, "a"; \ + .balign 8; \ + .long 4; \ + .long 0x10; \ + .long 0x5; /* NT_GNU_PROPERTY_TYPE_0 */ \ + .asciz "GNU"; \ + .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ \ + .long 4; \ + .long (__bionic_asm_aarch64_feature_pac | \ + __bionic_asm_aarch64_feature_bti); \ + .long 0; \ + .popsection; + +#define NT_MEMTAG_LEVEL_MASK 3 +#define NT_MEMTAG_LEVEL_NONE 0 +#define NT_MEMTAG_LEVEL_ASYNC 1 +#define NT_MEMTAG_LEVEL_SYNC 2 +#define NT_MEMTAG_HEAP 4 +#define NT_MEMTAG_STACK 8 diff --git a/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_constants.h b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_constants.h new file mode 100644 index 0000000000..09294b64a7 --- /dev/null +++ b/tur-multilib/hangover-libqemu/setjmp-aarch64/private-bionic_constants.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BIONIC_CONSTANTS_H_ +#define _BIONIC_CONSTANTS_H_ + +#define NS_PER_S 1000000000 + +// Size of the shadow call stack. This must be a power of 2. +#define SCS_SIZE (8 * 1024) + +// The shadow call stack is allocated at an aligned address within a guard region of this size. The +// guard region must be large enough that we can allocate an SCS_SIZE-aligned SCS while ensuring +// that there is at least one guard page after the SCS so that a stack overflow results in a SIGSEGV +// instead of corrupting the allocation that comes after it. +#define SCS_GUARD_REGION_SIZE (16 * 1024 * 1024) + +#endif // _BIONIC_CONSTANTS_H_ diff --git a/tur-multilib/hangover-libqemu/setjmp-aarch64/setjmp.S b/tur-multilib/hangover-libqemu/setjmp-aarch64/setjmp.S new file mode 100644 index 0000000000..f97bb254e6 --- /dev/null +++ b/tur-multilib/hangover-libqemu/setjmp-aarch64/setjmp.S @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +// According to AARCH64 PCS document we need to save the following +// registers: +// +// Core x19 - x30, sp (see section 5.1.1) +// VFP d8 - d15 (see section 5.1.2) +// +// NOTE: All the registers saved here will have 64 bit vales. +// AAPCS mandates that the higher part of q registers do not need to +// be saved by the callee. +// +// The internal structure of a jmp_buf is totally private. +// Current layout (changes from release to release): +// +// word name description +// 0 sigflag/cookie setjmp cookie in top 31 bits, signal mask flag in low bit +// 1 sigmask signal mask (not used with _setjmp / _longjmp) +// 2 core_base base of core registers (x18-x30, sp) +// (We only store the low bits of x18 to avoid leaking the +// shadow call stack address into memory.) +// 16 float_base base of float registers (d8-d15) +// 24 checksum checksum of core registers +// 25 reserved reserved entries (room to grow) +// 32 + +#define _JB_SIGFLAG 0 +#define _JB_SIGMASK (_JB_SIGFLAG + 1) +#define _JB_X30_SP (_JB_SIGMASK + 1) +#define _JB_X28_X29 (_JB_X30_SP + 2) +#define _JB_X26_X27 (_JB_X28_X29 + 2) +#define _JB_X24_X25 (_JB_X26_X27 + 2) +#define _JB_X22_X23 (_JB_X24_X25 + 2) +#define _JB_X20_X21 (_JB_X22_X23 + 2) +#define _JB_SCS_X19 (_JB_X20_X21 + 2) +#define _JB_D14_D15 (_JB_SCS_X19 + 2) +#define _JB_D12_D13 (_JB_D14_D15 + 2) +#define _JB_D10_D11 (_JB_D12_D13 + 2) +#define _JB_D8_D9 (_JB_D10_D11 + 2) +#define _JB_CHECKSUM (_JB_D8_D9 + 2) + +#define SCS_MASK (SCS_SIZE - 1) +#define MANGLE_REGISTERS 1 +#define USE_CHECKSUM 1 + +.macro m_mangle_registers reg, sp_reg +#if MANGLE_REGISTERS + eor x3, x3, \reg + eor x19, x19, \reg + eor x20, x20, \reg + eor x21, x21, \reg + eor x22, x22, \reg + eor x23, x23, \reg + eor x24, x24, \reg + eor x25, x25, \reg + eor x26, x26, \reg + eor x27, x27, \reg + eor x28, x28, \reg + eor x29, x29, \reg + eor x30, x30, \reg + eor \sp_reg, \sp_reg, \reg +#endif +.endm + +.macro m_calculate_checksum dst, src, scratch + mov \dst, #0 + .irp i,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 + ldr \scratch, [\src, #(\i * 8)] + eor \dst, \dst, \scratch + .endr +.endm + +.macro m_unmangle_registers reg, sp_reg + m_mangle_registers \reg, sp_reg=\sp_reg +.endm + +ENTRY_PRIVATE(setjmp) + mov w1, #1 + b sigsetjmp +END(setjmp) + +ENTRY_PRIVATE(_setjmp) + mov w1, #0 + b sigsetjmp +END(_setjmp) + +// int sigsetjmp(sigjmp_buf env, int save_signal_mask); +ENTRY_PRIVATE(sigsetjmp) + stp x0, x30, [sp, #-16]! + .cfi_def_cfa_offset 16 + .cfi_rel_offset x0, 0 + .cfi_rel_offset x30, 8 + + // Get the cookie and store it along with the signal flag. + mov x0, x1 + //bl __bionic_setjmp_cookie_get + mov x1, x0 + ldr x0, [sp, #0] + str x1, [x0, #(_JB_SIGFLAG * 8)] + + // Do we need to save the signal mask? + tbz w1, #0, 1f + + // Save the cookie for later. + stp x1, xzr, [sp, #-16]! + .cfi_adjust_cfa_offset 16 + + // Save current signal mask. + // The 'how' argument is ignored if new_mask is NULL. + mov x1, #0 // NULL. + add x2, x0, #(_JB_SIGMASK * 8) // old_mask. + bl sigprocmask + + ldp x1, xzr, [sp], #16 + .cfi_adjust_cfa_offset -16 + +1: + // Restore original x0 and lr. + ldp x0, x30, [sp], #16 + .cfi_adjust_cfa_offset -16 + .cfi_restore x0 + .cfi_restore x30 + + // Mask off the signal flag bit. + bic x1, x1, #1 + + // Mask off the high bits of the shadow call stack pointer. + and x3, x18, #SCS_MASK + + // Save core registers. + mov x10, sp + m_mangle_registers x1, sp_reg=x10 + stp x30, x10, [x0, #(_JB_X30_SP * 8)] + stp x28, x29, [x0, #(_JB_X28_X29 * 8)] + stp x26, x27, [x0, #(_JB_X26_X27 * 8)] + stp x24, x25, [x0, #(_JB_X24_X25 * 8)] + stp x22, x23, [x0, #(_JB_X22_X23 * 8)] + stp x20, x21, [x0, #(_JB_X20_X21 * 8)] + stp x3, x19, [x0, #(_JB_SCS_X19 * 8)] + m_unmangle_registers x1, sp_reg=x10 + + // Save floating point registers. + stp d14, d15, [x0, #(_JB_D14_D15 * 8)] + stp d12, d13, [x0, #(_JB_D12_D13 * 8)] + stp d10, d11, [x0, #(_JB_D10_D11 * 8)] + stp d8, d9, [x0, #(_JB_D8_D9 * 8)] + +#if USE_CHECKSUM + // Calculate the checksum. + m_calculate_checksum x12, x0, x2 + str x12, [x0, #(_JB_CHECKSUM * 8)] +#endif + + mov w0, #0 + ret +END(sigsetjmp) + +// void siglongjmp(sigjmp_buf env, int value); +ENTRY_PRIVATE(siglongjmp) +#if USE_CHECKSUM + // Check the checksum before doing anything. + m_calculate_checksum x12, x0, x2 + ldr x2, [x0, #(_JB_CHECKSUM * 8)] + + cmp x2, x12 + //bne __bionic_setjmp_checksum_mismatch +#endif + +#if __has_feature(hwaddress_sanitizer) + stp x0, x30, [sp, #-16]! + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset x0, 0 + .cfi_rel_offset x30, 8 + mov x19, x1 // Save 'value'. + + // load and unmangle destination SP + ldr x2, [x0, #(_JB_SIGFLAG * 8)] + bic x2, x2, #1 + ldr x0, [x0, #(_JB_X30_SP * 8 + 8)] + eor x0, x0, x2 + bl __hwasan_handle_longjmp + + mov x1, x19 // Restore 'value'. + // Restore original x0 and lr. + ldp x0, x30, [sp], #16 + .cfi_adjust_cfa_offset -16 + .cfi_restore x0 + .cfi_restore x30 +#endif + + // Do we need to restore the signal mask? + ldr x2, [x0, #(_JB_SIGFLAG * 8)] + tbz w2, #0, 1f + + stp x0, x30, [sp, #-16]! + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset x0, 0 + .cfi_rel_offset x30, 8 + + // Restore signal mask. + mov x19, x1 // Save 'value'. + + mov x2, x0 + mov x0, #2 // SIG_SETMASK + add x1, x2, #(_JB_SIGMASK * 8) // new_mask. + mov x2, #0 // NULL. + bl sigprocmask + mov x1, x19 // Restore 'value'. + + // Restore original x0 and lr. + ldp x0, x30, [sp], #16 + .cfi_adjust_cfa_offset -16 + .cfi_restore x0 + .cfi_restore x30 + + ldr x2, [x0, #(_JB_SIGFLAG * 8)] +1: + // Restore core registers. + bic x2, x2, #1 + ldp x30, x10, [x0, #(_JB_X30_SP * 8)] + ldp x28, x29, [x0, #(_JB_X28_X29 * 8)] + ldp x26, x27, [x0, #(_JB_X26_X27 * 8)] + ldp x24, x25, [x0, #(_JB_X24_X25 * 8)] + ldp x22, x23, [x0, #(_JB_X22_X23 * 8)] + ldp x20, x21, [x0, #(_JB_X20_X21 * 8)] + ldp x3, x19, [x0, #(_JB_SCS_X19 * 8)] + m_unmangle_registers x2, sp_reg=x10 + mov sp, x10 + + // Restore the low bits of the shadow call stack pointer. + and x18, x18, #~SCS_MASK + orr x18, x3, x18 + + stp x0, x1, [sp, #-16]! + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset x0, 0 + .cfi_rel_offset x1, 8 + stp x30, xzr, [sp, #-16]! + .cfi_adjust_cfa_offset 16 + .cfi_rel_offset x30, 0 + ldr x0, [x0, #(_JB_SIGFLAG * 8)] + //bl __bionic_setjmp_cookie_check + ldp x30, xzr, [sp], #16 + .cfi_adjust_cfa_offset -16 + .cfi_restore x30 + ldp x0, x1, [sp], #16 + .cfi_adjust_cfa_offset -16 + .cfi_restore x0 + .cfi_restore x1 + + // Restore floating point registers. + ldp d14, d15, [x0, #(_JB_D14_D15 * 8)] + ldp d12, d13, [x0, #(_JB_D12_D13 * 8)] + ldp d10, d11, [x0, #(_JB_D10_D11 * 8)] + ldp d8, d9, [x0, #(_JB_D8_D9 * 8)] + + // Set return value. + cmp w1, wzr + csinc w0, w1, wzr, ne + ret +END(siglongjmp) + +ALIAS_SYMBOL(longjmp, siglongjmp) +.hidden longjmp +ALIAS_SYMBOL(_longjmp, siglongjmp) +.hidden _longjmp