From patchwork Fri Jun 1 07:30:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137471 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp610439lji; Fri, 1 Jun 2018 00:40:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI5k4pVMwEJ+LCcjFjegzMCumcO4P1CLnJIsOZYcSCEqdtCnuUvK+7nDjlVPzxb49PzKu7x X-Received: by 2002:ac8:607:: with SMTP id d7-v6mr9350406qth.242.1527838840108; Fri, 01 Jun 2018 00:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527838840; cv=none; d=google.com; s=arc-20160816; b=uCVocxrHHBAyKH97C/at23rUY4aKQFtaold/UI0a7HM9/P59vp/vFDbGi5Itlr66QP YXq4JWbDFyZ0TbhO/QtwyRnYNncIHAbt30OzIA+XfiZ5YrJD80K7mbKRMEJ9ZzlJdsXI wkXVZom/45NhuZtBly1LY+Od7tEZkntxC14DUcG8E481PXp6uDFYegJKvSaxW1Bdqj8W m5ynKsmDpGBn4SYEY6xr+g5VEihuX4MDQ6k5N6aU+JAMl7PLAJcPd3XVWo9WmaScF5Pp +7wTcJfdAUWQ0uk0I4YJ//L+44Pa8UtEUuwJqcTXXkYzdOX2ilE+dTVWzak3Y1720ZhR vphA== 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=sBkEds3zu+lhVLkIVyOM0TUUxvdaBfVFV4ENXOsunws=; b=iCRkgRKb4uni0wxT+Rpb6+GZ76j/vyeoh7jzx0RynFOvZ1EQIrZxDiilJtyQ0n4REK BAegM3v0UQh56wWyOmgMdAcdH7gZlzRoWwWtc2mYDT8TCPwU4NokuNQerZjV1xQa1q8V T19YPH72kDJFFCluxn4M54m1BHj+KGBQ06iUat9W3oR1ddHdwmeIcDdTZJzUSbqg3GRl VZv8XVik4LqmR9tDSvqB6O56BHrUNI4h8lbtsDV2hrrWaOcDdz07NMfCWlh6xZBBkqMB apBpYBqW4M2eu7+fekM8/7fTN2zNqyilqja1Xep5FO0TezetqwWKuHz4qTIEQYGa6YQU GX1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CmThZj37; 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 k30-v6si5840576qtk.393.2018.06.01.00.40.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Jun 2018 00:40:40 -0700 (PDT) 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=CmThZj37; 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]:47859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOefv-0004KS-FP for patch@linaro.org; Fri, 01 Jun 2018 03:40:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOeWk-0005Ue-IS for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOeWj-0000OY-9H for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:10 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:38620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOeWj-0000Nm-0x for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:09 -0400 Received: by mail-pl0-x243.google.com with SMTP id c11-v6so14817025plr.5 for ; Fri, 01 Jun 2018 00:31:08 -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:in-reply-to:references; bh=sBkEds3zu+lhVLkIVyOM0TUUxvdaBfVFV4ENXOsunws=; b=CmThZj37KlNM3qu2Q5R0S5E7Zs7U8AV1ACe/qbZ9HivrLROuuIdC0gx9GRQ/QlxnN9 WbYjTRHF1KOPYkDCg1ab5WP/xoEPgGH3PS9MkRgRIXajiNpEz46K3/kLjA0jZKxWIRK9 to4AwCpJyTtE6THqBBIyD0IWWco4D/Z8YAGu4= 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=sBkEds3zu+lhVLkIVyOM0TUUxvdaBfVFV4ENXOsunws=; b=EUuaf/bta2AzWFhQ/cZ6Lps7K+CuQZbgryLCmeN7xAAPLcisrvCGN2JdHZkeOBvo3Y zduRFSEszZIQDJ18PKd09agAh8Lw1dB4zHIyro65+LwqztuoiWlw5jAbxOoZriQYUF+2 yP5ZDbXjUXPRMDtRTl31WWPImRMgq7y0FhSl2fBciAk61ltOIpnsFwrQLorH/rgu8Kfm 4KPfPR6Sg3JnpwK2Rn9Ua39F9/qrSVZ4YG+T01RSpxCN0jicCDoLtVtyo5M7PVDw5vSR /kkefs2XLrGYqRqpPWmzlD4+prTzZJW/UVCEHTs6Lbeh76uCXJ1o0LsqR5AZDwOs1QO5 dIhw== X-Gm-Message-State: ALKqPwdVDgDFUmDVny3IykhiqiWc0pPzyYvp2Kkz3UpsPApRIPDS4ttU 1y1Ii9dZjI/QZ4/qEz7s8UU8ce/i4VE= X-Received: by 2002:a17:902:a986:: with SMTP id bh6-v6mr10277280plb.245.1527838267794; Fri, 01 Jun 2018 00:31:07 -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 c4-v6sm4431782pgv.86.2018.06.01.00.31.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 00:31:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Jun 2018 00:30:27 -0700 Message-Id: <20180601073050.8054-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601073050.8054-1-richard.henderson@linaro.org> References: <20180601073050.8054-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:c01::243 Subject: [Qemu-devel] [PATCH 10/33] linux-user: Split out brk, close, exit, read, write 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These are relatively simple unconditionally defined syscalls. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 198 ++++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 87 deletions(-) -- 2.17.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fc3dc3f40d..b0d268dab7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7984,6 +7984,112 @@ IMPL(enosys) return do_unimplemented(num); } +IMPL(brk) +{ + return do_brk(arg1); +} + +IMPL(close) +{ + if (is_hostfd(arg1)) { + return -TARGET_EBADF; + } + fd_trans_unregister(arg1); + return get_errno(close(arg1)); +} + +IMPL(exit) +{ + CPUState *cpu = ENV_GET_CPU(cpu_env); + + /* In old applications this may be used to implement _exit(2). + However in threaded applictions it is used for thread termination, + and _exit_group is used for application termination. + Do thread termination if we have more then one thread. */ + if (block_signals()) { + return -TARGET_ERESTARTSYS; + } + + cpu_list_lock(); + + if (CPU_NEXT(first_cpu)) { + /* Remove the CPU from the list. */ + QTAILQ_REMOVE(&cpus, cpu, node); + cpu_list_unlock(); + + TaskState *ts = cpu->opaque; + if (ts->child_tidptr) { + put_user_u32(0, ts->child_tidptr); + sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, + NULL, NULL, 0); + } + thread_cpu = NULL; + object_unref(OBJECT(cpu)); + g_free(ts); + rcu_unregister_thread(); + pthread_exit(NULL); + } else { + cpu_list_unlock(); + +#ifdef TARGET_GPROF + _mcleanup(); +#endif + gdb_exit(cpu_env, arg1); + _exit(arg1); + } + g_assert_not_reached(); +} + +IMPL(read) +{ + abi_long ret; + char *fn; + + if (arg3 == 0) { + return 0; + } + if (is_hostfd(arg1)) { + return -TARGET_EBADF; + } + fn = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!fn) { + return -TARGET_EFAULT; + } + ret = get_errno(safe_read(arg1, fn, arg3)); + if (ret >= 0 && fd_trans_host_to_target_data(arg1)) { + ret = fd_trans_host_to_target_data(arg1)(fn, ret); + } + unlock_user(fn, arg2, ret); + return ret; +} + +IMPL(write) +{ + abi_long ret; + char *fn; + + if (is_hostfd(arg1)) { + return -TARGET_EBADF; + } + fn = lock_user(VERIFY_READ, arg2, arg3, 1); + if (!fn) { + return -TARGET_EFAULT; + } + if (fd_trans_target_to_host_data(arg1)) { + void *copy = g_malloc(arg3); + memcpy(copy, fn, arg3); + ret = fd_trans_target_to_host_data(arg1)(copy, arg3); + if (ret >= 0) { + ret = get_errno(safe_write(arg1, copy, ret)); + } + g_free(copy); + } else { + ret = get_errno(safe_write(arg1, fn, arg3)); + } + unlock_user(fn, arg2, ret); + return ret; +} + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. @@ -7999,83 +8105,6 @@ IMPL(everything_else) char *fn; switch(num) { - case TARGET_NR_exit: - /* In old applications this may be used to implement _exit(2). - However in threaded applictions it is used for thread termination, - and _exit_group is used for application termination. - Do thread termination if we have more then one thread. */ - - if (block_signals()) { - return -TARGET_ERESTARTSYS; - } - - cpu_list_lock(); - - if (CPU_NEXT(first_cpu)) { - TaskState *ts; - - /* Remove the CPU from the list. */ - QTAILQ_REMOVE(&cpus, cpu, node); - - cpu_list_unlock(); - - ts = cpu->opaque; - if (ts->child_tidptr) { - put_user_u32(0, ts->child_tidptr); - sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, - NULL, NULL, 0); - } - thread_cpu = NULL; - object_unref(OBJECT(cpu)); - g_free(ts); - rcu_unregister_thread(); - pthread_exit(NULL); - } - - cpu_list_unlock(); -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); - _exit(arg1); - return 0; /* avoid warning */ - case TARGET_NR_read: - if (arg3 == 0) { - return 0; - } else { - if (is_hostfd(arg1)) { - return -TARGET_EBADF; - } - if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) - return -TARGET_EFAULT; - ret = get_errno(safe_read(arg1, p, arg3)); - if (ret >= 0 && - fd_trans_host_to_target_data(arg1)) { - ret = fd_trans_host_to_target_data(arg1)(p, ret); - } - unlock_user(p, arg2, ret); - } - return ret; - case TARGET_NR_write: - if (is_hostfd(arg1)) { - return -TARGET_EBADF; - } - if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) - return -TARGET_EFAULT; - if (fd_trans_target_to_host_data(arg1)) { - void *copy = g_malloc(arg3); - memcpy(copy, p, arg3); - ret = fd_trans_target_to_host_data(arg1)(copy, arg3); - if (ret >= 0) { - ret = get_errno(safe_write(arg1, copy, ret)); - } - g_free(copy); - } else { - ret = get_errno(safe_write(arg1, p, arg3)); - } - unlock_user(p, arg2, 0); - return ret; - #ifdef TARGET_NR_open case TARGET_NR_open: if (!(p = lock_user_string(arg1))) @@ -8116,15 +8145,6 @@ IMPL(everything_else) fd_trans_unregister(ret); return ret; #endif - case TARGET_NR_close: - if (is_hostfd(arg1)) { - return -TARGET_EBADF; - } - fd_trans_unregister(arg1); - return get_errno(close(arg1)); - - case TARGET_NR_brk: - return do_brk(arg1); #ifdef TARGET_NR_fork case TARGET_NR_fork: return get_errno(do_fork(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0)); @@ -12894,7 +12914,11 @@ IMPL(everything_else) } static impl_fn * const syscall_table[] = { - impl_everything_else, + [TARGET_NR_brk] = impl_brk, + [TARGET_NR_close] = impl_close, + [TARGET_NR_exit] = impl_exit, + [TARGET_NR_read] = impl_read, + [TARGET_NR_write] = impl_write, }; abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1,