From 96afb8b20362d493d98cd2e2dca8cfb1e7f77a63 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 7 Apr 2022 15:11:41 +0000 Subject: [PATCH] Add build time check and a shim for __rlimit_resource_t Use the __rlimit_resource_t type (which may be an int or an emum) to clean up enum conversion warnings with icc. Signed-off-by: Colin Ian King --- Makefile.config | 20 ++++++++++++-------- core-limit.c | 2 +- stress-get.c | 8 ++++---- stress-ng.h | 6 ++++++ stress-rlimit.c | 6 +++--- stress-set.c | 6 +++--- test/test-rlimit_resource_t.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 test/test-rlimit_resource_t.c diff --git a/Makefile.config b/Makefile.config index 19d6a8428..7d0e91eca 100644 --- a/Makefile.config +++ b/Makefile.config @@ -872,14 +872,15 @@ types: \ COMPLEX DATTR_T DVD_AUTHINFO DVD_STRUCT FLOAT_DECIMAL32 FLOAT_DECIMAL64 \ FLOAT_DECIMAL128 FLOAT16 FLOAT32 FLOAT64 FLOAT80 FLOAT128 INO64_T \ INT128_T KERNEL_LONG_T KERNEL_ULONG_T LANDLOCK_RULE_TYPE LOFF_T \ - MODE_T OFF_T OFF64_T PTHREAD_MUTEXATTR_T CDROM_BLK CDROM_MCN CDROM_MSF \ - CDROM_READ_AUDIO CDROM_SUBCHNL CDROM_TI CDROM_TOCENTRY CDROM_TOCHDR \ - CDROM_VOLCTRL CONSOLEFONTDESC DM_IOCTL FLOPPY_FDC_STATE FLOPPY_DRIVE_STRUCT \ - FLOPPY_STRUCT FSVERITY_DIGEST FSVERITY_ENABLE_ARG FSXATTR_STRUCT IFCONF \ - ICMPHDR KBDIACRS KBENTRY KBKEYCODE KBSENTRY LANDLOCK_RULESET_ATTR \ - MEDIA_DEVICE_INFO MSGINFO MTRR_GENTRY MTRR_SENTRY OPEN_HOW RTC_PARAM \ - RUSAGE_RU_MINFLT RUSAGE_RU_NVCSW SECCOMP_NOTIF_SIZES SERIAL_ICOUNTER \ - SERIAL_STRUCT SHMID_DS SHMINFO SND_CTL_CARD_INFO SND_CTL_TLV SOCKADDR_UN \ + MODE_T OFF_T OFF64_T PTHREAD_MUTEXATTR_T RLIMIT_RESOURCE_T \ + CDROM_BLK CDROM_MCN CDROM_MSF CDROM_READ_AUDIO CDROM_SUBCHNL CDROM_TI \ + CDROM_TOCENTRY CDROM_TOCHDR CDROM_VOLCTRL CONSOLEFONTDESC DM_IOCTL \ + FLOPPY_FDC_STATE FLOPPY_DRIVE_STRUCT FLOPPY_STRUCT FSVERITY_DIGEST \ + FSVERITY_ENABLE_ARG FSXATTR_STRUCT IFCONF ICMPHDR KBDIACRS KBENTRY \ + KBKEYCODE KBSENTRY LANDLOCK_RULESET_ATTR MEDIA_DEVICE_INFO MSGINFO \ + MTRR_GENTRY MTRR_SENTRY OPEN_HOW RTC_PARAM RUSAGE_RU_MINFLT \ + RUSAGE_RU_NVCSW SECCOMP_NOTIF_SIZES SERIAL_ICOUNTER SERIAL_STRUCT \ + SHMID_DS SHMINFO SND_CTL_CARD_INFO SND_CTL_TLV SOCKADDR_UN \ TERMIOS UNIMAPDESC USBDEVFS_GETDRIVER USER_DESC VT_CONSIZE VT_MODE \ VT_SIZES VT_STAT V4L2_AUDIO V4L2_AUDIOOUT V4L2_CAPABILITY V4L2_DV_TIMINGS \ V4L2_ENC_IDX V4L2_FRAMEBUFFER V4L2_JPEGCOMPRESSION V4L2_STD_ID V2DI \ @@ -951,6 +952,9 @@ OFF64_T: PTHREAD_MUTEXATTR_T: $(call check,test-pthread-mutexattr_t,HAVE_PTHREAD_MUTEXATTR_T,pthread_mutexattr_t) +RLIMIT_RESOURCE_T: + $(call check,test-rlimit_resource_t,HAVE_RLIMIT_RESOURCE_T,__rlimit_resource_t) + CDROM_BLK: $(call check,test-cdrom_blk,HAVE_CDROM_BLK,struct cdrom_blk) diff --git a/core-limit.c b/core-limit.c index 07ae42787..677c7999b 100644 --- a/core-limit.c +++ b/core-limit.c @@ -19,7 +19,7 @@ */ #include "stress-ng.h" -static const int limits[] = { +static const shim_rlimit_resource_t limits[] = { #if defined(RLIMIT_AS) RLIMIT_AS, #endif diff --git a/stress-get.c b/stress-get.c index f3a16e0e4..9821480fb 100644 --- a/stress-get.c +++ b/stress-get.c @@ -92,7 +92,7 @@ static const stress_rusage_t rusages[] = { #undef RLIMIT_FSIZE #endif -static const int rlimits[] = { +static const shim_rlimit_resource_t rlimits[] = { #if defined(RLIMIT_AS) RLIMIT_AS, #endif @@ -426,7 +426,7 @@ static int stress_get(const stress_args_t *args) UNEXPECTED #endif /* Invalid getrlimit syscall and ignoring failure */ - (void)getrlimit(INT_MAX, &rlim); + (void)getrlimit((shim_rlimit_resource_t)INT_MAX, &rlim); for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) { ret = getrlimit(rlimits[i], &rlim); @@ -457,9 +457,9 @@ static int stress_get(const stress_args_t *args) NEED_GLIBC(2,13,0) && \ defined(EOVERFLOW) /* Invalid prlimit syscall and ignoring failure */ - (void)prlimit(mypid, INT_MAX, NULL, &rlim); + (void)prlimit(mypid, (shim_rlimit_resource_t)INT_MAX, NULL, &rlim); pid = stress_get_unused_pid_racy(false); - (void)prlimit(pid, INT_MAX, NULL, &rlim); + (void)prlimit(pid, (shim_rlimit_resource_t)INT_MAX, NULL, &rlim); for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) { struct rlimit rlims[2]; diff --git a/stress-ng.h b/stress-ng.h index 4f664eade..95c7abce4 100644 --- a/stress-ng.h +++ b/stress-ng.h @@ -173,6 +173,12 @@ typedef long int __kernel_long_t; typedef unsigned long int __kernel_ulong_t; #endif +#if defined(HAVE_RLIMIT_RESOURCE_T) +#define shim_rlimit_resource_t __rlimit_resource_t +#else +#define shim_rlimit_resource_t int +#endif + #if defined(__sun__) #if defined(HAVE_GETDOMAINNAME) extern int getdomainname(char *name, size_t len); diff --git a/stress-rlimit.c b/stress-rlimit.c index 71f05da45..39aec4100 100644 --- a/stress-rlimit.c +++ b/stress-rlimit.c @@ -41,14 +41,14 @@ typedef struct { #define MAX_RLIMIT_NOFILE (32) typedef struct { - const int resource; /* rlimit resource ID */ + const shim_rlimit_resource_t resource; /* rlimit resource ID */ const struct rlimit new_limit; /* new rlimit setting */ struct rlimit old_limit; /* original old rlimit setting */ int ret; /* saved old rlimit setting return status */ } stress_limits_t; typedef struct { - const int resource; + const shim_rlimit_resource_t resource; const char *name; } stress_resource_id_t; @@ -184,7 +184,7 @@ static int stress_rlimit_child(const stress_args_t *args, void *ctxt) /* * Exercise illegal bad resource id */ - ret = getrlimit(~0, &rlim); + ret = getrlimit((shim_rlimit_resource_t)~0, &rlim); (void)ret; diff --git a/stress-set.c b/stress-set.c index 74c91b5a0..a25468b67 100644 --- a/stress-set.c +++ b/stress-set.c @@ -42,7 +42,7 @@ UNEXPECTED #define GIDS_MAX (1024) typedef struct { - int id; + shim_rlimit_resource_t id; int ret; struct rlimit rlim; } stress_rlimit_info_t; @@ -514,8 +514,8 @@ static int stress_set(const stress_args_t *args) * resource attribute resulting in EINVAL error */ (void)memset(&rlim, 0, sizeof(rlim)); - if ((getrlimit(INT_MAX, &rlim) < 0) && (errno == EINVAL)) { - (void)setrlimit(INT_MAX, &rlim); + if ((getrlimit((shim_rlimit_resource_t)INT_MAX, &rlim) < 0) && (errno == EINVAL)) { + (void)setrlimit((shim_rlimit_resource_t)INT_MAX, &rlim); } for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) { diff --git a/test/test-rlimit_resource_t.c b/test/test-rlimit_resource_t.c new file mode 100644 index 000000000..75bf03c35 --- /dev/null +++ b/test/test-rlimit_resource_t.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 Colin Ian King + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#define _GNU_SOURCE + +#include + +int main(void) +{ + __rlimit_resource_t r = 0; + + return (int)r; +}