From: Tom Hughes Date: Tue, 27 Oct 2009 09:19:26 +0000 (+0000) Subject: Add support for the perf_counter_open system call. Fixes #211498. X-Git-Tag: svn/VALGRIND_3_6_0~502 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=141ec942a1cc1fcb1f97bfb0d8ee727adc2d2979;p=thirdparty%2Fvalgrind.git Add support for the perf_counter_open system call. Fixes #211498. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10907 --- diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h index fed3ba6e19..ce48a929a0 100644 --- a/coregrind/m_syswrap/priv_syswrap-linux.h +++ b/coregrind/m_syswrap/priv_syswrap-linux.h @@ -47,6 +47,7 @@ extern SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags, DECL_TEMPLATE(linux, sys_mount); DECL_TEMPLATE(linux, sys_oldumount); DECL_TEMPLATE(linux, sys_umount); +DECL_TEMPLATE(linux, sys_perf_counter_open); // POSIX, but various sub-cases differ between Linux and Darwin. DECL_TEMPLATE(linux, sys_fcntl); diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c index 1e405c117e..3918890121 100644 --- a/coregrind/m_syswrap/syswrap-amd64-linux.c +++ b/coregrind/m_syswrap/syswrap-amd64-linux.c @@ -1374,13 +1374,13 @@ const SyscallTableEntry ML_(syscall_table)[] = { LINX_(__NR_eventfd2, sys_eventfd2), // 290 LINXY(__NR_epoll_create1, sys_epoll_create1), // 291 // (__NR_dup3, sys_ni_syscall) // 292 - LINXY(__NR_pipe2, sys_pipe2) // 293 + LINXY(__NR_pipe2, sys_pipe2), // 293 // (__NR_inotify_init1, sys_ni_syscall) // 294 // (__NR_preadv, sys_ni_syscall) // 295 // (__NR_pwritev, sys_ni_syscall) // 296 // (__NR_rt_tgsigqueueinfo, sys_ni_syscall) // 297 - // (__NR_perf_counter_open, sys_ni_syscall) // 298 + LINXY(__NR_perf_counter_open, sys_perf_counter_open) // 298 }; const UInt ML_(syscall_table_size) = diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 7f81262fad..7a2e70862a 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -2392,6 +2392,30 @@ PRE(sys_stime) PRE_MEM_READ( "stime(t)", ARG1, sizeof(vki_time_t) ); } +PRE(sys_perf_counter_open) +{ + PRINT("sys_perf_counter_open ( %#lx, %ld, %ld, %ld, %ld )", + ARG1,ARG2,ARG3,ARG4,ARG5); + PRE_REG_READ5(long, "perf_counter_open", + struct vki_perf_counter_attr *, attr, + vki_pid_t, pid, int, cpu, int, group_fd, + unsigned long, flags); + PRE_MEM_READ( "perf_counter_open(attr)", + ARG1, sizeof(struct vki_perf_counter_attr) ); +} + +POST(sys_perf_counter_open) +{ + vg_assert(SUCCESS); + if (!ML_(fd_allowed)(RES, "perf_counter_open", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_nameless)(tid, RES); + } +} + /* --------------------------------------------------------------------- utime wrapper ------------------------------------------------------------------ */ diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c index d4f15c7beb..d62febd4b7 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c @@ -1866,9 +1866,9 @@ const SyscallTableEntry ML_(syscall_table)[] = { LINX_(__NR_eventfd2, sys_eventfd2), // 314 LINXY(__NR_epoll_create1, sys_epoll_create1), // 315 // (__NR_dup3, sys_ni_syscall) // 316 - LINXY(__NR_pipe2, sys_pipe2) // 317 + LINXY(__NR_pipe2, sys_pipe2), // 317 // (__NR_inotify_init1, sys_ni_syscall) // 318 - // (__NR_perf_counter_open, sys_ni_syscall) // 319 + LINXY(__NR_perf_counter_open, sys_perf_counter_open) // 319 // (__NR_preadv, sys_ni_syscall) // 320 // (__NR_pwritev, sys_ni_syscall) // 321 // (__NR_rt_tgsigqueueinfo, sys_ni_syscall) // 322 diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c index bfb930159d..2f93880982 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c @@ -1506,9 +1506,9 @@ const SyscallTableEntry ML_(syscall_table)[] = { LINX_(__NR_eventfd2, sys_eventfd2), // 314 LINXY(__NR_epoll_create1, sys_epoll_create1), // 315 // (__NR_dup3, sys_ni_syscall) // 316 - LINXY(__NR_pipe2, sys_pipe2) // 317 + LINXY(__NR_pipe2, sys_pipe2), // 317 // (__NR_inotify_init1, sys_ni_syscall) // 318 - // (__NR_perf_counter_open, sys_ni_syscall) // 319 + LINXY(__NR_perf_counter_open, sys_perf_counter_open) // 319 // (__NR_preadv, sys_ni_syscall) // 320 // (__NR_pwritev, sys_ni_syscall) // 321 // (__NR_rt_tgsigqueueinfo, sys_ni_syscall) // 322 diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 57720dd126..ea9edc2c13 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -2253,13 +2253,13 @@ const SyscallTableEntry ML_(syscall_table)[] = { LINXY(__NR_epoll_create1, sys_epoll_create1), // 329 // (__NR_dup3, sys_ni_syscall) // 330 - LINXY(__NR_pipe2, sys_pipe2) // 331 + LINXY(__NR_pipe2, sys_pipe2), // 331 // (__NR_inotify_init1, sys_ni_syscall) // 332 // (__NR_preadv, sys_ni_syscall) // 333 // (__NR_pwritev, sys_ni_syscall) // 334 // (__NR_rt_tgsigqueueinfo, sys_ni_syscall) // 335 - // (__NR_perf_counter_open, sys_ni_syscall) // 336 + LINXY(__NR_perf_counter_open, sys_perf_counter_open) // 336 }; const UInt ML_(syscall_table_size) = diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index 90bffe6b7b..93d4ae6721 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -2570,6 +2570,57 @@ struct vki_iwreq union vki_iwreq_data u; }; +/*--------------------------------------------------------------------*/ +// From linux-2.6.31.5/include/linux/perf_counter.h +/*--------------------------------------------------------------------*/ + +struct vki_perf_counter_attr { + + /* + * Major type: hardware/software/tracepoint/etc. + */ + __vki_u32 type; + + /* + * Size of the attr structure, for fwd/bwd compat. + */ + __vki_u32 size; + + /* + * Type specific configuration information. + */ + __vki_u64 config; + + union { + __vki_u64 sample_period; + __vki_u64 sample_freq; + }; + + __vki_u64 sample_type; + __vki_u64 read_format; + + __vki_u64 disabled : 1, /* off by default */ + inherit : 1, /* children inherit it */ + pinned : 1, /* must always be on PMU */ + exclusive : 1, /* only group on PMU */ + exclude_user : 1, /* don't count user */ + exclude_kernel : 1, /* ditto kernel */ + exclude_hv : 1, /* ditto hypervisor */ + exclude_idle : 1, /* don't count when idle */ + mmap : 1, /* include mmap data */ + comm : 1, /* include comm data */ + freq : 1, /* use freq, not period */ + inherit_stat : 1, /* per task counts */ + enable_on_exec : 1, /* next exec enables */ + task : 1, /* trace fork/exit */ + + __reserved_1 : 50; + + __vki_u32 wakeup_events; /* wakeup every n events */ + __vki_u32 __reserved_2; + + __vki_u64 __reserved_3; +}; #endif // __VKI_LINUX_H