From patchwork Sun May 19 20:37:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164544 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4807089ili; Sun, 19 May 2019 14:20:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSZP68bNgmD2QmPK0i4JI2nmvs0g5SW/QLYSWfFl3UWJh8n47LiN1dcjRVCsdWhxN46ab4 X-Received: by 2002:a17:906:3713:: with SMTP id d19mr48607301ejc.194.1558300837399; Sun, 19 May 2019 14:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558300837; cv=none; d=google.com; s=arc-20160816; b=SG/xCAbMVUbm6YkDw91EtFu3bJYxwitwZa59i/oWBD5jGbGqeA54C+/TkeQqPHDf3e I0Msioy2CthoGzRRIj/7bvsg0eMO347FhDylGz9WfLIlpN+pSCMVeXwPQrIJvPvAtApg hJXL40pou3eib/Kzgd/OhhfbIeyVVvLrXBeGT9674Vypd9VhHym84eoeHEObftINaRmS QyPMeoDW7vYeVVXYv+wN6h3jWgrwK9IxvfAHTCC8WGfPJ0bPjXiAZZzcuO4o06vqarjl YXm2mZC/xP1pi+kZlAyP6I5qOa9dIKXxs4IC/GPJB55XDbdy5tJ/xr222sKlhNulBoak rZ0Q== 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; bh=C4XNH+VeEXaL+6UuHWZfoss3TaaEPTbmJNRx30bs8d0=; b=pprlfIcuIKs7nnP04CN47dtbI0OaGGJIl0+VJeFd4C576YtvuGdOO+maBQRMct9RrS sygGsuXq5jUjT3/YpfZrPlEhleRR89sdbeutPZJ8aoXyhKMAx5UkQab8uiqDBAMD5gCJ t4v/LbNYU9yf1lJ/fQC0pW3gY2I3ycIpCFlZsyGw5CC7dTL6G24gzbtD4TOMJxhHSKgQ 9SM6JydR34AiirM2+Cyh66HY77d4BsEtSf+3Vfw/m6eX2D9gLJsLfeFEWK7dVaYoaBbl dV9szLGnIUMtlMkXLk7nV5jC3bOe1/l4oEj5YpA1dx1646Z3XNoMy2EvfBud3RP8X/+9 oZHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HlkoJCcc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id s30si12599920eda.229.2019.05.19.14.20.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 14:20:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HlkoJCcc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:53751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSTES-0006Yw-8G for patch@linaro.org; Sun, 19 May 2019 17:20:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSa4-00040f-C0 for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSa3-0004xw-26 for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:52 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSa2-0004wx-S0 for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:51 -0400 Received: by mail-pf1-x442.google.com with SMTP id b76so6171951pfb.5 for ; Sun, 19 May 2019 13:38: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=C4XNH+VeEXaL+6UuHWZfoss3TaaEPTbmJNRx30bs8d0=; b=HlkoJCccjOovpX7qB2H7RM3LLddUnfOgcGNq2r9L7iv7jBhxc4TCfALr2Y0kJQhGLi pjcI4vJFA9mvNMBTOvit2RyzS3Qob7XGGdTKwnpXLhQsYKZuy2M8pSLa62n1RTdKIkTT WaDGdYAdlGBkk2KOioZ3lOcaJgThBANn7WM6StZ5btJKz13q24nHkg/2GdC/bf/wnDCP QMgong0Msl/4hTc/Kpebl7C42rDwkBQVNyY7PWmT5no5HqK77UY1Fqg8XK5vtg/HOuzL aJCZ7pLozOS3xLbkRONCiDyhwfbtSSauoLIDJA3mDU59PBr+kr0zgCkQSGyKaTQH7UX1 RgpA== 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=C4XNH+VeEXaL+6UuHWZfoss3TaaEPTbmJNRx30bs8d0=; b=NkVmQrVicfGwbqRlEoBJ01vRuIVLNcHYebUZO7946E7xpqtjLf9RgQZxosLX1LxD5P 45y/htrNSTQWbSJZ8vB5tpSXDUCO0oWoi+ZelHgRJxgVfIKqoJ2ONnL7H76cJna08yxj M0qPqbV6SzJX4GcFWOm5tWlXM3U+qWZSQD7EGC1zcHPx2dcgOYL4grsiGErwXrr2Quc8 su53dwQ7/bfSEnIhQl1/SjuSqa+eBkvh6J1RWaNqR41gLwx73ik8bnHm9IKUg6oQY5dM hXpV/KxOvScIjCPWX/xbUBnxcW93QS/IlHKBCZzclIa489zaDixDqfeLeGde1z8qMZrQ nMYg== X-Gm-Message-State: APjAAAW19lCwXShHSmc01ASaKEk3YyIVYLCmJhWpXZ+ekX6R59EREg44 62U84PEnQiXwOEjfxnx91IExM+85k+k= X-Received: by 2002:a63:5659:: with SMTP id g25mr72010606pgm.59.1558298329635; Sun, 19 May 2019 13:38:49 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.38.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:38:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:37:17 -0700 Message-Id: <20190519203726.20729-66-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v7 65/74] linux-user: Split out getrlimit, setrlimit 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" Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 6 ++++ linux-user/syscall-proc.inc.c | 52 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 46 ------------------------------- linux-user/strace.list | 6 ---- 4 files changed, 58 insertions(+), 52 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 3ba697fd53..34426a2e23 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -72,6 +72,9 @@ SYSCALL_DEF(getpid); #ifdef TARGET_NR_getppid SYSCALL_DEF(getppid); #endif +#ifdef TARGET_NR_getrlimit +SYSCALL_DEF(getrlimit, ARG_DEC, ARG_PTR); +#endif SYSCALL_DEF(getsid, ARG_DEC); #ifdef TARGET_NR_getxpid SYSCALL_DEF(getxpid); @@ -212,6 +215,9 @@ SYSCALL_DEF(semget, ARG_DEC, ARG_DEC, ARG_HEX); #endif SYSCALL_DEF(sethostname, ARG_STR); SYSCALL_DEF(setpgid, ARG_DEC, ARG_DEC); +#ifdef TARGET_NR_setrlimit +SYSCALL_DEF(setrlimit, ARG_DEC, ARG_PTR); +#endif SYSCALL_DEF(setsid); #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semop) SYSCALL_DEF(semop, ARG_DEC, ARG_PTR, ARG_DEC); diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c index b1a801fb62..1238b08191 100644 --- a/linux-user/syscall-proc.inc.c +++ b/linux-user/syscall-proc.inc.c @@ -479,6 +479,26 @@ SYSCALL_IMPL(getppid) } #endif +#ifdef TARGET_NR_getrlimit +SYSCALL_IMPL(getrlimit) +{ + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + abi_long ret; + + ret = get_errno(getrlimit(resource, &rlim)); + if (!is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) { + return -TARGET_EFAULT; + } + target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); + target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); + unlock_user_struct(target_rlim, arg2, 1); + } + return ret; +} +#endif SYSCALL_IMPL(getsid) { return get_errno(getsid(arg1)); @@ -518,6 +538,38 @@ SYSCALL_IMPL(setpgid) return get_errno(setpgid(arg1, arg2)); } +#ifdef TARGET_NR_setrlimit +SYSCALL_IMPL(setrlimit) +{ + int resource = target_to_host_resource(arg1); + struct target_rlimit *target_rlim; + struct rlimit rlim; + + if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) { + return -TARGET_EFAULT; + } + rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); + rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); + unlock_user_struct(target_rlim, arg2, 0); + + /* + * If we just passed through resource limit settings for memory then + * they would also apply to QEMU's own allocations, and QEMU will + * crash or hang or die if its allocations fail. Ideally we would + * track the guest allocations in QEMU and apply the limits ourselves. + * For now, just tell the guest the call succeeded but don't actually + * limit anything. + */ + if (resource != RLIMIT_AS && + resource != RLIMIT_DATA && + resource != RLIMIT_STACK) { + return get_errno(setrlimit(resource, &rlim)); + } else { + return 0; + } +} +#endif + SYSCALL_IMPL(setsid) { return get_errno(setsid()); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6dd4196647..401450b0e3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4240,52 +4240,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_setrlimit - case TARGET_NR_setrlimit: - { - int resource = target_to_host_resource(arg1); - struct target_rlimit *target_rlim; - struct rlimit rlim; - if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) - return -TARGET_EFAULT; - rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); - rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); - unlock_user_struct(target_rlim, arg2, 0); - /* - * If we just passed through resource limit settings for memory then - * they would also apply to QEMU's own allocations, and QEMU will - * crash or hang or die if its allocations fail. Ideally we would - * track the guest allocations in QEMU and apply the limits ourselves. - * For now, just tell the guest the call succeeded but don't actually - * limit anything. - */ - if (resource != RLIMIT_AS && - resource != RLIMIT_DATA && - resource != RLIMIT_STACK) { - return get_errno(setrlimit(resource, &rlim)); - } else { - return 0; - } - } -#endif -#ifdef TARGET_NR_getrlimit - case TARGET_NR_getrlimit: - { - int resource = target_to_host_resource(arg1); - struct target_rlimit *target_rlim; - struct rlimit rlim; - - ret = get_errno(getrlimit(resource, &rlim)); - if (!is_error(ret)) { - if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) - return -TARGET_EFAULT; - target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); - target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); - unlock_user_struct(target_rlim, arg2, 1); - } - } - return ret; -#endif case TARGET_NR_getrusage: { struct rusage rusage; diff --git a/linux-user/strace.list b/linux-user/strace.list index 361ceec853..711ad9c0aa 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -280,9 +280,6 @@ #ifdef TARGET_NR_getresuid32 { TARGET_NR_getresuid32, "getresuid32" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_getrlimit -{ TARGET_NR_getrlimit, "getrlimit" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_get_robust_list { TARGET_NR_get_robust_list, "get_robust_list" , NULL, NULL, NULL }, #endif @@ -1061,9 +1058,6 @@ #ifdef TARGET_NR_setreuid32 { TARGET_NR_setreuid32, "setreuid32" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_setrlimit -{ TARGET_NR_setrlimit, "setrlimit" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_set_robust_list { TARGET_NR_set_robust_list, "set_robust_list" , NULL, NULL, NULL }, #endif