]> Git Repo - qemu.git/commitdiff
linux-user/ppc: Implement swapcontext syscall
authorRichard Henderson <[email protected]>
Wed, 18 Jul 2018 20:06:48 +0000 (13:06 -0700)
committerLaurent Vivier <[email protected]>
Sun, 22 Jul 2018 19:33:45 +0000 (21:33 +0200)
This allows the tests generated by debian-powerpc-user-cross
to function properly, especially tests/test-coroutine.

Technically this syscall is available to both ppc32 and ppc64,
but only ppc32 glibc actually uses it.  Thus the ppc64 path is
untested.

Signed-off-by: Richard Henderson <[email protected]>
Tested-by: Alex Bennée <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Message-Id: <20180718200648[email protected]>

linux-user/ppc/signal.c
linux-user/qemu.h
linux-user/syscall.c

index ef4c518f111928852e4bd16dbae422eebc1f592e..2ae120a2bc71614ba66dce50f7432c8d7ded5b39 100644 (file)
@@ -675,3 +675,59 @@ sigsegv:
     force_sig(TARGET_SIGSEGV);
     return -TARGET_QEMU_ESIGRETURN;
 }
+
+/* This syscall implements {get,set,swap}context for userland.  */
+abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
+                        abi_ulong unew_ctx, abi_long ctx_size)
+{
+    struct target_ucontext *uctx;
+    struct target_mcontext *mctx;
+
+    /* For ppc32, ctx_size is "reserved for future use".
+     * For ppc64, we do not yet support the VSX extension.
+     */
+    if (ctx_size < sizeof(struct target_ucontext)) {
+        return -TARGET_EINVAL;
+    }
+
+    if (uold_ctx) {
+        TaskState *ts = (TaskState *)thread_cpu->opaque;
+
+        if (!lock_user_struct(VERIFY_WRITE, uctx, uold_ctx, 1)) {
+            return -TARGET_EFAULT;
+        }
+
+#ifdef TARGET_PPC64
+        mctx = &uctx->tuc_sigcontext.mcontext;
+#else
+        /* ??? The kernel aligns the pointer down here into padding, but
+         * in setup_rt_frame we don't.  Be self-compatible for now.
+         */
+        mctx = &uctx->tuc_mcontext;
+        __put_user(h2g(mctx), &uctx->tuc_regs);
+#endif
+
+        save_user_regs(env, mctx);
+        host_to_target_sigset(&uctx->tuc_sigmask, &ts->signal_mask);
+
+        unlock_user_struct(uctx, uold_ctx, 1);
+    }
+
+    if (unew_ctx) {
+        int err;
+
+        if (!lock_user_struct(VERIFY_READ, uctx, unew_ctx, 1)) {
+            return -TARGET_EFAULT;
+        }
+        err = do_setcontext(uctx, env, 0);
+        unlock_user_struct(uctx, unew_ctx, 1);
+
+        if (err) {
+            /* We cannot return to a partially updated context.  */
+            force_sig(TARGET_SIGSEGV);
+        }
+        return -TARGET_QEMU_ESIGRETURN;
+    }
+
+    return 0;
+}
index 7b16a1cdeae61f010fb08594014e6266ed802aca..b4959e41c6e384f4523573049db4b56a22ee3880 100644 (file)
@@ -396,6 +396,8 @@ long do_sigreturn(CPUArchState *env);
 long do_rt_sigreturn(CPUArchState *env);
 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
 int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
+abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
+                        abi_ulong unew_ctx, abi_long ctx_size);
 /**
  * block_signals: block all signals while handling this guest syscall
  *
index 3df3bdffb2e54e2c396638f3f55fc8cf0f7df1ad..dfc851cc35faf0c5031c54859a4799223378c962 100644 (file)
@@ -12790,6 +12790,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(kcmp(arg1, arg2, arg3, arg4, arg5));
         break;
 #endif
+#ifdef TARGET_NR_swapcontext
+    case TARGET_NR_swapcontext:
+        /* PowerPC specific.  */
+        ret = do_swapcontext(cpu_env, arg1, arg2, arg3);
+        break;
+#endif
 
     default:
     unimplemented:
This page took 0.050194 seconds and 4 git commands to generate.