[PATCH] D56158: [sanitizer_common] Implement funopen*() interceptors for NetBSD

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 29 15:17:19 PST 2018


mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D56158

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -549,5 +549,7 @@
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
+#define SANITIZER_INTERCEPT_FUNOPEN SI_NETBSD
+#define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9133,6 +9133,45 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie,
+            int (*readfn)(void *cookie, char *buf, int len),
+            int (*writefn)(void *cookie, const char *buf, int len),
+            OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+            int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+                           seekfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen)(cookie, readfn, writefn, seekfn,
+                                        closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+INTERCEPTOR(__sanitizer_FILE *, funopen2, void *cookie,
+            SSIZE_T (*readfn)(void *cookie, void *buf, SIZE_T len),
+            SSIZE_T (*writefn)(void *cookie, const void *buf, SIZE_T len),
+            OFF_T (*seekfn)(void *cookie, OFF_T pos, int whence),
+            int (*flushfn)(void *cookie),
+            int (*closefn)(void *cookie)) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen2, cookie, readfn, writefn,
+                           seekfn, flushfn, closefn);
+  __sanitizer_FILE *res = REAL(funopen2)(cookie, readfn, writefn, seekfn,
+                                         flushfn, closefn);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN2 COMMON_INTERCEPT_FUNCTION(funopen2)
+#else
+#define INIT_FUNOPEN2
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9416,6 +9455,8 @@
   INIT_POPEN;
   INIT_POPENVE;
   INIT_PCLOSE;
+  INIT_FUNOPEN;
+  INIT_FUNOPEN2;
 
   INIT___PRINTF_CHK;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56158.179714.patch
Type: text/x-patch
Size: 2679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181229/18cf4f1d/attachment.bin>


More information about the llvm-commits mailing list