From patchwork Sun Jun 10 03:00:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138085 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2578289lji; Sat, 9 Jun 2018 20:10:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJ5tpzOmcFG3ZMEpbrlPnUupNca4wRa6xCB7z7KJ93J0OpMn4Ov4wb17GdRsvFqn+zjoDv X-Received: by 2002:a37:97c4:: with SMTP id z187-v6mr10532361qkd.196.1528600246284; Sat, 09 Jun 2018 20:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528600246; cv=none; d=google.com; s=arc-20160816; b=ua/torUoFL/WKTc4S4A9doo7EfkrtDX53thqGhn5TYUg5RuGDSokUZFUfHhgnEcw/o euvcfPooLPORlvZsi5g/X+iSkj04lQwy8SNXYFZoFTZxF3P3FM+Mk3en8lTHapux7Vn7 dA08uWVUjjo39YzBjyejCSHmKE8E1xI7TvyalIPZvnhid3iEzvFXWqfHz3uUeUboJRRx 8dQx4JYNTJsXnLLuDhKTS8n/fpHB+PjOS1esr/FX+AFtbYpKz7KkbWg7Pqx6iq9WxOsx pn8Pupnkh6BHFbvG2E3J1luVbx5KFtzzCLv2jv8bFbDps0OamVXGpxESpo81MihMMpC2 VqWg== 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=v1gmxYTvtFoZy+0ESibyvIay/GhgpSmkgy8un55ftVc=; b=QXay66PwIxe25Vf9k2uY6pCDkChmRjhQCN03LBjsAsTn9E3GPmwE7gtHJR7LOgByGr ybyKAbuhtkyQbgLUrDDU78zwo+NZ4+Gj++tFg+al00HQme42wipFhUazsv5AuhgMNGdr Zolsd95a6m7kT394fvHZeLTrhVjAhJrfhQuBh8uuUyxwyed+FtdQXbRH0w0sOX25y/7c b3kmi6QyVjPuSm7mimZrUtcU+rtgi4kI1sIaA+qsLX6ihaYkhij66+Fjhd/F0K6/HgZF PvaCCKPXtvYrH4lzuIozOVksDZ4Q+WzHyJFxUOl0NRGdLsaGAJYbXBdjL3u/mb3vo96m tcvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dk+4yK8r; 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 r7-v6si8371998qkk.85.2018.06.09.20.10.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:10:46 -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=dk+4yK8r; 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]:42216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqkf-0000cX-Kf for patch@linaro.org; Sat, 09 Jun 2018 23:10:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqd0-0001jj-My for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqcz-0003Ck-Fu for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:50 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34412) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqcz-0003CU-8M for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:49 -0400 Received: by mail-pf0-x242.google.com with SMTP id a63-v6so8498419pfl.1 for ; Sat, 09 Jun 2018 20:02:49 -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=v1gmxYTvtFoZy+0ESibyvIay/GhgpSmkgy8un55ftVc=; b=dk+4yK8rgv2cYm/wiuDocbPxpJxr7yNmS1qGzizWAV9giKekBCPf9ir6tFbmkj5hOo O3xklsH7Ns4I2kanf00uvvPO70+eSt16r0pIatyjacPzDfgdJuC5H5p312O+zzCXEU1Z kotcNHcoHBJUMKdCZ/db9TfeXbWzjymWSMFSI= 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=v1gmxYTvtFoZy+0ESibyvIay/GhgpSmkgy8un55ftVc=; b=PsFYEOxqq4xGUz9eEpR00R99Ij9GYnIFjGqOUY8J9CnGeoQIJwxNXyoGrTq2UAtX3p OWgHsOiMCHK6o8urT9DIvKCReKv8HwHw5owYoAbglGkGzYJ2tafhYdBKR0vqy8CrmalR DYwYeZ9OJAkIABE7mFf9YmI8PP4jagNNXsOWYyA281rHyliO86mRNJtk4u7mMsjBcK2H Q9+9wl1OaZeZhnmk+RciVMb4CDb855dySFA8LAFZsemHUHWU21ebT0Unfrc/7nQT44nV R7n2pGAiBQ+IpHwPBUmyg8xIsfoef3T+PQI7YDci48CfVpKOaEIL+jn+gQIWhL7phDVX /rNA== X-Gm-Message-State: APt69E0j/WdrGS71F5hlQzQcRAYNAxfevsAX4mSSGM4r1Bk9VSe1Q7EO gdsrcex8ECne1VM2KJAn2L6I4BvvRUA= X-Received: by 2002:a63:83c3:: with SMTP id h186-v6mr10116244pge.298.1528599767997; Sat, 09 Jun 2018 20:02:47 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.02.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:02:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:00:42 -1000 Message-Id: <20180610030220.3777-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-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:c00::242 Subject: [Qemu-devel] [PATCH v2 010/108] 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 | 179 ++++++++++++++++++++++++------------------- 1 file changed, 102 insertions(+), 77 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8678e749ee..6d2f9915ec 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7958,6 +7958,103 @@ static abi_long impl_##NAME(void *cpu_env, unsigned num, abi_long arg1, \ abi_long arg5, abi_long arg6, abi_long arg7, \ abi_long arg8) +IMPL(brk) +{ + return do_brk(arg1); +} + +IMPL(close) +{ + 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 *p; + + if (arg3 == 0) { + return 0; + } + p = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!p) { + 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; +} + +IMPL(write) +{ + abi_long ret; + char *p; + + p = lock_user(VERIFY_READ, arg2, arg3, 1); + if (!p) { + 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, 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. @@ -7975,77 +8072,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; 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 (!(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 (!(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))) @@ -8077,12 +8103,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, fd_trans_unregister(ret); return ret; #endif - case TARGET_NR_close: - 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)); @@ -12445,6 +12465,11 @@ static impl_fn *syscall_table(unsigned num) /* * Other syscalls listed in collation order, with '_' ignored. */ + SYSCALL(brk); + SYSCALL(close); + SYSCALL(exit); + SYSCALL(read); + SYSCALL(write); } #undef SYSCALL