Patchwork [3/3] coroutine: adding enable/disable options for sigaltstack method

login
register
mail settings
Submitter Alex Barcelo
Date Feb. 13, 2012, 2:42 p.m.
Message ID <1329144150-7720-4-git-send-email-abarcelo@ac.upc.edu>
Download mbox | patch
Permalink /patch/140913/
State New
Headers show

Comments

Alex Barcelo - Feb. 13, 2012, 2:42 p.m.
It's possible to enable/disable sigaltstack, but it always has
less priority than ucontext method (to force sigaltstack,
ucontext has to be disabled).

Signed-off-by: Alex Barcelo <abarcelo@ac.upc.edu>
---
 Makefile.objs |    4 ++++
 configure     |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
Daniel P. Berrange - Feb. 13, 2012, 2:49 p.m.
On Mon, Feb 13, 2012 at 03:42:30PM +0100, Alex Barcelo wrote:
> It's possible to enable/disable sigaltstack, but it always has
> less priority than ucontext method (to force sigaltstack,
> ucontext has to be disabled).
> 
> Signed-off-by: Alex Barcelo <abarcelo@ac.upc.edu>
> ---
>  Makefile.objs |    4 ++++
>  configure     |   39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+), 0 deletions(-)
> 
> diff --git a/Makefile.objs b/Makefile.objs
> index 391e524..8874825 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -17,8 +17,12 @@ coroutine-obj-y += qemu-coroutine-sleep.o
>  ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
>  coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
>  else
> +ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
> +coroutine-obj-$(CONFIG_POSIX) += coroutine-sigaltstack.o
> +else
>  coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o
>  endif
> +endif
>  coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
>  
>  #######################################################################
> diff --git a/configure b/configure
> index ed40da8..e9c27f3 100755
> --- a/configure
> +++ b/configure
> @@ -191,6 +191,7 @@ zlib="yes"
>  guest_agent="yes"
>  libiscsi=""
>  ucontext=""
> +sigaltstack=""
>  
>  # parse CC options first
>  for opt do
> @@ -803,6 +804,10 @@ for opt do
>    ;;
>    --disable-ucontext) ucontext="no"
>    ;;
> +  --enable-sigaltstack) sigaltstack="yes"
> +  ;;
> +  --disable-sigaltstack) sigaltstack="no"
> +  ;;
>    *) echo "ERROR: unknown option $opt"; show_help="yes"
>    ;;
>    esac
> @@ -1091,6 +1096,8 @@ echo "  --disable-guest-agent    disable building of the QEMU Guest Agent"
>  echo "  --enable-guest-agent     enable building of the QEMU Guest Agent"
>  echo "  --disable-ucontext       disable ucontext functions for coroutines"
>  echo "  --enable-ucontext        enable ucontext functions for coroutines"
> +echo "  --disable-sigaltstack    disable sigaltstack functions for coroutines"
> +echo "  --enable-sigaltstack    enable sigaltstack functions for coroutines"

Since the 3 different coroutine impls are mutually exclusive
choices, perhaps it'd be preferable to just have a single
configure argument like

   --with-couroutines=[ucontext|sigaltstack|gthread]

Thus avoiding the non-sensical scenario of the user specifying

   --enable-ucontext --enable-sigaltstack

Regards,
Daniel
Alex Barcelo - Feb. 13, 2012, 3:16 p.m.
On Mon, Feb 13, 2012 at 15:49, Daniel P. Berrange <berrange@redhat.com> wrote:
> Since the 3 different coroutine impls are mutually exclusive
> choices, perhaps it'd be preferable to just have a single
> configure argument like
>
>   --with-couroutines=[ucontext|sigaltstack|gthread]
>
> Thus avoiding the non-sensical scenario of the user specifying
>
>   --enable-ucontext --enable-sigaltstack

Yes. Now that you mention it... it's the natural way. The v2 will be this way :)

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 391e524..8874825 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -17,8 +17,12 @@  coroutine-obj-y += qemu-coroutine-sleep.o
 ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
 coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
 else
+ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
+coroutine-obj-$(CONFIG_POSIX) += coroutine-sigaltstack.o
+else
 coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o
 endif
+endif
 coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
 
 #######################################################################
diff --git a/configure b/configure
index ed40da8..e9c27f3 100755
--- a/configure
+++ b/configure
@@ -191,6 +191,7 @@  zlib="yes"
 guest_agent="yes"
 libiscsi=""
 ucontext=""
+sigaltstack=""
 
 # parse CC options first
 for opt do
@@ -803,6 +804,10 @@  for opt do
   ;;
   --disable-ucontext) ucontext="no"
   ;;
+  --enable-sigaltstack) sigaltstack="yes"
+  ;;
+  --disable-sigaltstack) sigaltstack="no"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -1091,6 +1096,8 @@  echo "  --disable-guest-agent    disable building of the QEMU Guest Agent"
 echo "  --enable-guest-agent     enable building of the QEMU Guest Agent"
 echo "  --disable-ucontext       disable ucontext functions for coroutines"
 echo "  --enable-ucontext        enable ucontext functions for coroutines"
+echo "  --disable-sigaltstack    disable sigaltstack functions for coroutines"
+echo "  --enable-sigaltstack    enable sigaltstack functions for coroutines"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2745,6 +2752,33 @@  EOF
 fi
 
 ##########################################
+# check, if there is no ucontext, for
+# sigaltstack
+
+sigaltstack_coroutine=no
+if test "$ucontext_coroutine" = "no" -a "$sigaltstack" != "no" ; then
+  cat > $TMPC << EOF
+#include <signal.h>
+int main(void) {
+  stack_t ss;
+  ss.ss_size = SIGSTKSZ;
+  ss.ss_flags = 0;
+  sigaltstack(&ss, 0);
+}
+EOF
+  if compile_prog "" "" ; then
+    sigaltstack_coroutine=yes
+  elif test "$sigaltstack" = "yes"; then
+    echo
+    echo "Error: sigaltstack check failed"
+    echo "Make sure that sigaltstack is supported"
+    echo
+    exit 1
+  fi
+fi
+
+
+##########################################
 # check if we have open_by_handle_at
 
 open_by_hande_at=no
@@ -2936,6 +2970,7 @@  echo "OpenGL support    $opengl"
 echo "libiscsi support  $libiscsi"
 echo "build guest agent $guest_agent"
 echo "ucontext coroutine support    $ucontext_coroutine"
+echo "sigaltstack coroutine support $sigaltstack_coroutine"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3259,6 +3294,10 @@  if test "$ucontext_coroutine" = "yes" ; then
   echo "CONFIG_UCONTEXT_COROUTINE=y" >> $config_host_mak
 fi
 
+if test "$sigaltstack_coroutine" = "yes" ; then
+  echo "CONFIG_SIGALTSTACK_COROUTINE=y" >> $config_host_mak
+fi
+
 if test "$open_by_handle_at" = "yes" ; then
   echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
 fi