From patchwork Fri Feb 16 21:56:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 128652 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1019777ljc; Fri, 16 Feb 2018 14:01:43 -0800 (PST) X-Google-Smtp-Source: AH8x225/GxqJ+G+CdNGEKO0yC1kZ+cXbVEhTk2/aGQ3XP+MqTqpmFp9gHOWOKG3MhvIrBe6ry75+ X-Received: by 10.37.81.3 with SMTP id f3mr5490019ybb.99.1518818503688; Fri, 16 Feb 2018 14:01:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518818503; cv=none; d=google.com; s=arc-20160816; b=KtI18mUYrp3hg39ppg2KCkMbNDlDYfxxsRzjHyMRQjEdbFZWnLJ49zYsREPaKn+CMk 15GuxBCdaQ5QMwlqUW7MwotlTj/DIlVR0dX7LYpcvK2bieNyr/Sje1RS0PtS5eIu40Mt vKmVGsEqKZZOl18hNwX0MINA2S/QBqicUwCsmAmm9wMieo6qwoxYmYC7d+f9OZphEGI2 79D7Nr1r18uRP7C2r31nEe39qItpivEyqHucrSopIywuU+FF660BT6lekNTNQOIJJZZ2 J8OArkxVRYczQV+PooX7ONgmzcTbSCapWPzKWRnFR8mKCq/CcQwpMAMnlsf4TUnjCoRN 7XJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=uQrg57S+1ciiLZZckCpcfg+FQGP817cnRwWY4yG6r2w=; b=SHYLTJqvY/ReQg7OCqUEUl2aHf1/Gm1TY+g2rf/9HFyIhyQ721im2wzH7bYLOxcGu0 j+/PMWW9yjW5a/tDSr+oT+ydsXD6QtBXXLw5EZhvW+RHyQ0XmDR0XPEOd9wQARItYVyO y+z35NBhhZcKfcO29iqglSXe8qaJo477WSgLZw1n/dSjvWJ4kIMeTFrdVi9GLevCw+vM Bro7Xv+AFheO6QLz+WDLMaqtqci4vGGfaZZiOPWpSKi3Rlu6zmnOr6m7UVe+nVtDi6Qk 4B4sagm5N/80gJOp+7VOD8yh6jfJ/RXRDF0nYu6yCW3fJuwl0+2LUd4w8KnaSfW4Gz7Y sYmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IUsjKqvG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y18si1049069ybm.707.2018.02.16.14.01.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Feb 2018 14:01:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IUsjKqvG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emo4d-00024A-30 for patch@linaro.org; Fri, 16 Feb 2018 17:01:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emnzO-0006kG-15 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emnzM-0007Ot-Rg for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:18 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:43539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1emnzM-0007Og-JO for qemu-devel@nongnu.org; Fri, 16 Feb 2018 16:56:16 -0500 Received: by mail-pg0-x244.google.com with SMTP id f6so3432386pgs.10 for ; Fri, 16 Feb 2018 13:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uQrg57S+1ciiLZZckCpcfg+FQGP817cnRwWY4yG6r2w=; b=IUsjKqvGqyA4ctf+VY4tmJLrLeVs0yMTd+KUvVdMVJS+4m4tv2UqTifh6Q96UvcymV RdUvbnj7YN8xV4u3nUi6th6vL3F+xWfp0uh5hnPRQD5kKGu5ABTXv/TGY9e2rI76wsGX 5dZrDc7BM+uzIdztUD6O7Xz+UhdxizsOYhvxA= 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:in-reply-to :references; bh=uQrg57S+1ciiLZZckCpcfg+FQGP817cnRwWY4yG6r2w=; b=DWGoirBs1/06JN2YsTmUWBXMNhkA78Sirewzw0YaYgvJdFr4+EmBHGKkJGiTUnVbN5 RfL57JVa3xlDqN++Q2sAZwTuFuQG6ia2YdDP223cvqTvJJa4j38yLTsXyGvv0QxUVf68 /KlKXGKXhXcByC/V2PcXWq54BIBt8G+4VH1hedQKxJkYB9SYZRPMizHwUrbaYdHr5BQ9 9ovFP3UuEh/5Mq7qoxOXSR40PXRppxkJDAHX13MUgaxmg2Y4O5CVL+oAyDrGhYH71mqw A+CKk4fogZKDk1uS5nErQKpAzhhxhP3e7iyCUPNANI3WT0LxWYhHsSXTgMYXsJ/89Mbu 4VIw== X-Gm-Message-State: APf1xPBfCcTbqr1lbeHz7XNyDRWV0R6I+wxOSumALiyJq37CEPSHU5t+ mSHnN88G7Y9rcXp9A3nJJsrYSrLOGhk= X-Received: by 10.98.15.15 with SMTP id x15mr7433664pfi.197.1518818175155; Fri, 16 Feb 2018 13:56:15 -0800 (PST) Received: from cloudburst.twiddle.net ([50.0.192.64]) by smtp.gmail.com with ESMTPSA id b88sm39230538pfd.108.2018.02.16.13.56.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2018 13:56:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 13:56:05 -0800 Message-Id: <20180216215608.13227-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180216215608.13227-1-richard.henderson@linaro.org> References: <20180216215608.13227-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v3 2/5] aarch64-linux-user: Split out helpers for guest signal handling 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out helpers from target_setup_frame and target_restore_sigframe for dealing with general registers, fpsimd registers, and the end record. When we add support for sve registers, the relative positions of these will change. Signed-off-by: Richard Henderson --- linux-user/signal.c | 120 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 51 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/linux-user/signal.c b/linux-user/signal.c index 9a380b9e31..25c9743aed 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1462,16 +1462,17 @@ struct target_rt_sigframe { uint32_t tramp[2]; }; -static int target_setup_sigframe(struct target_rt_sigframe *sf, - CPUARMState *env, target_sigset_t *set) +static void target_setup_general_frame(struct target_rt_sigframe *sf, + CPUARMState *env, target_sigset_t *set) { int i; - struct target_aux_context *aux = - (struct target_aux_context *)sf->uc.tuc_mcontext.__reserved; - /* set up the stack frame for unwinding */ - __put_user(env->xregs[29], &sf->fp); - __put_user(env->xregs[30], &sf->lr); + __put_user(0, &sf->uc.tuc_flags); + __put_user(0, &sf->uc.tuc_link); + + __put_user(target_sigaltstack_used.ss_sp, &sf->uc.tuc_stack.ss_sp); + __put_user(sas_ss_flags(env->xregs[31]), &sf->uc.tuc_stack.ss_flags); + __put_user(target_sigaltstack_used.ss_size, &sf->uc.tuc_stack.ss_size); for (i = 0; i < 31; i++) { __put_user(env->xregs[i], &sf->uc.tuc_mcontext.regs[i]); @@ -1485,39 +1486,42 @@ static int target_setup_sigframe(struct target_rt_sigframe *sf, for (i = 0; i < TARGET_NSIG_WORDS; i++) { __put_user(set->sig[i], &sf->uc.tuc_sigmask.sig[i]); } +} + +static void target_setup_fpsimd_record(struct target_fpsimd_context *fpsimd, + CPUARMState *env) +{ + int i; + + __put_user(TARGET_FPSIMD_MAGIC, &fpsimd->head.magic); + __put_user(sizeof(struct target_fpsimd_context), &fpsimd->head.size); + __put_user(vfp_get_fpsr(env), &fpsimd->fpsr); + __put_user(vfp_get_fpcr(env), &fpsimd->fpcr); for (i = 0; i < 32; i++) { uint64_t *q = aa64_vfp_qreg(env, i); #ifdef TARGET_WORDS_BIGENDIAN - __put_user(q[0], &aux->fpsimd.vregs[i * 2 + 1]); - __put_user(q[1], &aux->fpsimd.vregs[i * 2]); + __put_user(q[0], &fpsimd->vregs[i * 2 + 1]); + __put_user(q[1], &fpsimd->vregs[i * 2]); #else - __put_user(q[0], &aux->fpsimd.vregs[i * 2]); - __put_user(q[1], &aux->fpsimd.vregs[i * 2 + 1]); + __put_user(q[0], &fpsimd->vregs[i * 2]); + __put_user(q[1], &fpsimd->vregs[i * 2 + 1]); #endif } - __put_user(vfp_get_fpsr(env), &aux->fpsimd.fpsr); - __put_user(vfp_get_fpcr(env), &aux->fpsimd.fpcr); - __put_user(TARGET_FPSIMD_MAGIC, &aux->fpsimd.head.magic); - __put_user(sizeof(struct target_fpsimd_context), - &aux->fpsimd.head.size); - - /* set the "end" magic */ - __put_user(0, &aux->end.magic); - __put_user(0, &aux->end.size); - - return 0; } -static int target_restore_sigframe(CPUARMState *env, - struct target_rt_sigframe *sf) +static void target_setup_end_record(struct target_aarch64_ctx *end) +{ + __put_user(0, &end->magic); + __put_user(0, &end->size); +} + +static void target_restore_general_frame(CPUARMState *env, + struct target_rt_sigframe *sf) { sigset_t set; - int i; - struct target_aux_context *aux = - (struct target_aux_context *)sf->uc.tuc_mcontext.__reserved; - uint32_t magic, size, fpsr, fpcr; uint64_t pstate; + int i; target_to_host_sigset(&set, &sf->uc.tuc_sigmask); set_sigmask(&set); @@ -1530,30 +1534,48 @@ static int target_restore_sigframe(CPUARMState *env, __get_user(env->pc, &sf->uc.tuc_mcontext.pc); __get_user(pstate, &sf->uc.tuc_mcontext.pstate); pstate_write(env, pstate); +} - __get_user(magic, &aux->fpsimd.head.magic); - __get_user(size, &aux->fpsimd.head.size); +static void target_restore_fpsimd_record(CPUARMState *env, + struct target_fpsimd_context *fpsimd) +{ + uint32_t fpsr, fpcr; + int i; - if (magic != TARGET_FPSIMD_MAGIC - || size != sizeof(struct target_fpsimd_context)) { - return 1; - } + __get_user(fpsr, &fpsimd->fpsr); + vfp_set_fpsr(env, fpsr); + __get_user(fpcr, &fpsimd->fpcr); + vfp_set_fpcr(env, fpcr); for (i = 0; i < 32; i++) { uint64_t *q = aa64_vfp_qreg(env, i); #ifdef TARGET_WORDS_BIGENDIAN - __get_user(q[0], &aux->fpsimd.vregs[i * 2 + 1]); - __get_user(q[1], &aux->fpsimd.vregs[i * 2]); + __get_user(q[0], &fpsimd->vregs[i * 2 + 1]); + __get_user(q[1], &fpsimd->vregs[i * 2]); #else - __get_user(q[0], &aux->fpsimd.vregs[i * 2]); - __get_user(q[1], &aux->fpsimd.vregs[i * 2 + 1]); + __get_user(q[0], &fpsimd->vregs[i * 2]); + __get_user(q[1], &fpsimd->vregs[i * 2 + 1]); #endif } - __get_user(fpsr, &aux->fpsimd.fpsr); - vfp_set_fpsr(env, fpsr); - __get_user(fpcr, &aux->fpsimd.fpcr); - vfp_set_fpcr(env, fpcr); +} +static int target_restore_sigframe(CPUARMState *env, + struct target_rt_sigframe *sf) +{ + struct target_aux_context *aux + = (struct target_aux_context *)sf->uc.tuc_mcontext.__reserved; + uint32_t magic, size; + + target_restore_general_frame(env, sf); + + __get_user(magic, &aux->fpsimd.head.magic); + __get_user(size, &aux->fpsimd.head.size); + if (magic == TARGET_FPSIMD_MAGIC + && size == sizeof(struct target_fpsimd_context)) { + target_restore_fpsimd_record(env, &aux->fpsimd); + } else { + return 1; + } return 0; } @@ -1580,6 +1602,7 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, CPUARMState *env) { struct target_rt_sigframe *frame; + struct target_aux_context *aux; abi_ulong frame_addr, return_addr; frame_addr = get_sigframe(ka, env); @@ -1587,17 +1610,12 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { goto give_sigsegv; } + aux = (struct target_aux_context *)frame->uc.tuc_mcontext.__reserved; - __put_user(0, &frame->uc.tuc_flags); - __put_user(0, &frame->uc.tuc_link); + target_setup_general_frame(frame, env, set); + target_setup_fpsimd_record(&aux->fpsimd, env); + target_setup_end_record(&aux->end); - __put_user(target_sigaltstack_used.ss_sp, - &frame->uc.tuc_stack.ss_sp); - __put_user(sas_ss_flags(env->xregs[31]), - &frame->uc.tuc_stack.ss_flags); - __put_user(target_sigaltstack_used.ss_size, - &frame->uc.tuc_stack.ss_size); - target_setup_sigframe(frame, env, set); if (ka->sa_flags & TARGET_SA_RESTORER) { return_addr = ka->sa_restorer; } else {