From: Mark Wielaard Date: Sat, 14 Dec 2024 22:34:12 +0000 (+0000) Subject: Use Ints for fds in PRE and POST sys_close_range X-Git-Tag: VALGRIND_3_25_0~199 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d984d9aabe5b89d6787c2604b72c09360e7b6fc0;p=thirdparty%2Fvalgrind.git Use Ints for fds in PRE and POST sys_close_range The double_close_range test failed on riscv64-linux because the close_range wrapper is using unsigned int and the ARG regwords directly. Which causes the ARG2 == ~0U check to fail. Explicitly using Int for the fd arguments fixes this. I am not clear on why this was only an issue for the riscv port. It seems this patch is OK for other arches (tested on amd64 and i386). --- diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index d6b10780d..bfe4c6fe0 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -560,7 +560,7 @@ Int ML_(get_fd_count)(void) } /* Close_range caller might want to close very wide range of file descriptors, - up to 0U. We want to avoid iterating through such a range in a normall + up to ~0U. We want to avoid iterating through such a range in a normal close_range, just up to any open file descriptor. Also, unlike record_fd_close_range, we assume the user might deliberately double closes any file descriptors in the range, so don't warn about double close here. */ diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index e01d920e1..60e05a46c 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -13625,8 +13625,9 @@ PRE(sys_execveat) PRE(sys_close_range) { SysRes res = VG_(mk_SysRes_Success)(0); - unsigned int beg, end; - unsigned int last = ARG2; + Int beg, end; + Int first = ARG1; + Int last = ARG2; FUSE_COMPATIBLE_MAY_BLOCK(); PRINT("sys_close_range ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" @@ -13635,7 +13636,7 @@ PRE(sys_close_range) unsigned int, first, unsigned int, last, unsigned int, flags); - if (ARG1 > last) { + if (first > last) { SET_STATUS_Failure( VKI_EINVAL ); return; } @@ -13643,12 +13644,12 @@ PRE(sys_close_range) if (last >= VG_(fd_hard_limit)) last = VG_(fd_hard_limit) - 1; - if (ARG1 > last) { + if (first > last) { SET_STATUS_Success ( 0 ); return; } - beg = end = ARG1; + beg = end = first; do { if (end > last || (end == 2/*stderr*/ && VG_(debugLog_getLevel)() > 0) @@ -13668,8 +13669,9 @@ PRE(sys_close_range) POST(sys_close_range) { - unsigned int fd; - unsigned int last = ARG2; + Int fd; + Int first = ARG1; + Int last = ARG2; if (!VG_(clo_track_fds) || (ARG3 & VKI_CLOSE_RANGE_CLOEXEC) != 0) @@ -13680,10 +13682,10 @@ POST(sys_close_range) /* If the close_range range is too wide, we don't want to loop through the whole range. */ - if (ARG2 == ~0U) - ML_(record_fd_close_range)(tid, ARG1); + if (last == ~0U) + ML_(record_fd_close_range)(tid, first); else { - for (fd = ARG1; fd <= last; fd++) + for (fd = first; fd <= last; fd++) if ((fd != 2/*stderr*/ || VG_(debugLog_getLevel)() == 0) && fd != VG_(log_output_sink).fd && fd != VG_(xml_output_sink).fd)