]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge a bunch of syscall-related revisions from the trunk, in the
authorJulian Seward <jseward@acm.org>
Thu, 29 May 2008 13:32:51 +0000 (13:32 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 29 May 2008 13:32:51 +0000 (13:32 +0000)
following order:

7917 (partial): add epoll_pwait utimensat eventfd timerfd signalfd
7942: add timerfd_create timerfd_gettime timerfd_settime
7983: kludgey fix for ppc compile failures for timerfd_*
8047: fix futimesat and utimensat
8051: proper fix replacing 7983
8132: fix signalfd
8138: tidy up signalfd
8147: tidy up signalfd some more

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_3_BRANCH@8148

coregrind/m_syswrap/priv_syswrap-linux.h
coregrind/m_syswrap/syswrap-amd64-linux.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-ppc32-linux.c
coregrind/m_syswrap/syswrap-ppc64-linux.c
coregrind/m_syswrap/syswrap-x86-linux.c
include/vki/vki-scnums-amd64-linux.h
include/vki/vki-scnums-ppc32-linux.h
include/vki/vki-scnums-ppc64-linux.h
include/vki/vki-scnums-x86-linux.h

index c5edfeaca6ecc44633fd1c63e5b8fedc89cd7f98..128196edd94c7f26a6ae17c5369feb5627d5e785 100644 (file)
@@ -82,6 +82,8 @@ DECL_TEMPLATE(linux, sys_ppoll);
 DECL_TEMPLATE(linux, sys_epoll_create);
 DECL_TEMPLATE(linux, sys_epoll_ctl);
 DECL_TEMPLATE(linux, sys_epoll_wait);
+DECL_TEMPLATE(linux, sys_epoll_pwait);
+DECL_TEMPLATE(linux, sys_eventfd);
 
 DECL_TEMPLATE(linux, sys_gettid);
 DECL_TEMPLATE(linux, sys_set_tid_address);
@@ -124,6 +126,11 @@ DECL_TEMPLATE(linux, sys_timer_settime);
 DECL_TEMPLATE(linux, sys_timer_gettime);
 DECL_TEMPLATE(linux, sys_timer_getoverrun);
 DECL_TEMPLATE(linux, sys_timer_delete);
+DECL_TEMPLATE(linux, sys_timerfd_create);
+DECL_TEMPLATE(linux, sys_timerfd_gettime);
+DECL_TEMPLATE(linux, sys_timerfd_settime);
+
+DECL_TEMPLATE(linux, sys_signalfd);
 
 DECL_TEMPLATE(linux, sys_capget);
 DECL_TEMPLATE(linux, sys_capset);
index f44dfa615912b12c76a19a35369394c36c069e48..9e1ee5e4b2f89a0e4a1c83ea6e287ef9febff1da 100644 (file)
@@ -1367,7 +1367,7 @@ const SyscallTableEntry ML_(syscall_table)[] = {
    LINX_(__NR_faccessat,        sys_faccessat),        // 269
 
    LINX_(__NR_pselect6,                 sys_pselect6),         // 270
-//   LINXY(__NR_ppoll,          sys_ni_syscall),       // 271
+   LINXY(__NR_ppoll,            sys_ppoll),            // 271
 //   LINX_(__NR_unshare,                sys_unshare),          // 272
    LINX_(__NR_set_robust_list,  sys_set_robust_list),  // 273
    LINXY(__NR_get_robust_list,  sys_get_robust_list),  // 274
@@ -1377,6 +1377,14 @@ const SyscallTableEntry ML_(syscall_table)[] = {
    LINX_(__NR_sync_file_range,   sys_sync_file_range),  // 277
 //   LINX_(__NR_vmsplice,          sys_ni_syscall),       // 278
 //   LINX_(__NR_move_pages,        sys_ni_syscall),       // 279
+   LINX_(__NR_utimensat,         sys_utimensat),        // 280
+   LINXY(__NR_epoll_pwait,       sys_epoll_pwait),      // 281
+   LINXY(__NR_signalfd,          sys_signalfd),         // 282
+   LINXY(__NR_timerfd_create,    sys_timerfd_create),   // 283
+   LINX_(__NR_eventfd,           sys_eventfd),          // 284
+//   LINX_(__NR_fallocate,        sys_ni_syscall),        // 285
+   LINXY(__NR_timerfd_settime,   sys_timerfd_settime),  // 286
+   LINXY(__NR_timerfd_gettime,   sys_timerfd_gettime),  // 287
 };
 
 const UInt ML_(syscall_table_size) = 
index 4879869874b0fc016ee1756010ebc910f7dae9c5..95a6d3fadf2f932d50e523512ffab99bb8be37c2 100644 (file)
@@ -5638,7 +5638,7 @@ PRE(sys_utimes)
    PRE_REG_READ2(long, "utimes", char *, filename, struct timeval *, tvp);
    PRE_MEM_RASCIIZ( "utimes(filename)", ARG1 );
    if (ARG2 != 0)
-      PRE_MEM_READ( "utimes(tvp)", ARG2, sizeof(struct vki_timeval) );
+      PRE_MEM_READ( "utimes(tvp)", ARG2, 2 * sizeof(struct vki_timeval) );
 }
 
 PRE(sys_acct)
index 66de8296ee76ccc2e4e4821de04dfe5c001603d7..d8006a8ab6b29cd4b182d21699173b6d8e1d8146 100644 (file)
@@ -988,7 +988,7 @@ PRE(sys_ppoll)
    UInt i;
    struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1;
    *flags |= SfMayBlock;
-   PRINT("sys_ppoll ( %p, %d, %p, %p, %llu )\n", ARG1,ARG2,ARG3,ARG4,ARG5);
+   PRINT("sys_ppoll ( %p, %d, %p, %p, %llu )\n", ARG1,ARG2,ARG3,ARG4,(ULong)ARG5);
    PRE_REG_READ5(long, "ppoll",
                  struct vki_pollfd *, ufds, unsigned int, nfds,
                  struct vki_timespec *, tsp, vki_sigset_t *, sigmask,
@@ -1072,6 +1072,41 @@ POST(sys_epoll_wait)
       POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
 }
 
+PRE(sys_epoll_pwait)
+{
+   *flags |= SfMayBlock;
+   PRINT("sys_epoll_pwait ( %d, %p, %d, %d, %p, %llu )", ARG1,ARG2,ARG3,ARG4,ARG5,(ULong)ARG6);
+   PRE_REG_READ6(long, "epoll_pwait",
+                 int, epfd, struct vki_epoll_event *, events,
+                 int, maxevents, int, timeout, vki_sigset_t *, sigmask,
+                 vki_size_t, sigsetsize);
+   PRE_MEM_WRITE( "epoll_pwait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
+   if (ARG4)
+      PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );
+}
+POST(sys_epoll_pwait)
+{
+   vg_assert(SUCCESS);
+   if (RES > 0)
+      POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
+}
+
+PRE(sys_eventfd)
+{
+   PRINT("sys_eventfd ( %u )", ARG1);
+   PRE_REG_READ1(long, "sys_eventfd", unsigned int, count);
+}
+POST(sys_eventfd)
+{
+   if (!ML_(fd_allowed)(RES, "eventfd", tid, True)) {
+      VG_(close)(RES);
+      SET_STATUS_Failure( VKI_EMFILE );
+   } else {
+      if (VG_(clo_track_fds))
+         ML_(record_fd_open_nameless) (tid, RES);
+   }
+}
+
 /* ---------------------------------------------------------------------
    tid-related wrappers
    ------------------------------------------------------------------ */
@@ -1672,6 +1707,126 @@ PRE(sys_timer_delete)
    PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid);
 }
 
