From patchwork Sun Jun 10 03:02:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138177 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2616229lji; Sat, 9 Jun 2018 21:18:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLe2Fm7KDhkydVYsgSn0hbHCiLWA6ya7SqKnqokJ0MKeFU0YKUn7H+k45zvJpJyeiySu5bc X-Received: by 2002:ac8:3548:: with SMTP id z8-v6mr11149535qtb.161.1528604302382; Sat, 09 Jun 2018 21:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528604302; cv=none; d=google.com; s=arc-20160816; b=GW0BGMcDBhhFiXnr+lca3JLP56l+6bClhvFDF+AZ/tR4gjpmWgB4XcrIpcUBMzl7nn D+rWRHiPK5vkFlE5bQSWAdvRFVDs2bv7/sezmYEvVXmfpHxtLwxU259bf4vbuq6toIOh dLDDjYuk35cWC+J3xsSfL9bECTOEW+ZkMkNbOSz/4ePSR25JSA51ePlyZy0L0P+69vA8 wfizOiDJWqJYQgNqRADjUmFYvOMZamt8HYez+pggqlNm0/eS/Xno+GgB3aYuOdXzwCd9 y0jbHafiW3vHdVkNcMnSoQRP/IxxESzSnt6QSq+xTB9eZh4Dz8wZMIzIlMmXv0uQO4Rt DV6w== 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=CII5PWAJCoKDXZtRNhlraOIcAUh9jlthYVTcnyEYQws=; b=wirqG1HInZI3farx17zYF1+rzTApkIMLGS4Q18zybKXEvqUuURpDCyqKHEXH2iTuI2 M7BFroHPR5QODfCvgCtr7BgW/Qz7EBW/OeNuFm1HwWAEyp03tpR7qjoe0wkucV0WRdn6 2nTuH9oLqMr1nxygnfmNDm/1rJ2RmFYfcxVGxvk3rN5XsiPFelG9ETZoxKepXckjPMWH GChkg1UazBxTww6MOR5jxOFEo/wtIkFFfMAGujQgpHfg5mZuhAKTB5WjMVOBL3zSHSbW aUU0Sca6B8/P9CbWf4Am0hBcN+gnrbNT9H+VbTUkdj8V8SyswPYVJ7jKXX+fslnTbUPV +34A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RFHvoowx; 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 t74-v6si1286008qkl.41.2018.06.09.21.18.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 21:18:22 -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=RFHvoowx; 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]:42602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRro5-0003jQ-S8 for patch@linaro.org; Sun, 10 Jun 2018 00:18:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfw-0004b2-HI for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqfv-0004kU-Ax for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:52 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:33749) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqfv-0004k3-2B for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:51 -0400 Received: by mail-pl0-x243.google.com with SMTP id n10-v6so10392412plp.0 for ; Sat, 09 Jun 2018 20:05:50 -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=CII5PWAJCoKDXZtRNhlraOIcAUh9jlthYVTcnyEYQws=; b=RFHvoowxr7P9LqNNq53yWWIxv4Ty2nABCQZKQDuG9bbZ0UHvQIEzOsls2wpVTD9FWh 6S2EPxPiFsKAkk3YH92t0NIvmklkjHYe9ud8tOJonWjB/Y5I8BiYKridf8z1cHQnfvAe EL6DNFPIsQgrFFBbj0dmign5wYvz2fQZNZuGo= 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=CII5PWAJCoKDXZtRNhlraOIcAUh9jlthYVTcnyEYQws=; b=O8l+GTTMJe44lhyrQ7y4+G1sD7wd/mdwfGncEoOEX2ML5jbIyYzl8MQAkwJMVmuKgW 9FBd5V4DZOuLBQ0gXssgKvb1GLFC7e/WLfGXRUDmGIVWfYcjhvQ90A7K5/3OIovXSM7w uBtcsKquWXkKpwCu6AGqg2SzmHVVHrOrDA+8AjHEN1ePBRq1PzYha6FqDuw10xews+jl GwJJrDRi6wt66RU/Bm6qTSrBX8ncEEV4RyiiwIOw3RU5tS5qlroBvUvzjWEpGI7Sw0nx t8NGOcD/IbtRVwas9/QRgrAtaKcizTSmSYwVXB18r5iw6Ti9wcnKijzVmW/EbGhWxD7s o1yw== X-Gm-Message-State: APt69E0LbCV8Abo1j/UREBIz3yu6nYJdVOpdXxvvNyAb1yCLcwiUpYqG 6OUzMCyjqhDf2GE4ZTUnwYgVReztMY4= X-Received: by 2002:a17:902:1029:: with SMTP id b38-v6mr12795421pla.277.1528599949896; Sat, 09 Jun 2018 20:05:49 -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.05.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:05:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:02:12 -1000 Message-Id: <20180610030220.3777-101-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:c01::243 Subject: [Qemu-devel] [PATCH v2 100/108] linux-user: Split out epoll syscalls 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" This includes epoll_create, epoll_create1, epoll_ctl, epoll_pwait, epoll_wait. All targets define epoll_create1, epoll_ctl, epoll_pwait; remove those ifdefs. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 244 +++++++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 116 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e630a43f97..9ce37c1119 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7897,6 +7897,123 @@ IMPL(dup3) return ret; } +#ifdef CONFIG_EPOLL +# ifdef TARGET_NR_epoll_create +IMPL(epoll_create) +{ + return get_errno(epoll_create(arg1)); +} +# endif + +IMPL(epoll_create1) +{ +# ifdef CONFIG_EPOLL_CREATE1 + return get_errno(epoll_create1(arg1)); +# else + /* If flags are 0, we can emulate with epoll_create. + * The size argument is ignored after linux 2.6.8, + * other than verifying that it is positive. + */ + if (arg1 == 0) { + return get_errno(epoll_create(1)); + } + return -TARGET_ENOSYS; +# endif +} + +IMPL(epoll_ctl) +{ + struct epoll_event ep; + struct epoll_event *epp = 0; + + if (arg4) { + struct target_epoll_event *target_ep; + if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) { + return -TARGET_EFAULT; + } + ep.events = tswap32(target_ep->events); + /* The epoll_data_t union is just opaque data to the kernel, + * so we transfer all 64 bits across and need not worry what + * actual data type it is. + */ + ep.data.u64 = tswap64(target_ep->data.u64); + unlock_user_struct(target_ep, arg4, 0); + epp = &ep; + } + return get_errno(epoll_ctl(arg1, arg2, arg3, epp)); +} + +IMPL(epoll_pwait_wait) +{ + struct target_epoll_event *target_ep; + struct epoll_event *ep; + int epfd = arg1; + int maxevents = arg3; + int timeout = arg4; + abi_long ret; + + if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) { + return -TARGET_EINVAL; + } + + target_ep = lock_user(VERIFY_WRITE, arg2, + maxevents * sizeof(struct target_epoll_event), 1); + if (!target_ep) { + return -TARGET_EFAULT; + } + + ep = g_try_new(struct epoll_event, maxevents); + if (!ep) { + unlock_user(target_ep, arg2, 0); + return -TARGET_ENOMEM; + } + + switch (num) { + default: /* TARGET_NR_epoll_pwait */ + if (arg5) { + target_sigset_t *target_set; + sigset_t set; + + if (arg6 != sizeof(target_sigset_t)) { + ret = -TARGET_EINVAL; + break; + } + target_set = lock_user(VERIFY_READ, arg5, + sizeof(target_sigset_t), 1); + if (!target_set) { + ret = -TARGET_EFAULT; + break; + } + target_to_host_sigset(&set, target_set); + unlock_user(target_set, arg5, 0); + + ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout, + &set, SIGSET_T_SIZE)); + break; + } + /* fallthru */ +# ifdef TARGET_NR_epoll_wait + case TARGET_NR_epoll_wait: +# endif + ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, + timeout, NULL, 0)); + break; + } + if (!is_error(ret)) { + int i; + for (i = 0; i < ret; i++) { + target_ep[i].events = tswap32(ep[i].events); + target_ep[i].data.u64 = tswap64(ep[i].data.u64); + } + unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event)); + } else { + unlock_user(target_ep, arg2, 0); + } + g_free(ep); + return ret; +} +#endif /* CONFIG_EPOLL */ + #ifdef CONFIG_EVENTFD # ifdef TARGET_NR_eventfd IMPL(eventfd) @@ -12856,122 +12973,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, abi_long ret; switch(num) { -#if defined(CONFIG_EPOLL) -#if defined(TARGET_NR_epoll_create) - case TARGET_NR_epoll_create: - return get_errno(epoll_create(arg1)); -#endif -#if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1) - case TARGET_NR_epoll_create1: - return get_errno(epoll_create1(arg1)); -#endif -#if defined(TARGET_NR_epoll_ctl) - case TARGET_NR_epoll_ctl: - { - struct epoll_event ep; - struct epoll_event *epp = 0; - if (arg4) { - struct target_epoll_event *target_ep; - if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) { - return -TARGET_EFAULT; - } - ep.events = tswap32(target_ep->events); - /* The epoll_data_t union is just opaque data to the kernel, - * so we transfer all 64 bits across and need not worry what - * actual data type it is. - */ - ep.data.u64 = tswap64(target_ep->data.u64); - unlock_user_struct(target_ep, arg4, 0); - epp = &ep; - } - return get_errno(epoll_ctl(arg1, arg2, arg3, epp)); - } -#endif - -#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait) -#if defined(TARGET_NR_epoll_wait) - case TARGET_NR_epoll_wait: -#endif -#if defined(TARGET_NR_epoll_pwait) - case TARGET_NR_epoll_pwait: -#endif - { - struct target_epoll_event *target_ep; - struct epoll_event *ep; - int epfd = arg1; - int maxevents = arg3; - int timeout = arg4; - - if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) { - return -TARGET_EINVAL; - } - - target_ep = lock_user(VERIFY_WRITE, arg2, - maxevents * sizeof(struct target_epoll_event), 1); - if (!target_ep) { - return -TARGET_EFAULT; - } - - ep = g_try_new(struct epoll_event, maxevents); - if (!ep) { - unlock_user(target_ep, arg2, 0); - return -TARGET_ENOMEM; - } - - switch (num) { -#if defined(TARGET_NR_epoll_pwait) - case TARGET_NR_epoll_pwait: - { - target_sigset_t *target_set; - sigset_t _set, *set = &_set; - - if (arg5) { - if (arg6 != sizeof(target_sigset_t)) { - ret = -TARGET_EINVAL; - break; - } - - target_set = lock_user(VERIFY_READ, arg5, - sizeof(target_sigset_t), 1); - if (!target_set) { - ret = -TARGET_EFAULT; - break; - } - target_to_host_sigset(set, target_set); - unlock_user(target_set, arg5, 0); - } else { - set = NULL; - } - - ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout, - set, SIGSET_T_SIZE)); - } -#endif -#if defined(TARGET_NR_epoll_wait) - case TARGET_NR_epoll_wait: - ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout, - NULL, 0)); - break; -#endif - default: - ret = -TARGET_ENOSYS; - } - if (!is_error(ret)) { - int i; - for (i = 0; i < ret; i++) { - target_ep[i].events = tswap32(ep[i].events); - target_ep[i].data.u64 = tswap64(ep[i].data.u64); - } - unlock_user(target_ep, arg2, - ret * sizeof(struct target_epoll_event)); - } else { - unlock_user(target_ep, arg2, 0); - } - g_free(ep); - return ret; - } -#endif -#endif #ifdef TARGET_NR_prlimit64 case TARGET_NR_prlimit64: { @@ -13330,6 +13331,17 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(dup2); #endif SYSCALL(dup3); +#ifdef CONFIG_EPOLL +# ifdef TARGET_NR_epoll_create + SYSCALL(epoll_create); +# endif + SYSCALL(epoll_create1); + SYSCALL(epoll_ctl); + SYSCALL_WITH(epoll_pwait, epoll_pwait_wait); +# ifdef TARGET_NR_epoll_wait + SYSCALL_WITH(epoll_wait, epoll_pwait_wait); +# endif +#endif #ifdef CONFIG_EVENTFD # ifdef TARGET_NR_eventfd SYSCALL(eventfd);