From patchwork Fri Jan 5 13:24:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 856043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88859-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="OrYVJXJZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zCllY1nvkz9ryv for ; Sat, 6 Jan 2018 00:25:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=RNroBs3iG/lMWkl9lHqyfgZGDTDKu51 8yzEgEPjc1tBPj9ok+xj0/LEGF3txpxpEQkiJjVmQUfyv+/PDBgd8Oq9r5pqNLIn eZSxmwDeG1hq1LMiK5qVJ2JcRTHy6gkxT8nAz/7tBtkDdLw2nhN3AFfW/sl7oWA8 k0d4Zzd4Tkvk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=lG4J8V16sJq9N98G7SH35EqYLMk=; b=OrYVJ XJZ8zQDZau1MbYGqRNgXZzVv51ZeAK02C7twS7j7wwjtPNEAgYRlKXbfFBw8RrKG x5wHtptlwkSh93Ejj19r05XUcAYTAeocaHghMcN95AyZudrTrK4TO6i/2Z2UBVCn qLJHB+qtj795rmLjBElPZFRmpTZuxm8fMagS+Y= Received: (qmail 101904 invoked by alias); 5 Jan 2018 13:24:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 100277 invoked by uid 89); 5 Jan 2018 13:24:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, T_RP_MATCHES_RCVD, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Date: Fri, 5 Jan 2018 14:24:26 +0100 Message-Id: <20180105132429.21118-2-aurelien@aurel32.net> In-Reply-To: <20180105132429.21118-1-aurelien@aurel32.net> References: <20180105132429.21118-1-aurelien@aurel32.net> RLIM64_INFINITY was supposed to be a glibc convention rather than anything seen by the kernel, but it ended being passed to the kernel through the prlimit64 syscall. * On the kernel side, the value is defined for the prlimit64 syscall for all architectures in include/uapi/linux/resource.h: #define RLIM64_INFINITY (~0ULL) * On the kernel side, the value is defined for getrlimit and setrlimit in arch/alpha/include/uapi/asm/resource.h #define RLIM_INFINITY 0x7ffffffffffffffful * On the GNU libc side, the value is defined in sysdeps/unix/sysv/linux/alpha/bits/resource.h: # define RLIM64_INFINITY 0x7fffffffffffffffLL This was not an issue until the getrlimit and setrlimit glibc functions have been changed in commit 045c13d185 ("Consolidate Linux setrlimit and getrlimit implementation") to use the prlimit64 syscall instead of the getrlimit and setrlimit ones. This patch fixes that by adding a wrapper to fix the value passed to or received from the kernel, before or after calling the prlimit64 syscall. Changelog: [BZ #22648] * sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file. * sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto. --- ChangeLog | 6 +++ sysdeps/unix/sysv/linux/alpha/getrlimit64.c | 64 +++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/alpha/setrlimit64.c | 61 +++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/alpha/getrlimit64.c create mode 100644 sysdeps/unix/sysv/linux/alpha/setrlimit64.c diff --git a/ChangeLog b/ChangeLog index ddd49200ed..489cd1fd84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-01-05 Aurelien Jarno + + [BZ #22648] + * sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file. + * sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto. + 2018-01-04 Joseph Myers * malloc/tst-malloc-tcache-leak.c (TIMEOUT): Define to 50. diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c new file mode 100644 index 0000000000..908be53180 --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c @@ -0,0 +1,64 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* Add this redirection so the strong_alias linking getrlimit64 to + {__}getrlimit does not throw a type error. */ +#undef getrlimit +#undef __getrlimit +#define getrlimit getrlimit_redirect +#define __getrlimit __getrlimit_redirect +#include +#undef getrlimit +#undef __getrlimit + +/* RLIM64_INFINITY was supposed to be a glibc convention rather than + anything seen by the kernel, but it ended being passed to the kernel + through the prlimit64 syscall. Given that a lot of binaries with + the wrong constant value are in the wild, provide a wrapper function + fixing the value after the syscall. */ +#define KERNEL_RLIM64_INFINITY 0xffffffffffffffffULL + +int +__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits) +{ + struct rlimit64 krlimits; + + if (INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, &krlimits) < 0) + return -1; + + if (krlimits.rlim_cur == KERNEL_RLIM64_INFINITY) + rlimits->rlim_cur = RLIM64_INFINITY; + else + rlimits->rlim_cur = krlimits.rlim_cur; + if (krlimits.rlim_max == KERNEL_RLIM64_INFINITY) + rlimits->rlim_max = RLIM64_INFINITY; + else + rlimits->rlim_max = krlimits.rlim_max; + + return 0; +} +libc_hidden_def (__getrlimit64) +strong_alias (__getrlimit64, __GI_getrlimit) +strong_alias (__getrlimit64, __GI___getrlimit) +strong_alias (__getrlimit64, __getrlimit) +weak_alias (__getrlimit64, getrlimit) + +weak_alias (__getrlimit64, getrlimit64) +libc_hidden_weak (getrlimit64) diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c new file mode 100644 index 0000000000..1b8a95b9e9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* Add this redirection so the strong_alias linking setrlimit64 to + {__}setrlimit does not throw a type error. */ +#undef setrlimit +#undef __setrlimit +#define setrlimit setrlimit_redirect +#define __setrlimit __setrlimit_redirect +#include +#undef setrlimit +#undef __setrlimit + +/* RLIM64_INFINITY was supposed to be a glibc convention rather than + anything seen by the kernel, but it ended being passed to the kernel + through the prlimit64 syscall. Given that a lot of binaries with + the wrong constant value are in the wild, provide a wrapper function + fixing the value before the syscall. */ +#define KERNEL_RLIM64_INFINITY 0xffffffffffffffffULL + +int +__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) +{ + struct rlimit64 krlimits; + + if (rlimits->rlim_cur == RLIM64_INFINITY) + krlimits.rlim_cur = KERNEL_RLIM64_INFINITY; + else + krlimits.rlim_cur = rlimits->rlim_cur; + if (rlimits->rlim_max == RLIM64_INFINITY) + krlimits.rlim_max = KERNEL_RLIM64_INFINITY; + else + krlimits.rlim_max = rlimits->rlim_max; + + return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &krlimits, NULL); +} + +weak_alias (__setrlimit64, setrlimit64) + +strong_alias (__setrlimit64, __setrlimit) +weak_alias (__setrlimit64, setrlimit) +#ifdef SHARED +__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64); +#endif From patchwork Fri Jan 5 13:24:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 856044 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88860-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="TqcOYVR0"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zCllr0FVXz9t34 for ; Sat, 6 Jan 2018 00:25:24 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=WTOTQyuaTPUwvKDik3cqFgQCoC6l5/e Dx+/xDd8Dts3IXlk0dAPpIaAXe1roKHUe8EuFk9GG4vSc+vkvtzMuV2oIHnbItiU DZznLym5STmVe5awTmp2sCJKu4uIUutpd9savb8TkmsnzFUkGgpS6Hy0cAonfJb6 56jy7WCZnNhQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=M3EB88EA13DIaeIYrOSRvAo+Mhw=; b=TqcOY VR0/CUoBY7oIMdUze0sPPlnGspEAf1Y0vFRz81viJZLpNR0prmulpDOZIkqzZNAu /iOVBuHsg2ZO6PMZKRrsdTceQpXQpZDPZioathtoDfgDkfvqAdrBDjdgAJnQgarT B39KtRyofKM4XkgTDRSMB8l2d3ibmUPfO1LO8I= Received: (qmail 103397 invoked by alias); 5 Jan 2018 13:24:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 103120 invoked by uid 89); 5 Jan 2018 13:24:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Date: Fri, 5 Jan 2018 14:24:27 +0100 Message-Id: <20180105132429.21118-3-aurelien@aurel32.net> In-Reply-To: <20180105132429.21118-1-aurelien@aurel32.net> References: <20180105132429.21118-1-aurelien@aurel32.net> Fix the RLIM_INFINITY and RLIM64_INFINITY constants on alpha to match the kernel one and all other architectures. Change the getrlimit, getrlimit64, setrlimit, setrlimit64 into old compat symbols, and provide the Linux generic functions as GLIBC_2_27 version. Changelog: * sysdeps/unix/sysv/linux/getrlimit64.c [USE_VERSIONED_RLIMIT]: Do not define getrlimit and getrlimit64 as weak aliases of __getrlimit64. Define __GI_getrlimit64 as weak alias of __getrlimit64. [__RLIM_T_MATCHES_RLIM64_T]: Do not redefine SHLIB_COMPAT, use #elif instead. * sysdeps/unix/sysv/linux/setrlimit64.c [USE_VERSIONED_RLIMIT]: Do not define setrlimit and setrlimit64 as weak aliases of __setrlimit64. * sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY, RLIM64_INFINITY): Fix values to match the kernel ones. * sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Define USE_VERSIONED_RLIMIT. Rename __getrlimit64 into __old_getrlimit64 and provide it as getrlimit@@GLIBC_2_0 and getrlimit64@@GLIBC_2_1. Add a __getrlimit64 function and provide it as getrlimit@@GLIBC_2_27 and getrlimit64@@GLIBC_2_27. * sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto with setrlimit and setrlimit64. * sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.27): Add getrlimit, setrlimit, getrlimit64 and setrlimit64. * sysdeps/unix/sysv/linux/alpha/Versions (libc): Add getrlimit, setrlimit, getrlimit64 and setrlimit64. --- ChangeLog | 24 +++++++++++++++ sysdeps/unix/sysv/linux/alpha/Versions | 3 ++ sysdeps/unix/sysv/linux/alpha/bits/resource.h | 6 ++-- sysdeps/unix/sysv/linux/alpha/getrlimit64.c | 44 +++++++++++---------------- sysdeps/unix/sysv/linux/alpha/libc.abilist | 4 +++ sysdeps/unix/sysv/linux/alpha/setrlimit64.c | 42 +++++++++++-------------- sysdeps/unix/sysv/linux/getrlimit64.c | 18 +++++------ sysdeps/unix/sysv/linux/setrlimit64.c | 5 +++ 8 files changed, 83 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 489cd1fd84..fd0fc0bc71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2018-01-05 Aurelien Jarno + Adhemerval Zanella + + * sysdeps/unix/sysv/linux/getrlimit64.c [USE_VERSIONED_RLIMIT]: Do not + define getrlimit and getrlimit64 as weak aliases of __getrlimit64. + Define __GI_getrlimit64 as weak alias of __getrlimit64. + [__RLIM_T_MATCHES_RLIM64_T]: Do not redefine SHLIB_COMPAT, use #elif + instead. + * sysdeps/unix/sysv/linux/setrlimit64.c [USE_VERSIONED_RLIMIT]: Do not + define setrlimit and setrlimit64 as weak aliases of __setrlimit64. + * sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY, + RLIM64_INFINITY): Fix values to match the kernel ones. + * sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Define + USE_VERSIONED_RLIMIT. Rename __getrlimit64 into __old_getrlimit64 and + provide it as getrlimit@@GLIBC_2_0 and getrlimit64@@GLIBC_2_1. Add a + __getrlimit64 function and provide it as getrlimit@@GLIBC_2_27 and + getrlimit64@@GLIBC_2_27. + * sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto with setrlimit + and setrlimit64. + * sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.27): Add + getrlimit, setrlimit, getrlimit64 and setrlimit64. + * sysdeps/unix/sysv/linux/alpha/Versions (libc): Add getrlimit, + setrlimit, getrlimit64 and setrlimit64. + 2018-01-05 Aurelien Jarno [BZ #22648] diff --git a/sysdeps/unix/sysv/linux/alpha/Versions b/sysdeps/unix/sysv/linux/alpha/Versions index 29b82f999b..3b7971c2a3 100644 --- a/sysdeps/unix/sysv/linux/alpha/Versions +++ b/sysdeps/unix/sysv/linux/alpha/Versions @@ -85,6 +85,9 @@ libc { #errlist-compat 140 _sys_errlist; sys_errlist; _sys_nerr; sys_nerr; } + GLIBC_2.27 { + getrlimit; setrlimit; getrlimit64; setrlimit64; + } GLIBC_PRIVATE { __libc_alpha_cache_shape; } diff --git a/sysdeps/unix/sysv/linux/alpha/bits/resource.h b/sysdeps/unix/sysv/linux/alpha/bits/resource.h index ac05cbb803..dddcb0f049 100644 --- a/sysdeps/unix/sysv/linux/alpha/bits/resource.h +++ b/sysdeps/unix/sysv/linux/alpha/bits/resource.h @@ -112,13 +112,13 @@ enum __rlimit_resource /* Value to indicate that there is no limit. */ #ifndef __USE_FILE_OFFSET64 -# define RLIM_INFINITY ((long int)(~0UL >> 1)) +# define RLIM_INFINITY ((__rlim_t) -1) #else -# define RLIM_INFINITY 0x7fffffffffffffffLL +# define RLIM_INFINITY 0xffffffffffffffffuLL #endif #ifdef __USE_LARGEFILE64 -# define RLIM64_INFINITY 0x7fffffffffffffffLL +# define RLIM64_INFINITY 0xffffffffffffffffuLL #endif /* We can represent all limits. */ diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c index 908be53180..5502586462 100644 --- a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c +++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c @@ -15,50 +15,42 @@ License along with the GNU C Library; if not, see . */ -#include -#include - -/* Add this redirection so the strong_alias linking getrlimit64 to - {__}getrlimit does not throw a type error. */ -#undef getrlimit -#undef __getrlimit -#define getrlimit getrlimit_redirect -#define __getrlimit __getrlimit_redirect -#include -#undef getrlimit -#undef __getrlimit +#define USE_VERSIONED_RLIMIT +#include +versioned_symbol (libc, __getrlimit, getrlimit, GLIBC_2_27); +versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_27); +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27) /* RLIM64_INFINITY was supposed to be a glibc convention rather than anything seen by the kernel, but it ended being passed to the kernel through the prlimit64 syscall. Given that a lot of binaries with the wrong constant value are in the wild, provide a wrapper function fixing the value after the syscall. */ -#define KERNEL_RLIM64_INFINITY 0xffffffffffffffffULL +# define OLD_RLIM64_INFINITY 0x7fffffffffffffffULL int -__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits) +attribute_compat_text_section +__old_getrlimit64 (enum __rlimit_resource resource, + struct rlimit64 *rlimits) { struct rlimit64 krlimits; - if (INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, &krlimits) < 0) + if (__getrlimit64 (resource, &krlimits) < 0) return -1; - if (krlimits.rlim_cur == KERNEL_RLIM64_INFINITY) - rlimits->rlim_cur = RLIM64_INFINITY; + if (krlimits.rlim_cur == RLIM64_INFINITY) + rlimits->rlim_cur = OLD_RLIM64_INFINITY; else rlimits->rlim_cur = krlimits.rlim_cur; - if (krlimits.rlim_max == KERNEL_RLIM64_INFINITY) - rlimits->rlim_max = RLIM64_INFINITY; + if (krlimits.rlim_max == RLIM64_INFINITY) + rlimits->rlim_max = OLD_RLIM64_INFINITY; else rlimits->rlim_max = krlimits.rlim_max; return 0; } -libc_hidden_def (__getrlimit64) -strong_alias (__getrlimit64, __GI_getrlimit) -strong_alias (__getrlimit64, __GI___getrlimit) -strong_alias (__getrlimit64, __getrlimit) -weak_alias (__getrlimit64, getrlimit) -weak_alias (__getrlimit64, getrlimit64) -libc_hidden_weak (getrlimit64) +strong_alias (__old_getrlimit64, __old_getrlimit) +compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0); +compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1); +#endif diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index fd2d81fb68..8674a874b4 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -2016,6 +2016,8 @@ GLIBC_2.26 pwritev64v2 F GLIBC_2.26 reallocarray F GLIBC_2.27 GLIBC_2.27 A GLIBC_2.27 copy_file_range F +GLIBC_2.27 getrlimit F +GLIBC_2.27 getrlimit64 F GLIBC_2.27 glob F GLIBC_2.27 glob64 F GLIBC_2.27 memfd_create F @@ -2025,6 +2027,8 @@ GLIBC_2.27 pkey_free F GLIBC_2.27 pkey_get F GLIBC_2.27 pkey_mprotect F GLIBC_2.27 pkey_set F +GLIBC_2.27 setrlimit F +GLIBC_2.27 setrlimit64 F GLIBC_2.27 strfromf128 F GLIBC_2.27 strfromf32 F GLIBC_2.27 strfromf32x F diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c index 1b8a95b9e9..871c878b7e 100644 --- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c +++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c @@ -15,47 +15,39 @@ License along with the GNU C Library; if not, see . */ -#include -#include - -/* Add this redirection so the strong_alias linking setrlimit64 to - {__}setrlimit does not throw a type error. */ -#undef setrlimit -#undef __setrlimit -#define setrlimit setrlimit_redirect -#define __setrlimit __setrlimit_redirect -#include -#undef setrlimit -#undef __setrlimit +#define USE_VERSIONED_RLIMIT +#include +versioned_symbol (libc, __setrlimit, setrlimit, GLIBC_2_27); +versioned_symbol (libc, __setrlimit64, setrlimit64, GLIBC_2_27); +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27) /* RLIM64_INFINITY was supposed to be a glibc convention rather than anything seen by the kernel, but it ended being passed to the kernel through the prlimit64 syscall. Given that a lot of binaries with the wrong constant value are in the wild, provide a wrapper function fixing the value before the syscall. */ -#define KERNEL_RLIM64_INFINITY 0xffffffffffffffffULL +# define OLD_RLIM64_INFINITY 0x7fffffffffffffffULL int -__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) +attribute_compat_text_section +__old_setrlimit64 (enum __rlimit_resource resource, + const struct rlimit64 *rlimits) { struct rlimit64 krlimits; - if (rlimits->rlim_cur == RLIM64_INFINITY) - krlimits.rlim_cur = KERNEL_RLIM64_INFINITY; + if (rlimits->rlim_cur == OLD_RLIM64_INFINITY) + krlimits.rlim_cur = RLIM64_INFINITY; else krlimits.rlim_cur = rlimits->rlim_cur; - if (rlimits->rlim_max == RLIM64_INFINITY) - krlimits.rlim_max = KERNEL_RLIM64_INFINITY; + if (rlimits->rlim_max == OLD_RLIM64_INFINITY) + krlimits.rlim_max = RLIM64_INFINITY; else krlimits.rlim_max = rlimits->rlim_max; - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &krlimits, NULL); + return __setrlimit64 (resource, &krlimits); } -weak_alias (__setrlimit64, setrlimit64) - -strong_alias (__setrlimit64, __setrlimit) -weak_alias (__setrlimit64, setrlimit) -#ifdef SHARED -__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64); +strong_alias (__old_setrlimit64, __old_setrlimit) +compat_symbol (libc, __old_setrlimit, setrlimit, GLIBC_2_0); +compat_symbol (libc, __old_setrlimit64, setrlimit64, GLIBC_2_1); #endif diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c index 3750cf22fa..1cc82e364d 100644 --- a/sysdeps/unix/sysv/linux/getrlimit64.c +++ b/sysdeps/unix/sysv/linux/getrlimit64.c @@ -45,13 +45,16 @@ libc_hidden_def (__getrlimit64) strong_alias (__getrlimit64, __GI_getrlimit) strong_alias (__getrlimit64, __GI___getrlimit) strong_alias (__getrlimit64, __getrlimit) +/* Alpha defines a versioned getrlimit{64}. */ +# ifndef USE_VERSIONED_RLIMIT weak_alias (__getrlimit64, getrlimit) -/* And there is no need for compat symbols. */ -# undef SHLIB_COMPAT -# define SHLIB_COMPAT(a, b, c) 0 -#endif +weak_alias (__getrlimit64, getrlimit64) +libc_hidden_weak (getrlimit64) +# else +weak_alias (__getrlimit64, __GI_getrlimit64) +# endif -#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2) +#elif SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2) /* Back compatible 2GiB limited rlimit. */ extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *) attribute_hidden; @@ -78,7 +81,4 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits) } versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2); compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1); -#else -weak_alias (__getrlimit64, getrlimit64) -libc_hidden_weak (getrlimit64) -#endif +#endif /* __RLIM_T_MATCHES_RLIM64_T */ diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c index 3ec831fb4d..860fccb548 100644 --- a/sysdeps/unix/sysv/linux/setrlimit64.c +++ b/sysdeps/unix/sysv/linux/setrlimit64.c @@ -38,11 +38,16 @@ __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) { return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL); } +/* Alpha defines a versioned setrlimit{64}. */ +#ifndef USE_VERSIONED_RLIMIT weak_alias (__setrlimit64, setrlimit64) +#endif #if __RLIM_T_MATCHES_RLIM64_T strong_alias (__setrlimit64, __setrlimit) +# ifndef USE_VERSIONED_RLIMIT weak_alias (__setrlimit64, setrlimit) +# endif # ifdef SHARED __hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64); # endif From patchwork Fri Jan 5 13:24:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 856042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88858-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="cIA0OXvJ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zCllN1Wfhz9ryv for ; Sat, 6 Jan 2018 00:25:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=S6nhkGDy91cAz47ynWgGna1fDAi/9W6 rpy/0IVPIIMnbuQKiGWjOH/ijBQP4XXJWlqxGQgIJoCdjFb2OlQM8Wv8KS9tR5DY 9+EoNC6JygjdUPsWriQ6UH4ncakcmIletmhuXflUVUH6XU0Vt1kfR/g3J92gV8xk VZbzjLMKX/Ic= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=87eaVQ7RJri3u2hR/1s0CPy1wlM=; b=cIA0O XvJGdhaVfLln+KsrjkMmUmXHmueW9jI32+wpuM/571kOy0tcPr4TDqooQfkAAmMf hvnHjQKvpAQewA759OM7tEvVcW4YWAcUkFSebXgSoSWuh07HphUhYRc5VIP9UWAs kduIpGqnDzbUuDKUU5OGTYIF32akiP1zxpMBUo= Received: (qmail 101767 invoked by alias); 5 Jan 2018 13:24:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 97113 invoked by uid 89); 5 Jan 2018 13:24:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678] Date: Fri, 5 Jan 2018 14:24:28 +0100 Message-Id: <20180105132429.21118-4-aurelien@aurel32.net> In-Reply-To: <20180105132429.21118-1-aurelien@aurel32.net> References: <20180105132429.21118-1-aurelien@aurel32.net> prlimit called without a new value fails on 32-bit machines if any of the soft or hard limits are infinity. This is because prlimit does not translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY, but checks that the value returned by the prlimit64 syscall fits into a 32-bit value, like it is done for example in getrlimit. Note that on the other hand new_rlimit is correctly translated from RLIM_INFINITY to RLIM64_INFINITY before calling the syscall. This patch fixes that. Changelog: [BZ #22678] * sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY. Reviewed-by: Adhemerval Zanella --- ChangeLog | 6 ++++++ sysdeps/unix/sysv/linux/prlimit.c | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd0fc0bc71..53c3d62b2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-01-05 Aurelien Jarno + + [BZ #22678] + * sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate + old_rlimit from RLIM64_INFINITY to RLIM_INFINITY. + 2018-01-05 Aurelien Jarno Adhemerval Zanella diff --git a/sysdeps/unix/sysv/linux/prlimit.c b/sysdeps/unix/sysv/linux/prlimit.c index 9db8e821b3..2fa0642c76 100644 --- a/sysdeps/unix/sysv/linux/prlimit.c +++ b/sysdeps/unix/sysv/linux/prlimit.c @@ -50,21 +50,24 @@ prlimit (__pid_t pid, enum __rlimit_resource resource, { /* The prlimit64 syscall is ill-designed for 32-bit machines. We have to provide a 32-bit variant since otherwise the LFS - system would not work. But what shall we do if the syscall - succeeds but the old values do not fit into a rlimit - structure? We cannot return an error because the operation - itself worked. Best is perhaps to return RLIM_INFINITY. */ + system would not work. The infinity value can be translated, + but otherwise what shall we do if the syscall succeeds but the + old values do not fit into a rlimit structure? We cannot return + an error because the operation itself worked. Best is perhaps + to return RLIM_INFINITY. */ old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur; if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur) { - if (new_rlimit == NULL) + if ((new_rlimit == NULL) + && (old_rlimit64_mem.rlim_cur != RLIM64_INFINITY)) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); old_rlimit->rlim_cur = RLIM_INFINITY; } old_rlimit->rlim_max = old_rlimit64_mem.rlim_max; if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max) { - if (new_rlimit == NULL) + if ((new_rlimit == NULL) + && (old_rlimit64_mem.rlim_max != RLIM64_INFINITY)) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); old_rlimit->rlim_max = RLIM_INFINITY; } From patchwork Fri Jan 5 13:24:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 856041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88857-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="R97S5sQN"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zCllD1GxHz9ryv for ; Sat, 6 Jan 2018 00:24:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=F0cFf6fctiw8rtP5des+2xDqMcB1B2Z NEwEBrVbF7dolfuvr0JZNwLPWfS0x64v3XhHIahIJMe6VpZ7XctlwqchpYxBgeTh H1oUBYVgH+b8Sa+5F+IQeWEmdoo0JPGJm6QWvyCvSIjmH6HVgObT3i1+IsjlMxyh ejYSys9OV4JU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=sM7FRFky1lKGC+kYsAXS+NmSNpw=; b=R97S5 sQNjv1txutz5PjEMwTl9RKLGiZefD2ikC5l7eQFoRWVvcZtHKiD1Gd1m+6oS0V1N 6VyQiRGlDuyegXdrU4s40q5HPqdtM/+W9IF2J6PCw2gyiMWS72bF3QVwXGbI1zZm 8FWEM5dWle7Yq1dfEVjgy35HgQw9/nU/jefEDc= Received: (qmail 101611 invoked by alias); 5 Jan 2018 13:24:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 100262 invoked by uid 89); 5 Jan 2018 13:24:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=shoot, foot X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Date: Fri, 5 Jan 2018 14:24:29 +0100 Message-Id: <20180105132429.21118-5-aurelien@aurel32.net> In-Reply-To: <20180105132429.21118-1-aurelien@aurel32.net> References: <20180105132429.21118-1-aurelien@aurel32.net> Add a test to check that the getrlimit, setrlimit and prlimit functions and their 64-bit equivalent behave correctly with RLIM_INFINITY and RLIM64_INFINITY. For that it assumes that the prlimit64 function calls the syscall directly without translating the value and that the kernel uses the -1 value to represent infinity. It first finds a resource with the hard limit set to infinity so the soft limit can be manipulated easily and check for the consistency between the value set or get by the prlimit64 and the other functions. It is Linux specific add it uses the prlimit and prlimit64 functions. Changelog: * sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file. * sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity. Reviewed-by: Adhemerval Zanella --- ChangeLog | 5 + sysdeps/unix/sysv/linux/Makefile | 3 +- sysdeps/unix/sysv/linux/tst-rlimit-infinity.c | 157 ++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c diff --git a/ChangeLog b/ChangeLog index 53c3d62b2e..81ce7f3dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-01-05 Aurelien Jarno + + * sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file. + * sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity. + 2018-01-05 Aurelien Jarno [BZ #22678] diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 4af9c5661d..8f19e0efc3 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -44,7 +44,8 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \ - test-errno-linux tst-memfd_create tst-mlock2 tst-pkey + test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ + tst-rlimit-infinity # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system diff --git a/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c new file mode 100644 index 0000000000..58aace625a --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include + +static int resources[] = { + /* The following 7 limits are part of POSIX and must exist. */ + RLIMIT_CORE, + RLIMIT_CPU, + RLIMIT_DATA, + RLIMIT_FSIZE, + RLIMIT_NOFILE, + RLIMIT_STACK, + RLIMIT_AS +}; + +#define nresources (sizeof (resources) / sizeof (resources[0])) + +/* Assume that the prlimit64 function calls the prlimit64 syscall without + mangling the arguments. */ +#define PRLIMIT64_INFINITY ((rlim64_t) -1) + +/* As we don't know which limit will be modified, use a sufficiently high + value to not shoot ourself in the foot. Use a 32-bit value to test + both the 32- and 64-bit versions, and keep the highest bit clear to + avoid sign extension. */ +#define PRLIMIT64_TESTVAL ((rlim64_t) 0x42420000) + +static void +test_getrlimit (int resource, rlim_t exp_cur, rlim_t exp_max) +{ + struct rlimit r; + TEST_VERIFY_EXIT (getrlimit (resource, &r) == 0); + TEST_COMPARE (r.rlim_cur, exp_cur); + TEST_COMPARE (r.rlim_max, exp_max); +} + +static void +test_getrlimit64 (int resource, rlim64_t exp_cur, rlim64_t exp_max) +{ + struct rlimit64 r; + TEST_VERIFY_EXIT (getrlimit64 (resource, &r) == 0); + TEST_COMPARE (r.rlim_cur, exp_cur); + TEST_COMPARE (r.rlim_max, exp_max); +} + +static void +test_prlimit_get (int resource, rlim_t exp_cur, rlim_t exp_max) +{ + struct rlimit r; + TEST_VERIFY_EXIT (prlimit (0, resource, NULL, &r) == 0); + TEST_COMPARE (r.rlim_cur, exp_cur); + TEST_COMPARE (r.rlim_max, exp_max); +} + +static void +test_prlimit64_get (int resource, rlim64_t exp_cur, rlim64_t exp_max) +{ + struct rlimit64 r; + TEST_COMPARE (prlimit64 (0, resource, NULL, &r), 0); + TEST_COMPARE (r.rlim_cur, exp_cur); + TEST_COMPARE (r.rlim_max, exp_max); +} + +static void +test_setrlimit (int resource, rlim_t new_cur, rlim_t new_max) +{ + struct rlimit r = { new_cur, new_max }; + TEST_COMPARE (setrlimit (resource, &r), 0); +} + +static void +test_setrlimit64 (int resource, rlim64_t new_cur, rlim64_t new_max) +{ + struct rlimit64 r = { new_cur, new_max }; + TEST_COMPARE (setrlimit64 (resource, &r), 0); +} + +static void +test_prlimit_set (int resource, rlim_t new_cur, rlim_t new_max) +{ + struct rlimit r = { new_cur, new_max }; + TEST_COMPARE (prlimit (0, resource, &r, NULL), 0); +} + +static void +test_prlimit64_set (int resource, rlim64_t new_cur, rlim64_t new_max) +{ + struct rlimit64 r = { new_cur, new_max }; + TEST_COMPARE (prlimit64 (0, resource, &r, NULL), 0); +} + +static int +do_test (void) +{ + int resource = -1; + + /* Find a resource with hard limit set to infinity, so that the soft limit + can be manipulated to any value. */ + for (int i = 0; i < nresources; ++i) + { + struct rlimit64 r64; + int res = prlimit64 (0, resources[i], NULL, &r64); + if ((res == 0) && (r64.rlim_max == PRLIMIT64_INFINITY)) + { + resource = resources[i]; + break; + } + } + + if (resource == -1) + FAIL_UNSUPPORTED + ("Could not find and limit with hard limit set to infinity."); + + /* First check that the get functions work correctly with the test value. */ + test_prlimit64_set (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY); + test_getrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY); + test_getrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY); + test_prlimit_get (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY); + + /* Then check that the get functions work correctly with infinity. */ + test_prlimit64_set (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY); + test_getrlimit (resource, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY); + test_prlimit_get (resource, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit64_get (resource, RLIM64_INFINITY, RLIM64_INFINITY); + + /* Then check that setrlimit works correctly with the test value. */ + test_setrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY); + + /* Then check that setrlimit works correctly with infinity. */ + test_setrlimit (resource, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY); + + /* Then check that setrlimit64 works correctly with the test value. */ + test_setrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY); + + /* Then check that setrlimit64 works correctly with infinity. */ + test_setrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY); + + /* Then check that prlimit works correctly with the test value. */ + test_prlimit_set (resource, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY); + + /* Finally check that prlimit works correctly with infinity. */ + test_prlimit_set (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY); + test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"