From nobody Thu May 2 17:45:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531944492726486.84377159660505; Wed, 18 Jul 2018 13:08:12 -0700 (PDT) Received: from localhost ([::1]:38152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffsjw-0007gJ-RZ for importer@patchew.org; Wed, 18 Jul 2018 16:08:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffsiu-0007Iz-7p for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffsir-0003Hs-2x for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:56 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:36288) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffsiq-0003HP-SZ for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:53 -0400 Received: by mail-pg1-x542.google.com with SMTP id m19-v6so2489279pgv.3 for ; Wed, 18 Jul 2018 13:06:52 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id 16-v6sm10796403pfo.164.2018.07.18.13.06.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jul 2018 13:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=WgFADSmcYO1kHCFJUa6Mx6HlkC2oV+z4n0TWgT0vlrE=; b=Mv6JbBJoONptoX3TD6SivaMjPlDCxTVAFjmg3owXWSdtWshk/wkypC80ejucYtM+sB Bsine5xK5ulXbwcyKxz6m0HvuDlgvfZGYBWTbNZojJPndQL2IgGax4TyZYMn4A5WhFSy NX377eiE226pt5qtWNWhhxPtn43sKhM3q32b4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WgFADSmcYO1kHCFJUa6Mx6HlkC2oV+z4n0TWgT0vlrE=; b=s8LpPRK6dwxscTkjyiAu33ZQM0Fnt504O9JxPjDGXhPol9iorj6xhwxbWtMaURv3Gv JVRppiH5pAt8cMgbQgQOeoam0tTATn1+NnjkibR+3F7fle5+sUovfDsOW0m9Ji9riS82 t2Q5FgMIizIJABuAwkWnOMLayOrjJQaJHrPZ1VJyihQ3qDf5LnuoN3FxDDJvaK9FOxTE rz28U3Y8fuXejbFpJIebeyj+TZtXLrKmfrnixDhxbvuLMx14f8m9Ge25YIYNFgQ9uSz5 ONXyg8PUPG4nDVg23OxONJzinJhYxi3YWJ89/aTJsrumZqeFrIz3cUhOTmwFUTBqQs8E ZlTw== X-Gm-Message-State: AOUpUlHm6ukz4wSr8KaxsC8x1YXUGbnC39QJDcHrNjh9q7L6kA5nBgNZ aVxqUv6CI5wTJ1AlswPg6fru8MPBa3w= X-Google-Smtp-Source: AAOMgpfkj/X+gEbOE+mgM33ZyVY+SDv5D9/v973CLt0o1m63q/OxM38uZhgARje8wHEQH9u6rVp9QQ== X-Received: by 2002:a62:dc8f:: with SMTP id c15-v6mr6567689pfl.155.1531944411396; Wed, 18 Jul 2018 13:06:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 18 Jul 2018 13:06:48 -0700 Message-Id: <20180718200648.22529-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH] linux-user/ppc: Implement swapcontext syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alex Benn=C3=A9e --- linux-user/qemu.h | 2 ++ linux-user/ppc/signal.c | 56 +++++++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 6 +++++ 3 files changed, 64 insertions(+) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index bb85c81aa4..e0963676c7 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -395,6 +395,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 * diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index ef4c518f11..2ae120a2bc 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -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 =3D (TaskState *)thread_cpu->opaque; + + if (!lock_user_struct(VERIFY_WRITE, uctx, uold_ctx, 1)) { + return -TARGET_EFAULT; + } + +#ifdef TARGET_PPC64 + mctx =3D &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 =3D &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 =3D 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; +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3df3bdffb2..dfc851cc35 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12790,6 +12790,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_lo= ng arg1, ret =3D get_errno(kcmp(arg1, arg2, arg3, arg4, arg5)); break; #endif +#ifdef TARGET_NR_swapcontext + case TARGET_NR_swapcontext: + /* PowerPC specific. */ + ret =3D do_swapcontext(cpu_env, arg1, arg2, arg3); + break; +#endif =20 default: unimplemented: --=20 2.17.1