+/* ---------------------------------------------------------------------
+   timerfd* wrappers
+   See also http://lwn.net/Articles/260172/ for an overview.
+   See also /usr/src/linux/fs/timerfd.c for the implementation.
+   ------------------------------------------------------------------ */
+
+/* Returns True if running on 2.6.22, else False (or False if
+   cannot be determined). */
+static Bool linux_kernel_2_6_22(void)
+{
+   static Int result = -1;
+   Int fd, read;
+   HChar release[64];
+   SysRes res;
+
+   if (result == -1) {
+      res = VG_(open)("/proc/sys/kernel/osrelease", 0, 0);
+      if (res.isError)
+         return False;
+      fd = res.res;
+      read = VG_(read)(fd, release, sizeof(release) - 1);
+      vg_assert(read >= 0);
+      release[read] = 0;
+      VG_(close)(fd);
+      //VG_(printf)("kernel release = %s\n", release);
+      result = (VG_(strncmp)(release, "2.6.22", 6) == 0
+                && (release[6] < '0' || release[6] > '9'));
+   }
+   vg_assert(result == 0 || result == 1);
+   return result == 1;
+}
+
+PRE(sys_timerfd_create)
+{
+   if (linux_kernel_2_6_22()) {
+      /* 2.6.22 kernel: timerfd system call. */
+      PRINT("sys_timerfd ( %ld, %ld, %p )", ARG1, ARG2, ARG3);
+      PRE_REG_READ3(long, "sys_timerfd",
+                    int, fd, int, clockid, const struct itimerspec *, tmr);
+      PRE_MEM_READ("timerfd(tmr)", ARG3,
+                   sizeof(struct vki_itimerspec) );
+      if ((Word)ARG1 != -1L && !ML_(fd_allowed)(ARG1, "timerfd", tid, False))
+         SET_STATUS_Failure( VKI_EBADF );
+   } else {
+      /* 2.6.24 and later kernels: timerfd_create system call. */
+      PRINT("sys_timerfd_create (%ld, %ld )", ARG1, ARG2);
+      PRE_REG_READ2(long, "timerfd_create", int, clockid, int, flags);
+   }
+}
+POST(sys_timerfd_create)
+{
+   if (linux_kernel_2_6_22())
+   {
+      /* 2.6.22 kernel: timerfd system call. */
+      if (!ML_(fd_allowed)(RES, "timerfd", tid, True)) {
+         VG_(close)(RES);
+         SET_STATUS_Failure( VKI_EMFILE );
+      } else {
+         if (VG_(clo_track_fds))
+            ML_(record_fd_open_nameless) (tid, RES);
+      }
+   }
+   else
+   {
+      /* 2.6.24 and later kernels: timerfd_create system call. */
+      if (!ML_(fd_allowed)(RES, "timerfd_create", tid, True)) {
+         VG_(close)(RES);
+         SET_STATUS_Failure( VKI_EMFILE );
+      } else {
+         if (VG_(clo_track_fds))
+            ML_(record_fd_open_nameless) (tid, RES);
+      }
+   }
+}
+
+PRE(sys_timerfd_gettime)
+{
+   PRINT("sys_timerfd_gettime ( %d, %p )", ARG1, ARG2);
+   PRE_REG_READ2(long, "timerfd_gettime",
+                 int, ufd,
+                 struct vki_itimerspec*, otmr);
+   if (!ML_(fd_allowed)(ARG1, "timerfd_gettime", tid, False))
+      SET_STATUS_Failure(VKI_EBADF);
+   else
+      PRE_MEM_WRITE("timerfd_gettime(result)",
+                    ARG2, sizeof(struct vki_itimerspec));
+}
+POST(sys_timerfd_gettime)
+{
+   if (RES == 0)
+      POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerspec));
+}
+
+PRE(sys_timerfd_settime)
+{
+   PRINT("sys_timerfd_settime ( %d, %d, %p, %p )", ARG1, ARG2, ARG3, ARG4);
+   PRE_REG_READ4(long, "timerfd_settime",
+                 int, ufd,
+                 int, flags,
+                 const struct vki_itimerspec*, utmr,
+                 struct vki_itimerspec*, otmr);
+   if (!ML_(fd_allowed)(ARG1, "timerfd_settime", tid, False))
+      SET_STATUS_Failure(VKI_EBADF);
+   else
+   {
+      PRE_MEM_READ("timerfd_settime(result)",
+                   ARG3, sizeof(struct vki_itimerspec));
+      if (ARG4)
+      {
+         PRE_MEM_WRITE("timerfd_settime(result)",
+                       ARG4, sizeof(struct vki_itimerspec));
+      }
+   }
+}
+POST(sys_timerfd_settime)
+{
+   if (RES == 0 && ARG4 != 0)
+      POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec));
+}
+
 /* ---------------------------------------------------------------------
    capabilities wrappers
    ------------------------------------------------------------------ */
@@ -2220,6 +2375,27 @@ POST(sys_sigprocmask)
 }
 #endif
 
+PRE(sys_signalfd)
+{
+   PRINT("sys_signalfd ( %d, %p, %llu )", (Int)ARG1, ARG2, (ULong) ARG3);
+   PRE_REG_READ3(long, "sys_signalfd",
+                 int, fd, vki_sigset_t *, sigmask, vki_size_t, sigsetsize);
+   PRE_MEM_READ( "signalfd(sigmask)", ARG2, sizeof(vki_sigset_t) );
+   if ((int)ARG1 != -1 && !ML_(fd_allowed)(ARG1, "signalfd", tid, False))
+      SET_STATUS_Failure( VKI_EBADF );
+}
+POST(sys_signalfd)
+{
+   if (!ML_(fd_allowed)(RES, "signalfd", tid, True)) {
+      VG_(close)(RES);
+      SET_STATUS_Failure( VKI_EMFILE );
+   } else {
+      if (VG_(clo_track_fds))
+         ML_(record_fd_open_nameless) (tid, RES);
+   }
+}
+
+
 /* ---------------------------------------------------------------------
    rt_sig* wrappers
    ------------------------------------------------------------------ */
@@ -2540,9 +2716,21 @@ PRE(sys_futimesat)
    PRINT("sys_futimesat ( %d, %p(%s), %p )", ARG1,ARG2,ARG2,ARG3);
    PRE_REG_READ3(long, "futimesat",
                  int, dfd, char *, filename, struct timeval *, tvp);
-   PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 );
+   if (ARG2 != 0)
+      PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 );
+   if (ARG3 != 0)
+      PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) );
+}
+
+PRE(sys_utimensat)
+{
+   PRINT("sys_utimensat ( %d, %p(%s), %p, 0x%x )", ARG1,ARG2,ARG2,ARG3,ARG4);
+   PRE_REG_READ4(long, "utimensat",
+                 int, dfd, char *, filename, struct timespec *, utimes, int, flags);
+   if (ARG2 != 0)
+      PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2 );
    if (ARG3 != 0)
-      PRE_MEM_READ( "futimesat(tvp)", ARG3, sizeof(struct vki_timeval) );
+      PRE_MEM_READ( "utimensat(tvp)", ARG3, 2 * sizeof(struct vki_timespec) );
 }
 
 PRE(sys_newfstatat)
@@ -2823,19 +3011,6 @@ PRE(sys_ioprio_set)
    PRE_REG_READ3(int, "ioprio_set", int, which, int, who, int, ioprio);
 }
 
-
-/* XXX I don't think this is really the right place for this.
-   Move it elsewhere in this file? */
-PRE(sys_utimensat)
-{
-   PRINT("sys_utimensat ( %d, %p(%s), %p )", ARG1,ARG2,ARG2,ARG3);
-   PRE_REG_READ3(long, "utimensat",
-                 int, dfd, char *, filename, struct timespec *, tvp);
-   PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2 );
-   if (ARG3 != 0)
-      PRE_MEM_READ( "utimensat(tvp)", ARG3, sizeof(struct vki_timespec) );
-}
-
 #undef PRE
 #undef POST
 
index af80c110dc3da7f680d4f2f67fd3050cdac26ade..02c9e2db3a1f9f5a407654ee3968255b4aa956e6 100644 (file)
@@ -1820,6 +1820,18 @@ const SyscallTableEntry ML_(syscall_table)[] = {
    LINX_(__NR_faccessat,         sys_faccessat),         // 298
    LINX_(__NR_set_robust_list,   sys_set_robust_list),   // 299
    LINXY(__NR_get_robust_list,   sys_get_robust_list),   // 300
+//   LINX_(__NR_move_pages,        sys_ni_syscall),        // 301
+//   LINX_(__NR_getcpu,            sys_ni_syscall),        // 302
+   LINXY(__NR_epoll_pwait,       sys_epoll_pwait),       // 303
+   LINX_(__NR_utimensat,         sys_utimensat),         // 304
+   LINXY(__NR_signalfd,          sys_signalfd),          // 305
+   LINXY(__NR_timerfd_create,    sys_timerfd_create),    // 306
+   LINX_(__NR_eventfd,           sys_eventfd),           // 307
+//   LINX_(__NR_sync_file_range2,   sys_ni_syscall),       // 308
+//   LINX_(__NR_fallocate,        sys_ni_syscall),         // 309
+//   LINXY(__NR_subpage_prot,       sys_ni_syscall),       // 310
+   LINXY(__NR_timerfd_settime,   sys_timerfd_settime),  // 311
+   LINXY(__NR_timerfd_gettime,   sys_timerfd_gettime),  // 312
 };
 
 const UInt ML_(syscall_table_size) = 
index 04ce86e48ca3dcfe17dc4e032710aae75d6cbe5a..ee3be1c92586f0305775fc6c51e56e2f87a27500 100644 (file)
@@ -1475,7 +1475,18 @@ const SyscallTableEntry ML_(syscall_table)[] = {
    LINX_(__NR_faccessat,         sys_faccessat),          // 298
    LINX_(__NR_set_robust_list,   sys_set_robust_list),    // 299
    LINXY(__NR_get_robust_list,   sys_get_robust_list),    // 300
-
+//   LINX_(__NR_move_pages,        sys_ni_syscall),        // 301
+//   LINX_(__NR_getcpu,            sys_ni_syscall),        // 302
+   LINXY(__NR_epoll_pwait,       sys_epoll_pwait),       // 303
+   LINX_(__NR_utimensat,         sys_utimensat),         // 304
+   LINXY(__NR_signalfd,          sys_signalfd),          // 305
+   LINXY(__NR_timerfd_create,    sys_timerfd_create),    // 306
+   LINX_(__NR_eventfd,           sys_eventfd),           // 307
+//   LINX_(__NR_sync_file_range2,   sys_ni_syscall),       // 308
+//   LINX_(__NR_fallocate,        sys_ni_syscall),         // 309
+//   LINXY(__NR_subpage_prot,       sys_ni_syscall),       // 310
+   LINXY(__NR_timerfd_settime,   sys_timerfd_settime),  // 311
+   LINXY(__NR_timerfd_gettime,   sys_timerfd_gettime),  // 312
 };
 
 const UInt ML_(syscall_table_size) = 
