[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#805826: qemu-sh4*: Unsupported syscall: 186



Package: qemu
Version: 1:2.4+dfsg-4
Severity: normal
Tags: patch
User: debian-sh4@superh.org
Usertags: sh4

Hello!

While setting up qemu-sh4 with sbuild to create a fast build environment
for buildd purposes [1], I tried installing a Python environment in the
chroot which resulted in an error message about a missing syscall:

       Unsupported syscall: 186

Reading through the sources, I noticed that the missing syscall is simply
not enabled for the sh4 target in linux-user/syscall.c:8153. Changing
the sources to enable the syscall fixes the problem. A patch to do that
for the Debian package is attached to this bug report.

The following minimal test case verifies that the patch works by emitting
the message "recovered" instead of just segfaulting which can also be
verified on other targets or native Linux environments by commenting
out the sigaltstack call.

Besides, the patch cannot result in a regression for other targets, so
it should be 100% safe to apply.

Test case:

=============================================================

#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>

jmp_buf exit_jmp;

void handler(int x)
{
  longjmp(exit_jmp, 1);
}

int f(void)
{
  return f();
}

int main(void)
{
  stack_t sigstack;
  sigstack.ss_sp = malloc(1024*1024);
  sigstack.ss_size = 1024*1024;
  sigstack.ss_flags = 0;
  sigaltstack(&sigstack, NULL);
  struct sigaction sa;
  sa.sa_handler = handler;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = SA_ONSTACK;
  sigaction(SIGSEGV, &sa, NULL);
  if (setjmp(exit_jmp) == 0)
  {
    return f();
  }
  puts("recovered");
  return 0;
}

=============================================================

I have also filed this bug upstream [2]. However, since qemu is currently
in freeze, it's unlikely that the patch gets merged anytime soon. However,
since we are planning to use qemu to set up additional build environment
for Debian's sh4 port, it would be very important for us to have the problem
fixed in Debian rather soon.

> [1] https://wiki.debian.org/SH4/sbuildQEMU
> [2] https://bugs.launchpad.net/qemu/+bug/1516408

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
Description: Enable sigaltstack syscall for sh4 target
 This patched enables the sigaltstack syscall for the sh4 target
 where it is currently disabled despite the fact that all the
 necessary code pieces for the implementation are there. A small
 test case which verifies that the sigaltstack syscall work
 properly after applying the patch can be found on the qemu
 upstream bug tracker: https://bugs.launchpad.net/qemu/+bug/1516408
 .

--- qemu-2.4+dfsg.orig/linux-user/syscall.c
+++ qemu-2.4+dfsg/linux-user/syscall.c
@@ -8152,7 +8152,8 @@ abi_long do_syscall(void *cpu_env, int n
     case TARGET_NR_sigaltstack:
 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
     defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
-    defined(TARGET_M68K) || defined(TARGET_S390X) || defined(TARGET_OPENRISC)
+    defined(TARGET_M68K) || defined(TARGET_S390X) || defined(TARGET_OPENRISC) || \
+    defined(TARGET_SH4)
         ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env));
         break;
 #else

Reply to: