Blame SOURCES/valgrind-3.16.1-sched_getsetattr.patch

3f23f3
commit a53adb79711ccfc76a4ee32b20253045cdab55c7
3f23f3
Author: Mark Wielaard <mark@klomp.org>
3f23f3
Date:   Mon Jul 27 16:36:17 2020 +0200
3f23f3
3f23f3
    Handle linux syscalls sched_getattr and sched_setattr
3f23f3
    
3f23f3
    The only "special" thing about these syscalls is that the given
3f23f3
    struct sched_attr determines its own size for future expansion.
3f23f3
    
3f23f3
    Original fix by "ISHIKAWA,chiaki" <ishikawa@yk.rim.or.jp>
3f23f3
    
3f23f3
    https://bugs.kde.org/show_bug.cgi?id=369029
3f23f3
3f23f3
diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h
3f23f3
index cdc73c1e6..eb0b320ca 100644
3f23f3
--- a/coregrind/m_syswrap/priv_syswrap-linux.h
3f23f3
+++ b/coregrind/m_syswrap/priv_syswrap-linux.h
3f23f3
@@ -227,6 +227,8 @@ DECL_TEMPLATE(linux, sys_fremovexattr);
3f23f3
 // syscalls.
3f23f3
 DECL_TEMPLATE(linux, sys_sched_setparam);
3f23f3
 DECL_TEMPLATE(linux, sys_sched_getparam);
3f23f3
+DECL_TEMPLATE(linux, sys_sched_setattr);
3f23f3
+DECL_TEMPLATE(linux, sys_sched_getattr);
3f23f3
 DECL_TEMPLATE(linux, sys_sched_setscheduler);
3f23f3
 DECL_TEMPLATE(linux, sys_sched_getscheduler);
3f23f3
 DECL_TEMPLATE(linux, sys_sched_yield);
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c
3f23f3
index 28d90135a..d6f3eb910 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-amd64-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-amd64-linux.c
3f23f3
@@ -846,9 +846,8 @@ static SyscallTableEntry syscall_table[] = {
3f23f3
    LINX_(__NR_process_vm_writev, sys_process_vm_writev),// 311
3f23f3
    LINX_(__NR_kcmp,              sys_kcmp),             // 312
3f23f3
    LINX_(__NR_finit_module,      sys_finit_module),     // 313
3f23f3
-//   LIN__(__NR_sched_setattr,     sys_ni_syscall),       // 314
3f23f3
-
3f23f3
-//   LIN__(__NR_sched_getattr,     sys_ni_syscall),       // 315
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),    // 314
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 315
3f23f3
    LINX_(__NR_renameat2,         sys_renameat2),        // 316
3f23f3
 //   LIN__(__NR_seccomp,           sys_ni_syscall),       // 317
3f23f3
    LINXY(__NR_getrandom,         sys_getrandom),        // 318
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c
3f23f3
index 579542785..70700e53f 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-arm-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-arm-linux.c
3f23f3
@@ -1009,6 +1009,8 @@ static SyscallTableEntry syscall_main_table[] = {
3f23f3
    LINXY(__NR_process_vm_readv,  sys_process_vm_readv), // 376
3f23f3
    LINX_(__NR_process_vm_writev, sys_process_vm_writev),// 377
3f23f3
 
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),    // 380
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 381
3f23f3
    LINX_(__NR_renameat2,         sys_renameat2),        // 382
3f23f3
 
3f23f3
    LINXY(__NR_getrandom,         sys_getrandom),        // 384
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-arm64-linux.c b/coregrind/m_syswrap/syswrap-arm64-linux.c
3f23f3
index 81e01456f..acca02442 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-arm64-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-arm64-linux.c
3f23f3
@@ -806,8 +806,8 @@ static SyscallTableEntry syscall_main_table[] = {
3f23f3
    LINX_(__NR_process_vm_writev, sys_process_vm_writev), // 271
3f23f3
    LINX_(__NR_kcmp,              sys_kcmp),              // 272
3f23f3
    LINX_(__NR_finit_module,      sys_finit_module),      // 273
3f23f3
-   //   (__NR_sched_setattr,     sys_ni_syscall),        // 274
3f23f3
-   //   (__NR_sched_getattr,     sys_ni_syscall),        // 275
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),     // 274
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),     // 275
3f23f3
    LINX_(__NR_renameat2,         sys_renameat2),         // 276