index 24fa29f2fe82d22f805aa261cc60be0c487e4b43..6015b81396364694e379b7b6c40ec9a9917bc4cb 100644 (file)
@@ -2221,9 +2221,15 @@ const SyscallTableEntry ML_(syscall_table)[] = {
 //   LINX_(__NR_vmsplice,          sys_ni_syscall),       // 316
 //   LINX_(__NR_move_pages,        sys_ni_syscall),       // 317
 //   LINX_(__NR_getcpu,            sys_ni_syscall),       // 318
-//   LINX_(__NR_epoll_pwait,       sys_ni_syscall),       // 319
+   LINXY(__NR_epoll_pwait,       sys_epoll_pwait),      // 319
 
    LINX_(__NR_utimensat,         sys_utimensat),        // 320
+   LINXY(__NR_signalfd,          sys_signalfd),         // 321
+   LINXY(__NR_timerfd_create,    sys_timerfd_create),   // 322
+   LINX_(__NR_eventfd,           sys_eventfd),          // 323
+//   LINX_(__NR_fallocate,        sys_ni_syscall),        // 324
+   LINXY(__NR_timerfd_settime,   sys_timerfd_settime),  // 325
+   LINXY(__NR_timerfd_gettime,   sys_timerfd_gettime),  // 326
 };
 
 const UInt ML_(syscall_table_size) = 
index a2fcdf755f16ec024de5f7d6f715366760f5af19..f382bea7541adc3e45b6a355b5f582abfc42cbc2 100644 (file)
 #define __NR_utimensat         280
 #define __NR_epoll_pwait       281
 #define __NR_signalfd          282
-#define __NR_timerfd           283
+#define __NR_timerfd_create    283
 #define __NR_eventfd           284
 #define __NR_fallocate         285
+#define __NR_timerfd_settime   286
+#define __NR_timerfd_gettime   287
 
 #endif /* __VKI_SCNUMS_AMD64_LINUX_H */
 
index 4207b2be611742bb6b3abb76e687b1f3ef46be5f..08543cc747573a30e9888b598ec3c988f968f935 100644 (file)
 #define __NR_epoll_pwait       303
 #define __NR_utimensat         304
 #define __NR_signalfd          305
-#define __NR_timerfd           306
+#define __NR_timerfd_create    306
 #define __NR_eventfd           307
 #define __NR_sync_file_range2  308
 #define __NR_fallocate         309
-
-#define __NR_syscalls          310
+#define __NR_subpage_prot      310
+#define __NR_timerfd_settime   311
+#define __NR_timerfd_gettime   312
 
 #endif /* __VKI_SCNUMS_PPC32_LINUX_H */
 
index 50467ed321dc36ab5abd21fb259704ccac0e56e0..236170dd533b6ff5db5dbc9f1c0f4295b32f1e40 100644 (file)
 #define __NR_epoll_pwait       303
 #define __NR_utimensat         304
 #define __NR_signalfd          305
-#define __NR_timerfd           306
+#define __NR_timerfd_create    306
 #define __NR_eventfd           307
 #define __NR_sync_file_range2  308
 #define __NR_fallocate         309
+#define __NR_subpage_prot      310
+#define __NR_timerfd_settime   311
+#define __NR_timerfd_gettime   312
 
 #endif /* __VKI_SCNUMS_PPC64_LINUX_H */
 
index c7d15f61e7bc363f88f954be3007d912184d4f87..40af252b3fb6e27d68508180e9c043da46d78591 100644 (file)
 #define __NR_epoll_pwait       319
 #define __NR_utimensat         320
 #define __NR_signalfd          321
-#define __NR_timerfd           322
+#define __NR_timerfd_create    322
 #define __NR_eventfd           323
 #define __NR_fallocate         324
+#define __NR_timerfd_settime   325
+#define __NR_timerfd_gettime   326
 
 #endif /* __VKI_SCNUMS_X86_LINUX_H */