Skip to content

Commit

Permalink
Interceptors for getchar interfaces: not usable yet
Browse files Browse the repository at this point in the history
  • Loading branch information
plusun committed Jun 9, 2018
1 parent c8f480d commit b33125f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8725,6 +8725,46 @@ SHA2_INTERCEPTORS(512, u64);
#define INIT_SHA2
#endif

#if SANITIZER_INTERCEPT_GETCHAR
INTERCEPTOR(int, fgetc, __sanitizer_FILE *stream) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, fgetc, stream);
return REAL(fgetc)(stream);
}
INTERCEPTOR(int, getc, __sanitizer_FILE *stream) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getc, stream);
return REAL(getc)(stream);
}

INTERCEPTOR(int, getchar) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getchar);
return REAL(getchar)();
}

INTERCEPTOR(int, getc_unlocked, __sanitizer_FILE *stream) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getc_unlocked, stream);
return REAL(getc_unlocked)(stream);
}

INTERCEPTOR(int, getchar_unlocked) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getchar_unlocked);
return REAL(getchar_unlocked)();
}

#define INIT_GETCHAR \
COMMON_INTERCEPT_FUNCTION(fgetc); \
COMMON_INTERCEPT_FUNCTION(getc); \
COMMON_INTERCEPT_FUNCTION(getchar); \
COMMON_INTERCEPT_FUNCTION(getc_unlocked); \
COMMON_INTERCEPT_FUNCTION(getchar_unlocked)
#else
#define INIT_GETCHAR
#endif

static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
Expand Down Expand Up @@ -8993,6 +9033,7 @@ static void InitializeCommonInterceptors() {
INIT_CDBR;
INIT_RMD160;
INIT_SHA2;
INIT_GETCHAR;

INIT___PRINTF_CHK;
}
1 change: 1 addition & 0 deletions lib/sanitizer_common/sanitizer_platform_interceptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,5 +529,6 @@
#define SANITIZER_INTERCEPT_CDBR SI_NETBSD
#define SANITIZER_INTERCEPT_RMD160 SI_NETBSD
#define SANITIZER_INTERCEPT_SHA2 SI_NETBSD
#define SANITIZER_INTERCEPT_GETCHAR SI_POSIX

#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

0 comments on commit b33125f

Please sign in to comment.