mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
[sanitizer] Intercept times.
llvm-svn: 195918
This commit is contained in:
20
compiler-rt/lib/msan/lit_tests/times.cc
Normal file
20
compiler-rt/lib/msan/lit_tests/times.cc
Normal file
@@ -0,0 +1,20 @@
|
||||
// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
int main(void) {
|
||||
struct tms t;
|
||||
clock_t res = times(&t);
|
||||
assert(res != (clock_t)-1);
|
||||
|
||||
if (t.tms_utime) printf("1\n");
|
||||
if (t.tms_stime) printf("2\n");
|
||||
if (t.tms_cutime) printf("3\n");
|
||||
if (t.tms_cstime) printf("4\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2878,6 +2878,20 @@ INTERCEPTOR(SIZE_T, iconv, void *cd, char **inbuf, SIZE_T *inbytesleft,
|
||||
#define INIT_ICONV
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_TIMES
|
||||
INTERCEPTOR(__sanitizer_clock_t, times, void *tms) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, times, tms);
|
||||
__sanitizer_clock_t res = REAL(times)(tms);
|
||||
if (res != (__sanitizer_clock_t)-1 && tms)
|
||||
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tms, struct_tms_sz);
|
||||
return res;
|
||||
}
|
||||
#define INIT_TIMES COMMON_INTERCEPT_FUNCTION(times);
|
||||
#else
|
||||
#define INIT_TIMES
|
||||
#endif
|
||||
|
||||
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
|
||||
INIT_STRCMP; \
|
||||
INIT_STRNCMP; \
|
||||
@@ -2989,4 +3003,5 @@ INTERCEPTOR(SIZE_T, iconv, void *cd, char **inbuf, SIZE_T *inbytesleft,
|
||||
INIT_DRAND48_R; \
|
||||
INIT_GETLINE; \
|
||||
INIT_ICONV; \
|
||||
INIT_TIMES; \
|
||||
/**/
|
||||
|
||||
@@ -159,6 +159,7 @@
|
||||
# define SANITIZER_INTERCEPT_LGAMMA_R SI_LINUX
|
||||
# define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID
|
||||
# define SANITIZER_INTERCEPT_ICONV SI_MAC || SI_LINUX_NOT_ANDROID
|
||||
# define SANITIZER_INTERCEPT_TIMES SI_NOT_WINDOWS
|
||||
|
||||
// FIXME: getline seems to be available on OSX 10.7
|
||||
# define SANITIZER_INTERCEPT_GETLINE SI_LINUX_NOT_ANDROID
|
||||
|
||||
@@ -939,4 +939,6 @@ CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid);
|
||||
CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
|
||||
#endif
|
||||
|
||||
CHECK_TYPE_SIZE(clock_t);
|
||||
|
||||
#endif // SANITIZER_LINUX || SANITIZER_MAC
|
||||
|
||||
@@ -287,6 +287,8 @@ namespace __sanitizer {
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef long __sanitizer_clock_t;
|
||||
|
||||
#if SANITIZER_LINUX
|
||||
#if defined(_LP64) || defined(__x86_64__)
|
||||
typedef unsigned __sanitizer___kernel_uid_t;
|
||||
|
||||
@@ -417,6 +417,7 @@ void StatOutput(u64 *stat) {
|
||||
name[StatInt_getline] = " getline ";
|
||||
name[StatInt_getdelim] = " getdelim ";
|
||||
name[StatInt_iconv] = " iconv ";
|
||||
name[StatInt_times] = " times ";
|
||||
|
||||
name[StatInt_pthread_attr_getdetachstate] = " pthread_addr_getdetachstate "; // NOLINT
|
||||
name[StatInt_pthread_attr_getguardsize] = " pthread_addr_getguardsize "; // NOLINT
|
||||
|
||||
@@ -412,6 +412,7 @@ enum StatType {
|
||||
StatInt_getline,
|
||||
StatInt_getdelim,
|
||||
StatInt_iconv,
|
||||
StatInt_times,
|
||||
|
||||
StatInt_pthread_attr_getdetachstate,
|
||||
StatInt_pthread_attr_getguardsize,
|
||||
|
||||
Reference in New Issue
Block a user