]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implement stable variant of sync_file ioctls
authorMark Wielaard <mark@klomp.org>
Sat, 31 Aug 2024 17:47:27 +0000 (19:47 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 5 Oct 2024 12:45:28 +0000 (14:45 +0200)
We implemented an old staging android variant of the sync_file
ioctls. But the data structures and ioctl numbers changed when these
were upstreamed in the table linux kernel.

This implements the SYNC_IOC_MERGE, SYNC_IOC_FILE_INFO and
SYNC_IOC_SET_DEADLINE ioctls. And makes sure to record the new file
descriptor created by SYNC_IOC_MERGE.

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

coregrind/m_syswrap/syswrap-linux.c
include/vki/vki-linux.h

index 4533855998183631667fbeae96839ec81f5b63dc..901c32e95fe8db08faeb5aa874132e2d31a85009 100644 (file)
@@ -7258,6 +7258,29 @@ PRE(sys_ioctl)
       PRE_FIELD_READ ("ioctl(SYNC_IOC_MERGE).fd2",   data->fd2);
       PRE_MEM_RASCIIZ("ioctl(SYNC_IOC_MERGE).name",  (Addr)(&data->name[0]));
       PRE_FIELD_WRITE("ioctl(SYNC_IOC_MERGE).fence", data->fence);
+      PRE_FIELD_READ("ioctl(SYNC_IOC_MERGE).flags",  data->flags);
+      break;
+   }
+
+   case VKI_SYNC_IOC_FILE_INFO: {
+      struct vki_sync_file_info* data =
+         (struct vki_sync_file_info*)(Addr)ARG3;
+      PRE_FIELD_READ ("ioctl(SYNC_IOC_FILE_INFO).flags",      data->flags);
+      PRE_FIELD_READ ("ioctl(SYNC_IOC_FILE_INFO).num_fences", data->num_fences);
+      PRE_FIELD_WRITE("ioctl(SYNC_IOC_FILE_INFO).status",     data->status);
+      if (data->num_fences)
+         PRE_MEM_WRITE("ioctl(SYNC_IOC_FILE_INFO).sync_fence_info",
+                       (Addr)data->sync_fence_info,
+                       (data->num_fences
+                        * sizeof(sizeof(struct vki_sync_fence_info))));
+      break;
+   }
+
+   case VKI_SYNC_IOC_SET_DEADLINE: {
+      struct vki_sync_set_deadline* data =
+         (struct vki_sync_set_deadline*)(Addr)ARG3;
+      PRE_FIELD_READ ("ioctl(SYNC_IOC_SET_DEADLINE).deadline_ns",
+                      data->deadline_ns);
       break;
    }
 
@@ -10454,6 +10477,18 @@ POST(sys_ioctl)
       struct vki_sync_merge_data* data =
          (struct vki_sync_merge_data*)(Addr)ARG3;
       POST_FIELD_WRITE(data->fence);
+      if (VG_(clo_track_fds))
+         ML_(record_fd_open_nameless) (tid, data->fence);
+      break;
+   }
+
+   case VKI_SYNC_IOC_FILE_INFO: {
+      struct vki_sync_file_info* data =
+         (struct vki_sync_file_info*)(Addr)ARG3;
+      POST_FIELD_WRITE(data->status);
+      if (data->num_fences > 0 && (Addr)data->sync_fence_info != (Addr)NULL)
+         POST_MEM_WRITE(data->sync_fence_info,
+                        data->num_fences * sizeof(struct vki_sync_fence_info));
       break;
    }
 
index 708a12b64d03753d7246c47109d68d0120d92165..006f16d9220196744ca5df959b38f4b656d23d34 100644 (file)
@@ -3859,29 +3859,37 @@ struct vki_ion_custom_data {
    _VKI_IOWR(VKI_ION_IOC_MAGIC, 6, struct vki_ion_custom_data)
 
 //----------------------------------------------------------------------
-// From linux-3.19-rc5/drivers/staging/android/uapi/sync.h
+// From include/uapi/linux/sync_file.h 6.10.3
 //----------------------------------------------------------------------
 
 struct vki_sync_merge_data {
-        __vki_s32 fd2;
         char      name[32];
+        __vki_s32 fd2;
         __vki_s32 fence;
+        __vki_u32 flags;
+       __vki_u32 pad;
 };
 
-struct vki_sync_pt_info {
-        __vki_u32 len;
+struct vki_sync_fence_info {
         char      obj_name[32];
         char      driver_name[32];
         __vki_s32 status;
-        __vki_u64 timestamp_ns;
-        __vki_u8  driver_data[0];
+        __vki_u32 flags;
+       __vki_u64 timestamp_ns;
 };
 
-struct vki_sync_fence_info_data {
-        __vki_u32 len;
+struct vki_sync_file_info {
         char      name[32];
         __vki_s32 status;
-        __vki_u8  pt_info[0];
+        __vki_u32 flags;
+        __vki_u32 num_fences;
+        __vki_u32 pad;
+       __vki_u64 sync_fence_info;
+};
+
+struct vki_sync_set_deadline {
+       __vki_u64 deadline_ns;
+       __vki_u64 pad;
 };
 
 #define VKI_SYNC_IOC_MAGIC   '>'
@@ -3890,10 +3898,13 @@ struct vki_sync_fence_info_data {
    _VKI_IOW(VKI_SYNC_IOC_MAGIC, 0, __vki_s32)
 
 #define VKI_SYNC_IOC_MERGE \
-   _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 1, struct vki_sync_merge_data)
+   _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 3, struct vki_sync_merge_data)
+
+#define VKI_SYNC_IOC_FILE_INFO \
+   _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 4, struct vki_sync_file_info)
 
-#define VKI_SYNC_IOC_FENCE_INFO \
-   _VKI_IOWR(VKI_SYNC_IOC_MAGIC, 2, struct vki_sync_fence_info_data)
+#define VKI_SYNC_IOC_SET_DEADLINE \
+   _VKI_IOW(VKI_SYNC_IOC_MAGIC, 5, struct vki_sync_set_deadline)
 
 //----------------------------------------------------------------------
 // From drivers/staging/lustre/lustre/include/lustre/lustre_user.h