[compiler-rt] r324120 - Add new NetBSD interceptors: devname(3), devname_r(3)
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 2 10:45:33 PST 2018
Author: kamil
Date: Fri Feb 2 10:45:33 2018
New Revision: 324120
URL: http://llvm.org/viewvc/llvm-project?rev=324120&view=rev
Log:
Add new NetBSD interceptors: devname(3), devname_r(3)
Summary:
devname, devname_r - get device name
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, vitalybuka
Reviewed By: vitalybuka
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D42053
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname.cc
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname_r.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=324120&r1=324119&r2=324120&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Feb 2 10:45:33 2018
@@ -6758,6 +6758,36 @@ INTERCEPTOR(SIZE_T, strlcat, char *dst,
#define INIT_STRLCPY
#endif
+#if SANITIZER_INTERCEPT_DEVNAME
+INTERCEPTOR(char *, devname, u64 dev, u32 type) {
+ void *ctx;
+ char *name;
+ COMMON_INTERCEPTOR_ENTER(ctx, devname, dev, type);
+ name = REAL(devname)(dev, type);
+ if (name)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ return name;
+}
+#define INIT_DEVNAME COMMON_INTERCEPT_FUNCTION(devname);
+#else
+#define INIT_DEVNAME
+#endif
+
+#if SANITIZER_INTERCEPT_DEVNAME_R
+INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
+ void *ctx;
+ int res;
+ COMMON_INTERCEPTOR_ENTER(ctx, devname_r, dev, type, path, len);
+ res = REAL(devname_r)(dev, type, path, len);
+ if (!res)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, path, REAL(strlen)(path) + 1);
+ return res;
+}
+#define INIT_DEVNAME_R COMMON_INTERCEPT_FUNCTION(devname_r);
+#else
+#define INIT_DEVNAME_R
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -6983,6 +7013,8 @@ static void InitializeCommonInterceptors
INIT_NAME_TO_HANDLE_AT;
INIT_OPEN_BY_HANDLE_AT;
INIT_STRLCPY;
+ INIT_DEVNAME;
+ INIT_DEVNAME_R;
#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=324120&r1=324119&r2=324120&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Feb 2 10:45:33 2018
@@ -456,4 +456,7 @@
#define SANITIZER_INTERCEPT_READLINKAT \
(SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10)
+#define SANITIZER_INTERCEPT_DEVNAME SI_NETBSD
+#define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD
+
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname.cc?rev=324120&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname.cc Fri Feb 2 10:45:33 2018
@@ -0,0 +1,22 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+int main(void) {
+ struct stat st;
+ char *name;
+
+ if (stat("/dev/null", &st))
+ exit(1);
+
+ if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
+ exit(1);
+
+ printf("%s\n", name);
+
+ // CHECK: null
+
+ return 0;
+}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname_r.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname_r.cc?rev=324120&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname_r.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/devname_r.cc Fri Feb 2 10:45:33 2018
@@ -0,0 +1,27 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck
+
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ struct stat st;
+ char name[10];
+ mode_t type;
+
+ if (stat("/dev/null", &st))
+ exit(1);
+
+ type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
+
+ if (devname_r(st.st_rdev, type, name, __arraycount(name)))
+ exit(1);
+
+ printf("%s\n", name);
+
+ // CHECK: null
+
+ return 0;
+}
More information about the llvm-commits
mailing list