From nobody Fri Dec 19 06:56:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604878590; cv=none; d=zohomail.com; s=zohoarc; b=Gec6FUnJWq7nQ3kDlK3cisMPnSGOG9E7ZoWg+ao9xjV4zjoJ9Ae5MosHowoCrwsBjJaKaswR/Pz8mT33jzZktC+NzPl/fTdQGu5dNgISUtnPMbOWWVgY/NZJPzdnSUIw9GCNJKMraqKgcptCN8KvfKmVqm+jXqjKeaQjwvueUrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604878590; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ttY5ncyy7BrT7Kmjsqme660xtaDnKnSGuGFstQY6vK4=; b=QpeMWMlV2j3RWgsX8V4OSj6wqBLuWRwgoX+4+YZB4LsSTm/2pRcrl3/Pes5wPAXklXXw4RsmAjtu+nid0qmRYs7UIUTzmWkHlwlO10Q3Guxf8hGsY502rcanf2Nx/PfQFSuTZStf5Iuza7Tfc0caUJ8OcJNN9sfI4KCKXM4Hnsk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604878590841875.626353541957; Sun, 8 Nov 2020 15:36:30 -0800 (PST) Received: from localhost ([::1]:50638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbuEX-0007qW-JZ for importer@patchew.org; Sun, 08 Nov 2020 18:36:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu31-0000pD-Nr; Sun, 08 Nov 2020 18:24:35 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33728) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu2z-0000Fm-7c; Sun, 08 Nov 2020 18:24:35 -0500 Received: by mail-pg1-f193.google.com with SMTP id r186so5271578pgr.0; Sun, 08 Nov 2020 15:24:32 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ttY5ncyy7BrT7Kmjsqme660xtaDnKnSGuGFstQY6vK4=; b=dXHb03XP8SmduZOAci22lvEmxxSTc055e/X4FpwLH0fCjbwtjO6ZZFhgmKQXiKxSQW oXISDD9NvZ1kFfcfgjtwsz29g0Ksav9+pQIQovjyeXZAdeBG1fjZ/7G8t1ENcsArXfgq Mpq3X7+hfmhVNN7HhqG15stMACY832ZXzfX+RUA9CPhjdq4Sf947uKicESXxtb+AfSwn o74WQdTEL08xYTYr9teXPs3BM5yuDx2E+rQRdSccIA30OiQP97Vk/8wDqau/YICchgsl J4hfVyXHH6bN19mGHEFTQywTYgKJc1V9SgTIa6DXQU3kEQPNn83smiAivGB48exRuuMw QVGQ== X-Gm-Message-State: AOAM530gKZ54UWTlP+Pw8HdA0bIIijMldypVBdxbGkuwQ74rctdOAA47 Ts76TXHnUnVOxMD0kbK+SteVwPYhzEM= X-Google-Smtp-Source: ABdhPJxNF/Lczuhsboa16wsPG/IBRvDNiF0AAWPgg5oy5CXQJ3GNeWX2qdAS4Vte8QeBDZyPDRWgZw== X-Received: by 2002:a17:90a:ab0f:: with SMTP id m15mr378851pjq.188.1604877871216; Sun, 08 Nov 2020 15:24:31 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 3/7] qemu: add support for iOS host Date: Sun, 8 Nov 2020 15:24:20 -0800 Message-Id: <20201108232425.1705-4-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=209.85.215.193; envelope-from=osy86github@gmail.com; helo=mail-pg1-f193.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:31 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , "open list:Block layer core" , Jason Wang , Michael Roth , Max Reitz , Joelle van Dyne , Paolo Bonzini , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This introduces support for building for iOS hosts. When the correct Xcode toolchain is used, iOS host will be detected automatically. * block: disable features not supported by iOS sandbox * slirp: disable SMB features for iOS * osdep: disable system() calls for iOS Signed-off-by: Joelle van Dyne --- docs/devel/index.rst | 1 + docs/devel/ios.rst | 28 +++++++++++++++++++++++++++ configure | 43 ++++++++++++++++++++++++++++++++++++++++- meson.build | 2 +- include/qemu/osdep.h | 11 +++++++++++ block.c | 2 +- block/file-posix.c | 31 +++++++++++++++++------------ net/slirp.c | 16 +++++++-------- qga/commands-posix.c | 6 ++++++ MAINTAINERS | 7 +++++++ tests/qtest/meson.build | 7 +++---- 11 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 docs/devel/ios.rst diff --git a/docs/devel/index.rst b/docs/devel/index.rst index 77baae5c77..a46740929f 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -34,3 +34,4 @@ Contents: clocks qom block-coroutine-wrapper + ios diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst new file mode 100644 index 0000000000..b4ab11bec1 --- /dev/null +++ b/docs/devel/ios.rst @@ -0,0 +1,28 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +iOS Support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +To run qemu on the iOS platform, some modifications were required. Most of= the +modifications are conditioned on the ``CONFIG_IOS`` and configuration vari= able. + +Build support +------------- + +For the code to compile, certain changes in the block driver and the slirp +driver had to be made. There is no ``system()`` call, so it has been repla= ced +with an assertion error. There should be no code path that call system() f= rom +iOS. + +``ucontext`` support is broken on iOS. The implementation from ``libuconte= xt`` +is used instead. + +JIT support +----------- + +On iOS, allocating RWX pages require special entitlements not usually gran= ted to +apps. However, it is possible to use `bulletproof JIT`_ with a development +certificate. This means that we need to allocate one chunk of memory with = RX +permissions and then mirror map the same memory with RW permissions. We ge= nerate +code to the mirror mapping and execute the original mapping. + +.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-K= rstic.pdf diff --git a/configure b/configure index fda7a875f7..2a6db88a46 100755 --- a/configure +++ b/configure @@ -557,6 +557,19 @@ EOF compile_object } =20 +check_ios() { + cat > $TMPC < $TMPC < @@ -599,7 +612,11 @@ elif check_define __DragonFly__ ; then elif check_define __NetBSD__; then targetos=3D'NetBSD' elif check_define __APPLE__; then - targetos=3D'Darwin' + if check_ios ; then + targetos=3D'iOS' + else + targetos=3D'Darwin' + fi else # This is a fatal error, but don't report it yet, because we # might be going to just print the --help text, or it might @@ -777,6 +794,22 @@ Darwin) # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS=3D"-DOS_OBJECT_USE_OBJC=3D0 $QEMU_CFLAGS" ;; +iOS) + bsd=3D"yes" + darwin=3D"yes" + ios=3D"yes" + if [ "$cpu" =3D "x86_64" ] ; then + QEMU_CFLAGS=3D"-arch x86_64 $QEMU_CFLAGS" + QEMU_LDFLAGS=3D"-arch x86_64 $QEMU_LDFLAGS" + fi + host_block_device_support=3D"no" + audio_drv_list=3D"" + audio_possible_drivers=3D"" + QEMU_LDFLAGS=3D"-framework CoreFoundation $QEMU_LDFLAGS" + # Disable attempts to use ObjectiveC features in os/object.h since they + # won't work when we're compiling with gcc as a C compiler. + QEMU_CFLAGS=3D"-DOS_OBJECT_USE_OBJC=3D0 $QEMU_CFLAGS" +;; SunOS) solaris=3D"yes" make=3D"${MAKE-gmake}" @@ -5962,6 +5995,10 @@ if test "$darwin" =3D "yes" ; then echo "CONFIG_DARWIN=3Dy" >> $config_host_mak fi =20 +if test "$ios" =3D "yes" ; then + echo "CONFIG_IOS=3Dy" >> $config_host_mak +fi + if test "$solaris" =3D "yes" ; then echo "CONFIG_SOLARIS=3Dy" >> $config_host_mak fi @@ -6926,6 +6963,7 @@ echo "cpp_link_args =3D [${LDFLAGS:+$(meson_quote $LD= FLAGS)}]" >> $cross echo "[binaries]" >> $cross echo "c =3D [$(meson_quote $cc)]" >> $cross test -n "$cxx" && echo "cpp =3D [$(meson_quote $cxx)]" >> $cross +test -n "$objcc" && echo "objc =3D [$(meson_quote $objcc)]" >> $cross echo "ar =3D [$(meson_quote $ar)]" >> $cross echo "nm =3D [$(meson_quote $nm)]" >> $cross echo "pkgconfig =3D [$(meson_quote $pkg_config_exe)]" >> $cross @@ -6944,6 +6982,9 @@ if test "$cross_compile" =3D "yes"; then if test "$linux" =3D "yes" ; then echo "system =3D 'linux'" >> $cross fi + if test "$darwin" =3D "yes" ; then + echo "system =3D 'darwin'" >> $cross + fi case "$ARCH" in i386|x86_64) echo "cpu_family =3D 'x86'" >> $cross diff --git a/meson.build b/meson.build index fd822346e7..8894171bd1 100644 --- a/meson.build +++ b/meson.build @@ -176,7 +176,7 @@ if targetos =3D=3D 'windows' include_directories: include_directo= ries('.')) elif targetos =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') - iokit =3D dependency('appleframeworks', modules: 'IOKit') + iokit =3D dependency('appleframeworks', modules: 'IOKit', required: 'CON= FIG_IOS' not in config_host) cocoa =3D dependency('appleframeworks', modules: 'Cocoa', required: get_= option('cocoa')) elif targetos =3D=3D 'sunos' socket =3D [cc.find_library('socket'), diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index f9ec8c84e9..eb8d06cbf5 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -686,4 +686,15 @@ char *qemu_get_host_name(Error **errp); */ size_t qemu_get_host_physmem(void); =20 +/** + * iOS does not support system() so we replace it with an assertion failur= e. + */ +#ifdef CONFIG_IOS +#define system ios_does_not_support_system +static inline int ios_does_not_support_system(const char *command) +{ + assert(0); +} +#endif /* CONFIG_IOS */ + #endif diff --git a/block.c b/block.c index 56bacc9e9f..e99cbf25ee 100644 --- a/block.c +++ b/block.c @@ -53,7 +53,7 @@ #ifdef CONFIG_BSD #include #include -#ifndef __DragonFly__ +#if !defined(__DragonFly__) && !defined(CONFIG_IOS) #include #endif #endif diff --git a/block/file-posix.c b/block/file-posix.c index a0fa9aad3a..d83219df55 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -181,7 +181,17 @@ typedef struct BDRVRawReopenState { bool check_cache_dropped; } BDRVRawReopenState; =20 -static int fd_open(BlockDriverState *bs); +static int fd_open(BlockDriverState *bs) +{ + BDRVRawState *s =3D bs->opaque; + + /* this is just to ensure s->fd is sane (its called by io ops) */ + if (s->fd >=3D 0) { + return 0; + } + return -EIO; +} + static int64_t raw_getlength(BlockDriverState *bs); =20 typedef struct RawPosixAIOData { @@ -252,6 +262,12 @@ static int raw_normalize_devicepath(const char **filen= ame, Error **errp) } #endif =20 +#if defined(CONFIG_IOS) +static int probe_logical_blocksize(int fd, unsigned int *sector_size_p) +{ + return -ENOTSUP; /* not supported on iOS */ +} +#else /* CONFIG_IOS */ /* * Get logical block size via ioctl. On success store it in @sector_size_p. */ @@ -284,6 +300,7 @@ static int probe_logical_blocksize(int fd, unsigned int= *sector_size_p) =20 return success ? 0 : -errno; } +#endif /* !CONFIG_IOS */ =20 /** * Get physical block size of @fd. @@ -2306,7 +2323,7 @@ again: } if (size =3D=3D 0) #endif -#if defined(__APPLE__) && defined(__MACH__) +#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__) { uint64_t sectors =3D 0; uint32_t sector_size =3D 0; @@ -3543,16 +3560,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long in= t req, void *buf) } #endif /* linux */ =20 -static int fd_open(BlockDriverState *bs) -{ - BDRVRawState *s =3D bs->opaque; - - /* this is just to ensure s->fd is sane (its called by io ops) */ - if (s->fd >=3D 0) - return 0; - return -EIO; -} - static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { diff --git a/net/slirp.c b/net/slirp.c index 77042e6df7..8413042c09 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -27,7 +27,7 @@ #include "net/slirp.h" =20 =20 -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) #include #include #endif @@ -90,7 +90,7 @@ typedef struct SlirpState { Slirp *slirp; Notifier poll_notifier; Notifier exit_notifier; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) gchar *smb_dir; #endif GSList *fwd; @@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =3D static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **err= p); static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **e= rrp); =20 -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) static int slirp_smb(SlirpState *s, const char *exported_dir, struct in_addr vserver_addr, Error **errp); static void slirp_smb_cleanup(SlirpState *s); @@ -368,7 +368,7 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, struct in6_addr ip6_prefix; struct in6_addr ip6_host; struct in6_addr ip6_dns; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) struct in_addr smbsrv =3D { .s_addr =3D 0 }; #endif NetClientState *nc; @@ -478,7 +478,7 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, return -1; } =20 -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) { error_setg(errp, "Failed to parse SMB address"); return -1; @@ -593,7 +593,7 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, } } } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) if (smb_export) { if (slirp_smb(s, smb_export, smbsrv, errp) < 0) { goto error; @@ -785,7 +785,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict) =20 } =20 -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(CONFIG_IOS) =20 /* automatic user mode samba server configuration */ static void slirp_smb_cleanup(SlirpState *s) @@ -900,7 +900,7 @@ static int slirp_smb(SlirpState* s, const char *exporte= d_dir, return 0; } =20 -#endif /* !defined(_WIN32) */ +#endif /* !defined(_WIN32) && !defined(CONFIG_IOS) */ =20 static int guestfwd_can_read(void *opaque) { diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 3711080d07..66a2f2ac9e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -34,6 +34,12 @@ =20 #ifndef CONFIG_HAS_ENVIRON #ifdef __APPLE__ +#include "TargetConditionals.h" +#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#define APPLE_USE_CRT_EXTERNS +#endif +#endif +#ifdef APPLE_USE_CRT_EXTERNS #include #define environ (*_NSGetEnviron()) #else diff --git a/MAINTAINERS b/MAINTAINERS index 63223e1183..1ec4c67a62 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -528,6 +528,13 @@ F: include/*/*win32* X: qga/*win32* F: qemu.nsi =20 +IOS +M: Joelle van Dyne +S: Maintained +K: ^Subject:.*(?i)iOS +F: docs/devel/ios.rst +F: include/tcg/tcg-apple-jit.h + Alpha Machines -------------- M: Richard Henderson diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c19f1c8503..8a151ee2da 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -46,12 +46,11 @@ qtests_i386 =3D \ (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : [= ]) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-swtpm-test= '] : []) + \ (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : [= ]) + \ + (not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test', 'hd-geo-te= st'] : []) + \ qtests_pci + = \ ['fdc-test', 'ide-test', - 'hd-geo-test', 'boot-order-test', - 'bios-tables-test', 'rtc-test', 'i440fx-test', 'fuzz-test', @@ -148,9 +147,9 @@ qtests_arm =3D \ 'boot-serial-test', 'hexloader-test'] =20 -# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-tes= t unconditional +# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-tes= t unconditional (except on iOS) qtests_aarch64 =3D \ - (cpu !=3D 'arm' ? ['bios-tables-test'] : []) + = \ + (cpu !=3D 'arm' and not config_host.has_key('CONFIG_IOS') ? ['bios-table= s-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-= test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-= swtpm-test'] : []) + \ ['arm-cpu-features', --=20 2.28.0