From: Joelle van Dyne <j@getutm.app>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Joelle van Dyne <j@getutm.app>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v5 4/7] coroutine: add libucontext as external library
Date: Sun, 8 Nov 2020 15:24:21 -0800 [thread overview]
Message-ID: <20201108232425.1705-5-j@getutm.app> (raw)
In-Reply-To: <20201108232425.1705-1-j@getutm.app>
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )
As a workaround we include a library implementation of ucontext and add it
as a build option.
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
configure | 23 ++++++++++++++++++++---
meson.build | 28 +++++++++++++++++++++++++++-
util/coroutine-ucontext.c | 9 +++++++++
.gitmodules | 3 +++
libucontext | 1 +
meson_options.txt | 2 ++
6 files changed, 62 insertions(+), 4 deletions(-)
create mode 160000 libucontext
diff --git a/configure b/configure
index 2a6db88a46..d1c6aa9750 100755
--- a/configure
+++ b/configure
@@ -1750,7 +1750,7 @@ Advanced options (experts only):
--oss-lib path to OSS library
--cpu=CPU Build for host CPU [$cpu]
--with-coroutine=BACKEND coroutine backend. Supported options:
- ucontext, sigaltstack, windows
+ ucontext, libucontext, sigaltstack, windows
--enable-gcov enable test coverage analysis with gcov
--disable-blobs disable installing provided firmware blobs
--with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
@@ -4883,6 +4883,8 @@ if test "$coroutine" = ""; then
coroutine=win32
elif test "$ucontext_works" = "yes"; then
coroutine=ucontext
+ elif test "$ios" = "yes"; then
+ coroutine=libucontext
else
coroutine=sigaltstack
fi
@@ -4906,12 +4908,27 @@ else
error_exit "only the 'windows' coroutine backend is valid for Windows"
fi
;;
+ libucontext)
+ ;;
*)
error_exit "unknown coroutine backend $coroutine"
;;
esac
fi
+case $coroutine in
+libucontext)
+ git_submodules="${git_submodules} libucontext"
+ mkdir -p libucontext
+ coroutine_impl=ucontext
+ libucontext="enabled"
+ ;;
+*)
+ coroutine_impl=$coroutine
+ libucontext="disabled"
+ ;;
+esac
+
if test "$coroutine_pool" = ""; then
coroutine_pool=yes
fi
@@ -6457,7 +6474,7 @@ if test "$rbd" = "yes" ; then
echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
fi
-echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
+echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
if test "$coroutine_pool" = "yes" ; then
echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
else
@@ -7035,7 +7052,7 @@ NINJA=$ninja $meson setup \
-Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dvirtiofsd=$virtiofsd \
- -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
+ -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Ducontext=$libucontext \
-Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
-Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
$cross_arg \
diff --git a/meson.build b/meson.build
index 8894171bd1..b087721f63 100644
--- a/meson.build
+++ b/meson.build
@@ -1259,9 +1259,34 @@ if not fdt.found() and fdt_required.length() > 0
error('fdt not available but required by targets ' + ', '.join(fdt_required))
endif
+ucontext = not_found
+if get_option('ucontext').enabled()
+ arch = host_machine.cpu()
+ if not fs.is_dir(meson.current_source_dir() / 'libucontext/arch' / arch)
+ error('libucontext is wanted but not implemented for host ' + arch)
+ endif
+ ucontext_cargs = ['-DG_LOG_DOMAIN="ucontext"', '-DCUSTOM_IMPL']
+ ucontext_files = [
+ 'libucontext/arch' / arch / 'getcontext.S',
+ 'libucontext/arch' / arch / 'setcontext.S',
+ 'libucontext/arch' / arch / 'makecontext.c',
+ 'libucontext/arch' / arch / 'startcontext.S',
+ 'libucontext/arch' / arch / 'swapcontext.S',
+ ]
+
+ ucontext_inc = include_directories('libucontext/include')
+ libucontext = static_library('ucontext',
+ sources: ucontext_files,
+ c_args: ucontext_cargs,
+ include_directories: ucontext_inc)
+ ucontext = declare_dependency(link_with: libucontext,
+ include_directories: ucontext_inc)
+endif
+
config_host_data.set('CONFIG_CAPSTONE', capstone.found())
config_host_data.set('CONFIG_FDT', fdt.found())
config_host_data.set('CONFIG_SLIRP', slirp.found())
+config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
#####################
# Generated sources #
@@ -1477,7 +1502,7 @@ util_ss.add_all(trace_ss)
util_ss = util_ss.apply(config_all, strict: false)
libqemuutil = static_library('qemuutil',
sources: util_ss.sources() + stub_ss.sources() + genh,
- dependencies: [util_ss.dependencies(), m, glib, socket, malloc])
+ dependencies: [util_ss.dependencies(), m, glib, socket, malloc, ucontext])
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res)
@@ -2135,6 +2160,7 @@ if targetos == 'windows'
summary_info += {'QGA MSI support': config_host.has_key('CONFIG_QGA_MSI')}
endif
summary_info += {'seccomp support': config_host.has_key('CONFIG_SECCOMP')}
+summary_info += {'libucontext support': ucontext.found()}
summary_info += {'coroutine backend': config_host['CONFIG_COROUTINE_BACKEND']}
summary_info += {'coroutine pool': config_host['CONFIG_COROUTINE_POOL'] == '1'}
summary_info += {'debug stack usage': config_host.has_key('CONFIG_DEBUG_STACK_USAGE')}
diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c
index 904b375192..1e1dd43512 100644
--- a/util/coroutine-ucontext.c
+++ b/util/coroutine-ucontext.c
@@ -23,7 +23,16 @@
#undef _FORTIFY_SOURCE
#endif
#include "qemu/osdep.h"
+#if defined(CONFIG_LIBUCONTEXT)
+#include <libucontext.h>
+#define ucontext_t libucontext_ucontext_t
+#define getcontext libucontext_getcontext
+#define setcontext libucontext_setcontext
+#define swapcontext libucontext_swapcontext
+#define makecontext libucontext_makecontext
+#else
#include <ucontext.h>
+#endif
#include "qemu/coroutine_int.h"
#ifdef CONFIG_VALGRIND_H
diff --git a/.gitmodules b/.gitmodules
index 2bdeeacef8..065b52867f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -64,3 +64,6 @@
[submodule "roms/vbootrom"]
path = roms/vbootrom
url = https://git.qemu.org/git/vbootrom.git
+[submodule "libucontext"]
+ path = libucontext
+ url = https://github.com/utmapp/libucontext.git
diff --git a/libucontext b/libucontext
new file mode 160000
index 0000000000..455ecd495f
--- /dev/null
+++ b/libucontext
@@ -0,0 +1 @@
+Subproject commit 455ecd495f706d5b57be3ff5b572c120c2a7a5a2
diff --git a/meson_options.txt b/meson_options.txt
index b4f1801875..da24102898 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -64,6 +64,8 @@ option('xkbcommon', type : 'feature', value : 'auto',
description: 'xkbcommon support')
option('virtiofsd', type: 'feature', value: 'auto',
description: 'build virtiofs daemon (virtiofsd)')
+option('ucontext', type : 'feature', value : 'disabled',
+ description: 'libucontext support')
option('capstone', type: 'combo', value: 'auto',
choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
--
2.28.0
next prev parent reply other threads:[~2020-11-08 23:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-08 23:24 [PATCH v5 0/7] iOS and Apple Silicon host support Joelle van Dyne
2020-11-08 23:24 ` [PATCH v5 1/7] configure: option to disable host block devices Joelle van Dyne
2020-11-08 23:24 ` [PATCH v5 2/7] configure: cross-compiling with empty cross_prefix Joelle van Dyne
2020-11-20 10:23 ` Philippe Mathieu-Daudé
2020-11-08 23:24 ` [PATCH v5 3/7] qemu: add support for iOS host Joelle van Dyne
2020-11-08 23:24 ` Joelle van Dyne [this message]
2020-11-09 0:01 ` [PATCH v5 4/7] coroutine: add libucontext as external library Philippe Mathieu-Daudé
2020-11-08 23:24 ` [PATCH v5 5/7] slirp: update build flags for iOS resolv fix Joelle van Dyne
2020-11-08 23:24 ` [PATCH v5 6/7] tcg: implement JIT for iOS and Apple Silicon Joelle van Dyne
2020-11-20 9:08 ` Alexander Graf
2020-11-20 14:15 ` Alexander Graf
2020-11-20 14:36 ` Richard Henderson
2020-11-20 15:58 ` Joelle van Dyne
2020-11-25 1:15 ` Alexander Graf
2020-11-25 2:08 ` Joelle van Dyne
2020-12-11 10:54 ` Alexander Graf
2020-12-11 12:35 ` Stefan Hajnoczi
2020-12-11 18:47 ` Joelle van Dyne
2020-11-08 23:24 ` [PATCH v5 7/7] block: check availablity for preadv/pwritev on mac Joelle van Dyne
2020-11-20 10:32 ` Philippe Mathieu-Daudé
2020-11-20 15:49 ` Joelle van Dyne
2020-11-20 16:20 ` Philippe Mathieu-Daudé
2020-11-20 16:55 ` Joelle van Dyne
2020-11-12 16:26 ` [PATCH v5 0/7] iOS and Apple Silicon host support Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201108232425.1705-5-j@getutm.app \
--to=j@getutm.app \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.