diff mbox series

[v6,4/7] coroutine: add libucontext as external library

Message ID 20210105022055.12113-5-j@getutm.app (mailing list archive)
State New, archived
Headers show
Series iOS and Apple Silicon host support | expand

Commit Message

Joelle van Dyne Jan. 5, 2021, 2:20 a.m. UTC
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               | 11 ++++++++++-
 util/coroutine-ucontext.c |  9 +++++++++
 .gitmodules               |  3 +++
 meson_options.txt         |  2 ++
 subprojects/libucontext   |  1 +
 6 files changed, 45 insertions(+), 4 deletions(-)
 create mode 160000 subprojects/libucontext

Comments

Daniel P. Berrangé Jan. 21, 2021, 4:17 p.m. UTC | #1
On Mon, Jan 04, 2021 at 06:20:52PM -0800, Joelle van Dyne wrote:
> 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               | 11 ++++++++++-
>  util/coroutine-ucontext.c |  9 +++++++++
>  .gitmodules               |  3 +++
>  meson_options.txt         |  2 ++
>  subprojects/libucontext   |  1 +
>  6 files changed, 45 insertions(+), 4 deletions(-)
>  create mode 160000 subprojects/libucontext

> diff --git a/.gitmodules b/.gitmodules
> index 2bdeeacef8..4f02eed79a 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 = subprojects/libucontext
> +	url = https://github.com/utmapp/libucontext.git

Using libucontext looks like a good idea to me, but I noticed that
this is a pointing to a fork of the main libucontext project at

   https://github.com/kaniini/libucontext

The main project appears 100's of commits ahead of the utmapp fork

What is in the utmapp fork that isn't present in the primary libucontext
repo ?  I think if we're going to use libucontext we will want to point
to the primary project, and this means anything custom in the fork will
need to get submitted upstream. Maybe you've already started doing that
making this a non-issue ?

Regards,
Daniel
Joelle van Dyne Jan. 21, 2021, 5:11 p.m. UTC | #2
Yes since the submission of this patch, we have been working with the
original authors to merge all the changes upstream. The next patch should
point to the original repo.

-j

On Thursday, January 21, 2021, Daniel P. Berrangé <berrange@redhat.com>
wrote:

> On Mon, Jan 04, 2021 at 06:20:52PM -0800, Joelle van Dyne wrote:
> > 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               | 11 ++++++++++-
> >  util/coroutine-ucontext.c |  9 +++++++++
> >  .gitmodules               |  3 +++
> >  meson_options.txt         |  2 ++
> >  subprojects/libucontext   |  1 +
> >  6 files changed, 45 insertions(+), 4 deletions(-)
> >  create mode 160000 subprojects/libucontext
>
> > diff --git a/.gitmodules b/.gitmodules
> > index 2bdeeacef8..4f02eed79a 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 = subprojects/libucontext
> > +     url = https://github.com/utmapp/libucontext.git
>
> Using libucontext looks like a good idea to me, but I noticed that
> this is a pointing to a fork of the main libucontext project at
>
>    https://github.com/kaniini/libucontext
>
> The main project appears 100's of commits ahead of the utmapp fork
>
> What is in the utmapp fork that isn't present in the primary libucontext
> repo ?  I think if we're going to use libucontext we will want to point
> to the primary project, and this means anything custom in the fork will
> need to get submitted upstream. Maybe you've already started doing that
> making this a non-issue ?
>
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org         -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/
> dberrange :|
>
>
diff mbox series

Patch

diff --git a/configure b/configure
index c1a08f0171..09dd22ebad 100755
--- a/configure
+++ b/configure
@@ -1767,7 +1767,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
@@ -4913,6 +4913,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
@@ -4936,12 +4938,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} subprojects/libucontext"
+  mkdir -p libucontext
+  coroutine_impl=ucontext
+  libucontext="enabled"
+  ;;
+*)
+  coroutine_impl=$coroutine
+  libucontext="disabled"
+  ;;
+esac
+
 if test "$coroutine_pool" = ""; then
   coroutine_pool=yes
 fi
@@ -6487,7 +6504,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
@@ -7069,7 +7086,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 \
         -Dvhost_user_blk_server=$vhost_user_blk_server \
diff --git a/meson.build b/meson.build
index ee333b7a94..900dbc36c8 100644
--- a/meson.build
+++ b/meson.build
@@ -1308,9 +1308,17 @@  if not fdt.found() and fdt_required.length() > 0
   error('fdt not available but required by targets ' + ', '.join(fdt_required))
 endif
 
+ucontext = dependency('libucontext', required : false)
+if not ucontext.found() and get_option('ucontext').enabled()
+  libucontext_proj = subproject('libucontext',
+                                default_options: ['freestanding=true'])
+  ucontext = libucontext_proj.get_variable('libucontext_dep')
+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 #
@@ -1528,7 +1536,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)
 
@@ -2188,6 +2196,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..220c57a743 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/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..4f02eed79a 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 = subprojects/libucontext
+	url = https://github.com/utmapp/libucontext.git
diff --git a/meson_options.txt b/meson_options.txt
index 74ac853548..0a93bccea3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -70,6 +70,8 @@  option('fuse', type: 'feature', value: 'auto',
        description: 'FUSE block device export')
 option('fuse_lseek', type : 'feature', value : 'auto',
        description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
+option('ucontext', type : 'feature', value : 'disabled',
+       description: 'libucontext support')
 
 option('capstone', type: 'combo', value: 'auto',
        choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
diff --git a/subprojects/libucontext b/subprojects/libucontext
new file mode 160000
index 0000000000..fc3b5e724e
--- /dev/null
+++ b/subprojects/libucontext
@@ -0,0 +1 @@ 
+Subproject commit fc3b5e724e21c2c01e2c93b344ab0e34b5a6649b