]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Use Ints for fds in PRE and POST sys_close_range
authorMark Wielaard <mark@klomp.org>
Sat, 14 Dec 2024 22:34:12 +0000 (22:34 +0000)
committerMark Wielaard <mark@klomp.org>
Fri, 20 Dec 2024 22:49:30 +0000 (23:49 +0100)
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).

coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c

index d6b10780dc2af867cd23651fb20d1c4abaf9c9f1..bfe4c6fe06b12105fb64a9e62fedb1cc98b8191a 100644 (file)
@@ -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. */
index e01d920e11c6108efc2c83f1a5c7f6e0f431408b..60e05a46c42237094409e199fa8b1608e7369413 100644 (file)
@@ -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)