]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Wrap the remap_file_pages syscall
authorMartin Cermak <mcermak@redhat.com>
Wed, 3 Sep 2025 14:02:26 +0000 (16:02 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 8 Sep 2025 17:13:18 +0000 (19:13 +0200)
The remap_file_pages() system call is used to create a nonlinear
mapping, that is, a mapping in which the pages of the file are
mapped into a nonsequential order in memory.  It is deprecated
but in some cases it may still be used.  LTP remap_file_pages01
and remap_file_pages02 test-cover it.

Declare a remap_file_pages wrapper in priv_syswrap-linux.h
and hook it for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x\
,x86}- linux using LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=309554

13 files changed:
NEWS
coregrind/m_syswrap/priv_syswrap-linux.h
coregrind/m_syswrap/syswrap-amd64-linux.c
coregrind/m_syswrap/syswrap-arm-linux.c
coregrind/m_syswrap/syswrap-arm64-linux.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-mips64-linux.c
coregrind/m_syswrap/syswrap-ppc32-linux.c
coregrind/m_syswrap/syswrap-ppc64-linux.c
coregrind/m_syswrap/syswrap-riscv64-linux.c
coregrind/m_syswrap/syswrap-s390x-linux.c
coregrind/m_syswrap/syswrap-x86-linux.c
include/vki/vki-scnums-riscv64-linux.h

diff --git a/NEWS b/NEWS
index 0158a23af838b1a56d5adaac1a639826823e1316..8c44791005517b4695e82db9be53a5a6c5c96984 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,7 @@ bugzilla (https://bugs.kde.org/enter_bug.cgi?product=valgrind) rather
 than mailing the developers (or mailing lists) directly -- bugs that
 are not entered into bugzilla tend to get forgotten about or ignored.
 
+309554  Wrap syscall remap_file_pages (216)
 338803  Handling of dwz debug alt files or cross-CU is broken
 418756  MAP_FIXED_NOREPLACE mmap flag unsupported
 493430  Review all syscalls that use or return (new) file descriptors
index 1d5135fc5658fe412e121089948e20070419e912..2fe8fd59da16ea8688018c0099d6ad9a949cdb4d 100644 (file)
@@ -110,6 +110,7 @@ DECL_TEMPLATE(linux, sys_epoll_ctl);
 DECL_TEMPLATE(linux, sys_epoll_wait);
 DECL_TEMPLATE(linux, sys_epoll_pwait);
 DECL_TEMPLATE(linux, sys_epoll_pwait2);
+DECL_TEMPLATE(linux, sys_remap_file_pages);
 DECL_TEMPLATE(linux, sys_eventfd);
 DECL_TEMPLATE(linux, sys_eventfd2);
 
index f15c3dac728bf9c72b9f2e83e5e12ed4cc0c9443..bb970b47d167eb50acd48e27264180676797b23b 100644 (file)
@@ -729,7 +729,7 @@ static SyscallTableEntry syscall_table[] = {
    //   (__NR_epoll_ctl_old,     sys_ni_syscall),     // 214 
 
    //   (__NR_epoll_wait_old,    sys_ni_syscall),     // 215 
-   //   (__NR_remap_file_pages,  sys_remap_file_pages)// 216 
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages), // 216
    GENXY(__NR_getdents64,        sys_getdents64),     // 217 
    LINX_(__NR_set_tid_address,   sys_set_tid_address),// 218 
    //   (__NR_restart_syscall,   sys_restart_syscall),// 219 
index 1aae03c02df406d0b9edcf2b5a8809526d251263..043a4095c40662737a54880ae0d16c798529285e 100644 (file)
@@ -860,7 +860,7 @@ static SyscallTableEntry syscall_main_table[] = {
 
    LINX_(__NR_epoll_ctl,         sys_epoll_ctl),         // 255
    LINXY(__NR_epoll_wait,        sys_epoll_wait),        // 256
-//zz    //   (__NR_remap_file_pages,  sys_remap_file_pages),  // 257 */Linux
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages),  // 257 */Linux
    LINX_(__NR_set_tid_address,   sys_set_tid_address),   // 258
    LINXY(__NR_timer_create,      sys_timer_create),      // 259
 
index f6f63a52e76e55797b28869bf0a2d28bdb3233dd..71d1123d0ef612835adbafc1bb60f6681b197337 100644 (file)
@@ -782,7 +782,7 @@ static SyscallTableEntry syscall_main_table[] = {
    LINX_(__NR_munlockall,        sys_munlockall),        // 231
    GENXY(__NR_mincore,           sys_mincore),           // 232
    GENX_(__NR_madvise,           sys_madvise),           // 233
-   //   (__NR_remap_file_pages,  sys_ni_syscall)         // 234
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages),  // 234
    LINX_(__NR_mbind,             sys_mbind),             // 235
    LINXY(__NR_get_mempolicy,     sys_get_mempolicy),     // 236
    LINX_(__NR_set_mempolicy,     sys_set_mempolicy),     // 237
index fef23763f33daf3d4aa1b55c52d1a9cbf803eb4a..e1450d88638bdf1ea541464829a6ee8bf51f882b 100644 (file)
@@ -2241,6 +2241,19 @@ POST(sys_epoll_pwait2)
    epoll_post_helper (tid, arrghs, status);
 }
 
