From patchwork Sun Jun 10 03:01:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138119 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2591880lji; Sat, 9 Jun 2018 20:35:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJcQR4BoqJPvZBhSWmg2uajvI2LTEf8aKhwXrMaPwsED8eWMExf7pyoo27zoP+fCWaryfG4 X-Received: by 2002:ac8:3854:: with SMTP id r20-v6mr11470424qtb.190.1528601718289; Sat, 09 Jun 2018 20:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528601718; cv=none; d=google.com; s=arc-20160816; b=TbxjjPqykJcjCpji82keW0G88daej8kBnS5JsoaNBAoXl7y0zGtb74Dw5GktLfMqMT K5FbN4QVoc3RgaV3q+sBy5dJeMWhrSgJrsuMRFc8MSRkQ/oapN5z3c33kqGbLvr8eQ82 trGvB9uaNRHpZXcuttgMNCYKeYo90szQR3nQhLWv0K6/ewqNy5WDed/Z31F/NDD6Ut1V YtMKP0SH6ABFbOvAdbPuwcxn/z4J1R1rj6MjPz7pNeUKnBq2TZoTrhNCO3Y63XaltkgY zIh0t5iuJ24x2DfnicdCrqJy72UEx+YxeUbHePj4NU1p3l6kSYz5EzCMf/FON7ncgeen OH2w== 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=tObNJbna5DJ9avJPvFGoAZlFiPJwl7Jm1RCZ5QclQGY=; b=JoPN+QivIecFuWVPAU5okuQh8xMw9SgihcZhq286h1lC8ykhwZObRA3NataUkr6jeX bqm95Mr38QHqVl3BSWOqxzUKK7zMGBjSokGeJKA48H8YyEbVtBtplHgMVtJwqjc3qOLi dACRenhYqJySFM8gJbVZ958wSUseU3Im7iTb/hy5Iep2IzsJTp7oMCChPgXDgFdNmAKz zHbGIv4nTfsWxUHSeIzOQJADTLctsB3z93JG5UoYjkmFEhD0308AQf1nlpmFq1Q+rpyS MdD7BSrzXotjPpw7XXKkBZWFsHwy0fheNkJt76ZwUP7kyEiZ3TiPs2zhreFLUWs3Xboz KnMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NXwDOd9L; 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 68-v6si2011475qkc.114.2018.06.09.20.35.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:35:18 -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=NXwDOd9L; 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]:42349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRr8P-00050l-MJ for patch@linaro.org; Sat, 09 Jun 2018 23:35:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqeL-00033B-QD for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqeK-0003hu-IJ for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:13 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:40843) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqeK-0003hm-80 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:12 -0400 Received: by mail-pg0-x241.google.com with SMTP id l2-v6so8127859pgc.7 for ; Sat, 09 Jun 2018 20:04:12 -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=tObNJbna5DJ9avJPvFGoAZlFiPJwl7Jm1RCZ5QclQGY=; b=NXwDOd9LD0ulgbzwT/NjfjNXQzNctCtC8m3FZ7tj51vXoJ9g7p6Ir9ZkatZhwGMExN u3l9zy7WPLquJpd9WpUPZfnDZwdyq2JsW4D9z/8mxbbfNdbdsiSgSrFHp227Ax1qgqOc wZaC1q/ScWyVllBccdYzxNYsHvK3uR7sSsk8U= 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=tObNJbna5DJ9avJPvFGoAZlFiPJwl7Jm1RCZ5QclQGY=; b=Igz5CfWnaJTAAiPbXqbMI+BCSdWtEUbWzbKgUUcaxjhz7Tf6+/DoofxLYdIuFbV8Y7 ZeIv14RtZG0/y4z19lT6110CLF7pLa3xk0GRoLEOaZoOLgHQuCTxj2JwozzrcKQqAL+0 p0BsVre2hNC5dnNcUYOwMI6EGqdlQo13cXCXRfuRIP6hCTKjmtpWQQ92EZEiP57PTyJz Y4u/zwy2sSaWvtOGSUdrM/73zR5Xqf3nwbqd5wJ+8FQCGjkZOE7fX57tVXAXT60VkJj5 B9FfvRFfVN0GrcJDME2TtkWy7NrSPFspSXG6NAK2VqR2VEyFvWVMPIPdvVKLvSHAeUG5 lEdg== X-Gm-Message-State: APt69E0J6DcfTimj4jyqrKNjUFwftrijYwtMvqAcJv1ICzFi0wJ6QFsd ID9N8rcpfYqkHR6kr6Sc9wnFBeT9bMM= X-Received: by 2002:a65:4cc3:: with SMTP id n3-v6mr10269044pgt.98.1528599851057; Sat, 09 Jun 2018 20:04:11 -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.04.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:20 -1000 Message-Id: <20180610030220.3777-49-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:c05::241 Subject: [Qemu-devel] [PATCH v2 048/108] linux-user: Split out getrandom, shutdown, setsockopt, socket, socketpair 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" All targets define getrandom; remove the ifdef. Define a stub if the host __NR_getrandom is not defined. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 90 ++++++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 28 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 977f61610c..4dc2312ae6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -249,6 +249,14 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ #define TARGET_NR__llseek TARGET_NR_llseek #endif +/* These definitions produce an ENOSYS from the host kernel. + * Performing a bogus syscall is lazier than boilerplating + * the replacement functions here in C. + */ +#ifndef __NR_getrandom +#define __NR_getrandom -1 +#endif + #ifdef __NR_gettid _syscall0(int, gettid) #else @@ -315,9 +323,7 @@ _syscall2(int, ioprio_get, int, which, int, who) #if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set) _syscall3(int, ioprio_set, int, which, int, who, int, ioprio) #endif -#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom) _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags) -#endif #if defined(TARGET_NR_kcmp) && defined(__NR_kcmp) _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type, @@ -8202,6 +8208,19 @@ IMPL(getpriority) #endif } +IMPL(getrandom) +{ + char *p = lock_user(VERIFY_WRITE, arg1, arg2, 0); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(getrandom(p, arg2, arg3)); + unlock_user(p, arg1, ret); + return ret; +} + IMPL(getrlimit) { int resource = target_to_host_resource(arg1); @@ -9284,6 +9303,13 @@ IMPL(sgetmask) } #endif +#ifdef TARGET_NR_shutdown +IMPL(shutdown) +{ + return get_errno(shutdown(arg1, arg2)); +} +#endif + #if defined(TARGET_NR_select) && !defined(TARGET_WANT_NI_OLD_SELECT) IMPL(select) { @@ -9361,6 +9387,13 @@ IMPL(setrlimit) return get_errno(setrlimit(resource, &rlim)); } +#ifdef TARGET_NR_setsockopt +IMPL(setsockopt) +{ + return do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); +} +#endif + IMPL(settimeofday) { struct timeval tv; @@ -9592,6 +9625,13 @@ IMPL(sigsuspend) } #endif +#ifdef TARGET_NR_socket +IMPL(socket) +{ + return do_socket(arg1, arg2, arg3); +} +#endif + #ifdef TARGET_NR_socketcall IMPL(socketcall) { @@ -9686,6 +9726,13 @@ IMPL(socketcall) } #endif +#ifdef TARGET_NR_socketpair +IMPL(socketpair) +{ + return do_socketpair(arg1, arg2, arg3, arg4); +} +#endif + #ifdef TARGET_NR_ssetmask IMPL(ssetmask) { @@ -10035,32 +10082,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_shutdown - case TARGET_NR_shutdown: - return get_errno(shutdown(arg1, arg2)); -#endif -#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom) - case TARGET_NR_getrandom: - p = lock_user(VERIFY_WRITE, arg1, arg2, 0); - if (!p) { - return -TARGET_EFAULT; - } - ret = get_errno(getrandom(p, arg2, arg3)); - unlock_user(p, arg1, ret); - return ret; -#endif -#ifdef TARGET_NR_socket - case TARGET_NR_socket: - return do_socket(arg1, arg2, arg3); -#endif -#ifdef TARGET_NR_socketpair - case TARGET_NR_socketpair: - return do_socketpair(arg1, arg2, arg3, arg4); -#endif -#ifdef TARGET_NR_setsockopt - case TARGET_NR_setsockopt: - return do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); -#endif #if defined(TARGET_NR_syslog) case TARGET_NR_syslog: { @@ -12878,6 +12899,7 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(getppid); #endif SYSCALL(getpriority); + SYSCALL(getrandom); SYSCALL(getrlimit); SYSCALL(getrusage); #ifdef TARGET_NR_getsockname @@ -12986,6 +13008,9 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_sgetmask SYSCALL(sgetmask); #endif +#ifdef TARGET_NR_shutdown + SYSCALL(shutdown); +#endif #ifdef TARGET_NR_select # ifdef TARGET_WANT_NI_OLD_SELECT SYSCALL_WITH(select, enosys); @@ -13009,6 +13034,9 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(setpgid); SYSCALL(setpriority); SYSCALL(setrlimit); +#ifdef TARGET_NR_setsockopt + SYSCALL(setsockopt); +#endif SYSCALL(settimeofday); SYSCALL(setsid); #ifdef TARGET_NR_sigaction @@ -13026,9 +13054,15 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_sigsuspend SYSCALL(sigsuspend); #endif +#ifdef TARGET_NR_socket + SYSCALL(socket); +#endif #ifdef TARGET_NR_socketcall SYSCALL(socketcall); #endif +#ifdef TARGET_NR_socketpair + SYSCALL(socketpair); +#endif #ifdef TARGET_NR_ssetmask SYSCALL(ssetmask); #endif