From patchwork Fri Jun 6 09:46:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 356770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 691C514009F for ; Fri, 6 Jun 2014 19:53:07 +1000 (EST) Received: from localhost ([::1]:46234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsqpd-0007th-Bx for incoming@patchwork.ozlabs.org; Fri, 06 Jun 2014 05:53:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsqju-0006GE-Ks for qemu-devel@nongnu.org; Fri, 06 Jun 2014 05:47:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wsqjm-0001XC-Er for qemu-devel@nongnu.org; Fri, 06 Jun 2014 05:47:10 -0400 Received: from afflict.kos.to ([92.243.29.197]:38374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsqjm-0001WL-4g for qemu-devel@nongnu.org; Fri, 06 Jun 2014 05:47:02 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id BE9EB26552; Fri, 6 Jun 2014 11:46:59 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 6 Jun 2014 12:46:53 +0300 Message-Id: <1402048017-30604-10-git-send-email-riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Riku Voipio Subject: [Qemu-devel] [PATCH v2 09/13] signal/all/setup_frame remove __put_user checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Riku Voipio Remove "if(__put_user" checks and their related error paths for all architecture's setup_frame, setup_rt_frame and similar. Remove the unlock_user_struct when the only way to end up there is from failed lock_user_struct. Remove err variable if there are no users for it in the function anymore. Signed-off-by: Riku Voipio --- linux-user/signal.c | 97 ++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 72 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 8edf1f9..f97ed58 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -971,7 +971,7 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, { abi_ulong frame_addr, addr; struct rt_sigframe *frame; - int i, err = 0; + int i; frame_addr = get_sigframe(ka, env, sizeof(*frame)); @@ -996,10 +996,9 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env, set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate)); - for(i = 0; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i])) - goto give_sigsegv; - } + for(i = 0; i < TARGET_NSIG_WORDS; i++) { + __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); + } /* Set up to return from userspace. If provided, use a stub already in userspace. */ @@ -1016,9 +1015,6 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, __put_user(val16, (uint16_t *)(frame->retcode+5)); } - if (err) - goto give_sigsegv; - /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; env->eip = ka->_sa_handler; @@ -1034,7 +1030,6 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, return; give_sigsegv: - unlock_user_struct(frame, frame_addr, 1); if (sig == TARGET_SIGSEGV) ka->_sa_handler = TARGET_SIG_DFL; force_sig(TARGET_SIGSEGV /* , current */); @@ -1592,7 +1587,7 @@ get_sigframe(struct target_sigaction *ka, CPUARMState *regs, int framesize) return (sp - framesize) & ~7; } -static int +static void setup_return(CPUARMState *env, struct target_sigaction *ka, abi_ulong *rc, abi_ulong frame_addr, int usig, abi_ulong rc_addr) { @@ -1616,8 +1611,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_SIGINFO) idx += 2; - if (__put_user(retcodes[idx], rc)) - return 1; + __put_user(retcodes[idx], rc); retcode = rc_addr + thumb; } @@ -1627,8 +1621,6 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, env->regs[14] = retcode; env->regs[15] = handler & (thumb ? ~1 : ~3); cpsr_write(env, cpsr, 0xffffffff); - - return 0; } static abi_ulong *setup_sigframe_v2_vfp(abi_ulong *regspace, CPUARMState *env) @@ -1715,15 +1707,13 @@ static void setup_frame_v1(int usig, struct target_sigaction *ka, setup_sigcontext(&frame->sc, regs, set->sig[0]); - for(i = 1; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->extramask[i - 1])) - goto end; - } + for(i = 1; i < TARGET_NSIG_WORDS; i++) { + __put_user(set->sig[i], &frame->extramask[i - 1]); + } setup_return(regs, ka, &frame->retcode, frame_addr, usig, frame_addr + offsetof(struct sigframe_v1, retcode)); -end: unlock_user_struct(frame, frame_addr, 1); } @@ -1785,8 +1775,7 @@ static void setup_rt_frame_v1(int usig, struct target_sigaction *ka, setup_sigcontext(&frame->uc.tuc_mcontext, env, set->sig[0]); for(i = 0; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i])) - goto end; + __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } setup_return(env, ka, &frame->retcode, frame_addr, usig, @@ -1795,7 +1784,6 @@ static void setup_rt_frame_v1(int usig, struct target_sigaction *ka, env->regs[1] = info_addr; env->regs[2] = uc_addr; -end: unlock_user_struct(frame, frame_addr, 1); } @@ -2919,8 +2907,7 @@ static void setup_frame(int sig, struct target_sigaction * ka, setup_sigcontext(regs, &frame->sf_sc); for(i = 0; i < TARGET_NSIG_WORDS; i++) { - if(__put_user(set->sig[i], &frame->sf_mask.sig[i])) - goto give_sigsegv; + __put_user(set->sig[i], &frame->sf_mask.sig[i]); } /* @@ -2947,7 +2934,6 @@ static void setup_frame(int sig, struct target_sigaction * ka, return; give_sigsegv: - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV/*, current*/); } @@ -3527,7 +3513,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, { struct target_signal_frame *frame; abi_ulong frame_addr; - int err = 0; int i; frame_addr = get_sigframe(ka, env, sizeof *frame); @@ -3536,12 +3521,9 @@ static void setup_frame(int sig, struct target_sigaction *ka, /* Save the mask. */ __put_user(set->sig[0], &frame->uc.tuc_mcontext.oldmask); - if (err) - goto badframe; for(i = 1; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->extramask[i - 1])) - goto badframe; + __put_user(set->sig[i], &frame->extramask[i - 1]); } setup_sigcontext(&frame->uc.tuc_mcontext, env); @@ -3566,9 +3548,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, env->regs[15] = ((unsigned long)frame->tramp) - 8; } - if (err) - goto badframe; - /* Set up registers for signal handler */ env->regs[1] = frame_addr; /* Signal handler args: */ @@ -3583,7 +3562,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, unlock_user_struct(frame, frame_addr, 1); return; badframe: - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV); } @@ -3714,7 +3692,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, { struct target_signal_frame *frame; abi_ulong frame_addr; - int err = 0; int i; frame_addr = get_sigframe(env, sizeof *frame); @@ -3735,13 +3712,10 @@ static void setup_frame(int sig, struct target_sigaction *ka, /* Save the mask. */ __put_user(set->sig[0], &frame->sc.oldmask); - if (err) - goto badframe; - for(i = 1; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->extramask[i - 1])) - goto badframe; - } + for(i = 1; i < TARGET_NSIG_WORDS; i++) { + __put_user(set->sig[i], &frame->extramask[i - 1]); + } setup_sigcontext(&frame->sc, env); @@ -3755,7 +3729,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, unlock_user_struct(frame, frame_addr, 1); return; badframe: - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV); } @@ -4144,9 +4117,7 @@ static void setup_frame(int sig, struct target_sigaction *ka, } qemu_log("%s: 1\n", __FUNCTION__); - if (__put_user(set->sig[0], &frame->sc.oldmask[0])) { - goto give_sigsegv; - } + __put_user(set->sig[0], &frame->sc.oldmask[0]); save_sigregs(env, &frame->sregs); @@ -4161,15 +4132,12 @@ static void setup_frame(int sig, struct target_sigaction *ka, } else { env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE; - if (__put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn, - (uint16_t *)(frame->retcode))) - goto give_sigsegv; + __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn, + (uint16_t *)(frame->retcode)); } /* Set up backchain. */ - if (__put_user(env->regs[15], (abi_ulong *) frame)) { - goto give_sigsegv; - } + __put_user(env->regs[15], (abi_ulong *) frame); /* Set up registers for signal handler */ env->regs[15] = frame_addr; @@ -4184,15 +4152,12 @@ static void setup_frame(int sig, struct target_sigaction *ka, env->regs[5] = 0; // FIXME: no clue... current->thread.prot_addr; /* Place signal number on stack to allow backtrace from handler. */ - if (__put_user(env->regs[2], (int *) &frame->signo)) { - goto give_sigsegv; - } + __put_user(env->regs[2], (int *) &frame->signo); unlock_user_struct(frame, frame_addr, 1); return; give_sigsegv: qemu_log("%s: give_sigsegv\n", __FUNCTION__); - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV); } @@ -4233,16 +4198,12 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE; } else { env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE; - if (__put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn, - (uint16_t *)(frame->retcode))) { - goto give_sigsegv; - } + __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn, + (uint16_t *)(frame->retcode)); } /* Set up backchain. */ - if (__put_user(env->regs[15], (abi_ulong *) frame)) { - goto give_sigsegv; - } + __put_user(env->regs[15], (abi_ulong *) frame); /* Set up registers for signal handler */ env->regs[15] = frame_addr; @@ -4255,7 +4216,6 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, give_sigsegv: qemu_log("%s: give_sigsegv\n", __FUNCTION__); - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV); } @@ -5053,7 +5013,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, abi_ulong frame_addr; abi_ulong retcode_addr; abi_ulong sc_addr; - int err = 0; int i; frame_addr = get_sigframe(ka, env, sizeof *frame); @@ -5068,8 +5027,7 @@ static void setup_frame(int sig, struct target_sigaction *ka, setup_sigcontext(&frame->sc, env, set->sig[0]); for(i = 1; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->extramask[i - 1])) - goto give_sigsegv; + __put_user(set->sig[i], &frame->extramask[i - 1]); } /* Set up to return from userspace. */ @@ -5082,9 +5040,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, __put_user(0x70004e40 + (TARGET_NR_sigreturn << 16), (long *)(frame->retcode)); - if (err) - goto give_sigsegv; - /* Set up to return from userspace */ env->aregs[7] = frame_addr; @@ -5094,7 +5049,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, return; give_sigsegv: - unlock_user_struct(frame, frame_addr, 1); force_sig(TARGET_SIGSEGV); } @@ -5208,8 +5162,7 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, goto give_sigsegv; for(i = 0; i < TARGET_NSIG_WORDS; i++) { - if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i])) - goto give_sigsegv; + __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } /* Set up to return from userspace. */