[compiler-rt] r325588 - Add new interceptor: strmode(3)
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 07:53:30 PST 2018
Author: kamil
Date: Tue Feb 20 07:53:30 2018
New Revision: 325588
URL: http://llvm.org/viewvc/llvm-project?rev=325588&view=rev
Log:
Add new interceptor: strmode(3)
Summary:
strmode - convert inode status information into a symbolic string
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, vitalybuka
Reviewed By: vitalybuka
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D43485
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/strmode.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=325588&r1=325587&r2=325588&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Feb 20 07:53:30 2018
@@ -6823,6 +6823,19 @@ INTERCEPTOR(char *, fgetln, __sanitizer_
#define INIT_FGETLN
#endif
+#if SANITIZER_INTERCEPT_STRMODE
+INTERCEPTOR(void, strmode, u32 mode, char *bp) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, strmode, mode, bp);
+ REAL(strmode)(mode, bp);
+ if (bp)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, bp, REAL(strlen)(bp) + 1);
+}
+#define INIT_STRMODE COMMON_INTERCEPT_FUNCTION(strmode)
+#else
+#define INIT_STRMODE
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7052,6 +7065,7 @@ static void InitializeCommonInterceptors
INIT_DEVNAME;
INIT_DEVNAME_R;
INIT_FGETLN;
+ INIT_STRMODE;
#if SANITIZER_NETBSD
COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=325588&r1=325587&r2=325588&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Feb 20 07:53:30 2018
@@ -460,5 +460,6 @@
#define SANITIZER_INTERCEPT_DEVNAME SI_NETBSD
#define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD
#define SANITIZER_INTERCEPT_FGETLN SI_NETBSD
+#define SANITIZER_INTERCEPT_STRMODE SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/strmode.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/strmode.cc?rev=325588&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/strmode.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/strmode.cc Tue Feb 20 07:53:30 2018
@@ -0,0 +1,20 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int main(void) {
+ struct stat st;
+ char modep[15];
+
+ if (stat("/etc/hosts", &st))
+ exit(1);
+
+ strmode(st.st_mode, modep);
+
+ printf("%s\n", modep);
+
+ return 0;
+}
More information about the llvm-commits
mailing list