+PRE(sys_remap_file_pages)
+{
+   /* int remap_file_pages(void addr[.size], size_t size,
+                           int prot, size_t pgoff, int flags); */
+   Int arg_3 = (Int) ARG3;
+   Int arg_5 = (Int) ARG5;
+   PRINT("sys_remap_file_pages ( %#" FMT_REGWORD "x, %lu, %d, %lu, %d",
+         ARG1, ARG2, arg_3, ARG4, arg_5);
+   PRE_REG_READ5(int, "remap_file_pages", void *, addr, vki_size_t,
+                 size_t, int, prot, vki_size_t, pgoff, int, flags);
+   PRE_MEM_READ("sys_remap_file_pages(addr)", ARG1, ARG2);
+}
+
 PRE(sys_eventfd)
 {
    PRINT("sys_eventfd ( %" FMT_REGWORD "u )", ARG1);
index 5234ccc377d89ac2e51a298a62e33152fd96acb7..26ece232b5c9ab67ab5ea0b8dbd2668460efef18 100644 (file)
@@ -701,6 +701,7 @@ static SyscallTableEntry syscall_main_table[] = {
    LINXY (__NR_epoll_create1, sys_epoll_create1),
    LINX_ (__NR_epoll_ctl, sys_epoll_ctl),
    LINXY (__NR_epoll_wait, sys_epoll_wait),
+   LINX_ (__NR_remap_file_pages, sys_remap_file_pages),
    PLAX_(__NR_rt_sigreturn,sys_rt_sigreturn),
 #if defined(VGABI_N32)
    LINXY(__NR_fcntl64, sys_fcntl64),
index cb44107953ac25dfda1ee05c9aca3f81af592b6e..d8dbe7de622be210be9b82d2cb222d78e68e2f20 100644 (file)
@@ -902,7 +902,7 @@ static SyscallTableEntry syscall_table[] = {
    LINX_(__NR_epoll_ctl,         sys_epoll_ctl),         // 237
    LINXY(__NR_epoll_wait,        sys_epoll_wait),        // 238
 
-//..    //   (__NR_remap_file_pages,  sys_remap_file_pages),  // 239 */Linux
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages),  // 239 */Linux
    LINXY(__NR_timer_create,      sys_timer_create),      // 240
    LINXY(__NR_timer_settime,     sys_timer_settime),     // 241
    LINXY(__NR_timer_gettime,     sys_timer_gettime),     // 242
index bb5cb4f7b8273b69c8f96a8f904b9e1132fc928b..3e7a14e405fe574bb17a8c69557a481a88d75bbc 100644 (file)
@@ -884,7 +884,7 @@ static SyscallTableEntry syscall_table[] = {
    LINXY(__NR_epoll_create,      sys_epoll_create),       // 236
    LINX_(__NR_epoll_ctl,         sys_epoll_ctl),          // 237
    LINXY(__NR_epoll_wait,        sys_epoll_wait),         // 238
-// _____(__NR_remap_file_pages,  sys_remap_file_pages),   // 239
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages),   // 239
 
    LINXY(__NR_timer_create,      sys_timer_create),       // 240
    LINXY(__NR_timer_settime,     sys_timer_settime),      // 241
index c3ab78ef594f5444ba1fadf0ac086a7c5db535bd..987205319881c04a14583dd6c39a3ee6f5537402 100644 (file)
@@ -537,6 +537,7 @@ static SyscallTableEntry syscall_main_table[] = {
    LINX_(__NR_munlockall, sys_munlockall),                         /* 231 */
    GENXY(__NR_mincore, sys_mincore),                               /* 232 */
    GENX_(__NR_madvise, sys_madvise),                               /* 233 */
+   LINX_(__NR_remap_file_pages, sys_remap_file_pages),             /* 234 */
    LINX_(__NR_mbind, sys_mbind),                                   /* 235 */
    LINXY(__NR_get_mempolicy, sys_get_mempolicy),                   /* 236 */
    LINX_(__NR_set_mempolicy, sys_set_mempolicy),                   /* 237 */
index ad35a4ebcf4a5eca980550af327ff9c8a4c86acf..8ab81d59352284865df8dc7e3c365ddc6aeddd5c 100644 (file)
@@ -731,7 +731,7 @@ static SyscallTableEntry syscall_table[] = {
 
    GENXY(__NR_statfs64, sys_statfs64),                                // 265
    GENXY(__NR_fstatfs64, sys_fstatfs64),                              // 266
-// ?????(__NR_remap_file_pages, ),
+   LINX_(__NR_remap_file_pages, sys_remap_file_pages),                // 267
    GENX_(268, sys_ni_syscall), /* unimplemented (by the kernel) */    // 268
    GENX_(269, sys_ni_syscall), /* unimplemented (by the kernel) */    // 269
 
index 45c76a6db5e99ac5807a55d7cc6b01604fe575d8..7e68c4e0e58cc4ad08bd8a7291ab54a3ec0f3175 100644 (file)
@@ -1468,7 +1468,7 @@ static SyscallTableEntry syscall_table[] = {
 
    LINX_(__NR_epoll_ctl,         sys_epoll_ctl),         // 255
    LINXY(__NR_epoll_wait,        sys_epoll_wait),        // 256
-//zz    //   (__NR_remap_file_pages,  sys_remap_file_pages),  // 257 */Linux
+   LINX_(__NR_remap_file_pages,  sys_remap_file_pages),  // 257 */Linux
    LINX_(__NR_set_tid_address,   sys_set_tid_address),   // 258
    LINXY(__NR_timer_create,      sys_timer_create),      // 259
 
index 17b6839f8a84f823c1943f7eba008d8451a27040..f084cf44e991e03656b818d86b427dcdb7bb282b 100644 (file)
 #define __NR_munlockall 231
 #define __NR_mincore 232
 #define __NR_madvise 233
+#define __NR_remap_file_pages 234
 #define __NR_mbind 235
 #define __NR_get_mempolicy 236
 #define __NR_set_mempolicy 237