3f23f3
    //   (__NR_seccomp,           sys_ni_syscall),        // 277
3f23f3
    LINXY(__NR_getrandom,         sys_getrandom),         // 278
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
3f23f3
index 5b5b7eee6..56be3032d 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-linux.c
3f23f3
@@ -3677,6 +3677,41 @@ POST(sys_sched_getparam)
3f23f3
    POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3f23f3
 }
3f23f3
 
3f23f3
+PRE(sys_sched_setattr)
3f23f3
+{
3f23f3
+   struct vki_sched_attr *attr;
3f23f3
+   PRINT("sched_setattr ( %ld, %#" FMT_REGWORD "x, %#"
3f23f3
+         FMT_REGWORD "x )", SARG1, ARG2, ARG3 );
3f23f3
+   PRE_REG_READ3(long, "sched_setattr",
3f23f3
+                 vki_pid_t, pid, struct sched_attr *, p, unsigned int, flags);
3f23f3
+   /* We need to be able to read at least the size field.  */
3f23f3
+   PRE_MEM_READ( "sched_setattr(attr->size)", ARG2, sizeof(vki_uint32_t) );
3f23f3
+   attr = (struct vki_sched_attr *)(Addr)ARG2;
3f23f3
+   if (ML_(safe_to_deref)(attr,sizeof(vki_uint32_t)))
3f23f3
+      PRE_MEM_READ( "sched_setattr(attr)", (Addr)attr, attr->size);
3f23f3
+}
3f23f3
+
3f23f3
+PRE(sys_sched_getattr)
3f23f3
+{
3f23f3
+   struct vki_sched_attr *attr;
3f23f3
+   PRINT("sched_getattr ( %ld, %#" FMT_REGWORD "x, %ld, %#"
3f23f3
+         FMT_REGWORD "x )", SARG1, ARG2, ARG3, ARG4 );
3f23f3
+   PRE_REG_READ4(long, "sched_getattr",
3f23f3
+                 vki_pid_t, pid, struct sched_attr *, p,
3f23f3
+                 unsigned int, size, unsigned int, flags);
3f23f3
+   /* We need to be able to read at least the size field.  */
3f23f3
+   PRE_MEM_READ( "sched_setattr(attr->size)", ARG2, sizeof(vki_uint32_t) );
3f23f3
+   /* And the kernel needs to be able to write to the whole struct size. */
3f23f3
+   attr = (struct vki_sched_attr *)(Addr)ARG2;
3f23f3
+   if (ML_(safe_to_deref)(attr,sizeof(vki_uint32_t)))
3f23f3
+      PRE_MEM_WRITE( "sched_setattr(attr)", (Addr)attr, attr->size);
3f23f3
+}
3f23f3
+POST(sys_sched_getattr)
3f23f3
+{
3f23f3
+   struct vki_sched_attr *attr = (struct vki_sched_attr *)(Addr)ARG2;
3f23f3
+   POST_MEM_WRITE( (Addr)attr, attr->size );
3f23f3
+}
3f23f3
+
3f23f3
 PRE(sys_sched_getscheduler)
3f23f3
 {
3f23f3
    PRINT("sys_sched_getscheduler ( %ld )", SARG1);
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c
3f23f3
index eed12a1bc..c19cb9e0e 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-ppc32-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c
3f23f3
@@ -1016,6 +1016,9 @@ static SyscallTableEntry syscall_table[] = {
3f23f3
    LINXY(__NR_process_vm_readv,  sys_process_vm_readv), // 351
3f23f3
    LINX_(__NR_process_vm_writev, sys_process_vm_writev),// 352
3f23f3
 
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),    // 355
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 356
3f23f3
+
3f23f3
    LINXY(__NR_getrandom,         sys_getrandom),        // 359
3f23f3
    LINXY(__NR_memfd_create,      sys_memfd_create),     // 360
3f23f3
 
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c
3f23f3
index d58200b49..b6422a765 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-ppc64-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c
3f23f3
@@ -998,6 +998,8 @@ static SyscallTableEntry syscall_table[] = {
3f23f3
    LINXY(__NR_process_vm_readv,  sys_process_vm_readv), // 351
3f23f3
    LINX_(__NR_process_vm_writev, sys_process_vm_writev),// 352
3f23f3
 
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),    // 355
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 356
3f23f3
    LINX_(__NR_renameat2,         sys_renameat2),        // 357
3f23f3
 
3f23f3
    LINXY(__NR_getrandom,         sys_getrandom),        // 359
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c
3f23f3
index a0a330aa2..3427fee16 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-s390x-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-s390x-linux.c
3f23f3
@@ -825,8 +825,8 @@ static SyscallTableEntry syscall_table[] = {
3f23f3
    LINX_(__NR_kcmp, sys_kcmp),                                        // 343
3f23f3
 // ?????(__NR_finit_module, ),                                        // 344
3f23f3
 
3f23f3
-// ?????(__NR_sched_setattr, ),                                       // 345
3f23f3
-// ?????(__NR_sched_getattr, ),                                       // 346
3f23f3
+   LINX_(__NR_sched_setattr, sys_sched_setattr),                      // 345
3f23f3
+   LINXY(__NR_sched_getattr, sys_sched_getattr),                      // 346
3f23f3
    LINX_(__NR_renameat2, sys_renameat2),                              // 347
3f23f3
 // ?????(__NR_seccomp, ),                                             // 348
3f23f3
    LINXY(__NR_getrandom, sys_getrandom),                              // 349
3f23f3
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
3f23f3
index 332ed0bf2..b59d96f37 100644
3f23f3
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
3f23f3
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
3f23f3
@@ -1580,8 +1580,8 @@ static SyscallTableEntry syscall_table[] = {
3f23f3
    LINX_(__NR_kcmp,              sys_kcmp),             // 349
3f23f3
 
3f23f3
 //   LIN__(__NR_finit_module,      sys_ni_syscall),       // 350
3f23f3
-//   LIN__(__NR_sched_setattr,     sys_ni_syscall),       // 351
3f23f3
-//   LIN__(__NR_sched_getattr,     sys_ni_syscall),       // 352
3f23f3
+   LINX_(__NR_sched_setattr,     sys_sched_setattr),    // 351
3f23f3
+   LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 352
3f23f3
    LINX_(__NR_renameat2,         sys_renameat2),        // 353
3f23f3
 //   LIN__(__NR_seccomp,           sys_ni_syscall),       // 354
3f23f3
 
3f23f3
diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h
3f23f3
index 75b583165..ef93b9258 100644
3f23f3
--- a/include/vki/vki-linux.h
3f23f3
+++ b/include/vki/vki-linux.h
3f23f3
@@ -410,6 +410,23 @@ struct vki_sched_param {
3f23f3
 	int sched_priority;
3f23f3
 };
3f23f3
 
3f23f3
+struct vki_sched_attr {
3f23f3
+	vki_uint32_t size;
3f23f3
+	vki_uint32_t sched_policy;
3f23f3
+	vki_uint64_t sched_flags;
3f23f3
+
3f23f3
+	/* SCHED_NORMAL, SCHED_BATCH */
3f23f3
+	vki_int32_t sched_nice;
3f23f3
+
3f23f3
+	/* SCHED_FIFO, SCHED_RR */
3f23f3
+	vki_uint32_t sched_priority;
3f23f3
+
3f23f3
+	/* SCHED_DEADLINE */
3f23f3
+	vki_uint64_t sched_runtime;
3f23f3
+	vki_uint64_t sched_deadline;
3f23f3
+	vki_uint64_t sched_period;
3f23f3
+};
3f23f3
+
3f23f3
 #define VKI_TASK_COMM_LEN 16
3f23f3
 
3f23f3
 //----------------------------------------------------------------------