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

2019-01-02 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350233: [sanitizer_common] Implement funopen*() interceptors 
for NetBSD (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56158?vs=179728=179873#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -551,5 +551,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: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9187,6 +9187,166 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedFunopenCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_funopen_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_funopen_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_funopen_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_funopen_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn, seekfn,
+   closefn);
+
+  WrappedFunopenCookie *wrapped_cookie =
+  (WrappedFunopenCookie *)InternalAlloc(sizeof(WrappedFunopenCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res =
+  REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_funopen_read  : nullptr,
+writefn ? wrapped_funopen_write : nullptr,
+seekfn  ? wrapped_funopen_seek  : nullptr,
+closefn ? wrapped_funopen_close : nullptr);
+  if (res)
+unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedFunopen2Cookie {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+

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

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179728.
mgorny added a comment.

Renamed stuff as requested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

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,166 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedFunopenCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_funopen_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_funopen_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_funopen_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_funopen_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedFunopenCookie *wrapped_cookie = (WrappedFunopenCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn, seekfn,
+   closefn);
+
+  WrappedFunopenCookie *wrapped_cookie =
+  (WrappedFunopenCookie *)InternalAlloc(sizeof(WrappedFunopenCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res =
+  REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_funopen_read  : nullptr,
+writefn ? wrapped_funopen_write : nullptr,
+seekfn  ? wrapped_funopen_seek  : nullptr,
+closefn ? wrapped_funopen_close : nullptr);
+  if (res)
+unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedFunopen2Cookie {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T wrapped_funopen2_read(void *cookie, void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedFunopen2Cookie *wrapped_cookie = (WrappedFunopen2Cookie *)cookie;
+  funopen2_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static SSIZE_T wrapped_funopen2_write(void *cookie, const void *buf,
+   

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

2018-12-30 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:9150
+
+static int wrapped_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);

How about `wrapped_funopen_read` etc? It won't clash with future potential 
inteceptors with so generic names.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-12-30 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:9142
+
+struct WrappedCookie {
+  void *real_cookie;

I would call it WrappedFunopenCookie to be less generic, similarly for funopen2.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179723.
mgorny added a comment.

Fixed accidental whitespace change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

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,161 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+
+  WrappedCookie *wrapped_cookie =
+  (WrappedCookie *)InternalAlloc(sizeof(WrappedCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res = REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_read  : nullptr,
+writefn ? wrapped_write : nullptr,
+seekfn  ? wrapped_seek  : nullptr,
+closefn ? wrapped_close : nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedCookie2 {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T wrapped_read2(void *cookie, void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie2 *wrapped_cookie = (WrappedCookie2 *)cookie;
+  funopen2_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static SSIZE_T wrapped_write2(void *cookie, const void *buf, SIZE_T len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie2 *wrapped_cookie = (WrappedCookie2 

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

2018-12-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 179722.
mgorny added a comment.

Implemented wrappers as requested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158

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

Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
===
--- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -2319,6 +2319,7 @@
   void *hash;
   uptr key_counter;
 };
+
 }  // namespace __sanitizer
 
 #define CHECK_TYPE_SIZE(TYPE) \
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,161 @@
 #define INIT_PCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_FUNOPEN
+typedef int (*funopen_readfn)(void *cookie, char *buf, int len);
+typedef int (*funopen_writefn)(void *cookie, const char *buf, int len);
+typedef OFF_T (*funopen_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen_closefn)(void *cookie);
+
+struct WrappedCookie {
+  void *real_cookie;
+  funopen_readfn real_read;
+  funopen_writefn real_write;
+  funopen_seekfn real_seek;
+  funopen_closefn real_close;
+};
+
+static int wrapped_read(void *cookie, char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_readfn real_read = wrapped_cookie->real_read;
+  return real_read(wrapped_cookie->real_cookie, buf, len);
+}
+
+static int wrapped_write(void *cookie, const char *buf, int len) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_writefn real_write = wrapped_cookie->real_write;
+  return real_write(wrapped_cookie->real_cookie, buf, len);
+}
+
+static OFF_T wrapped_seek(void *cookie, OFF_T offset, int whence) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_seekfn real_seek = wrapped_cookie->real_seek;
+  return real_seek(wrapped_cookie->real_cookie, offset, whence);
+}
+
+static int wrapped_close(void *cookie) {
+  COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
+  WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
+  funopen_closefn real_close = wrapped_cookie->real_close;
+  int res = real_close(wrapped_cookie->real_cookie);
+  InternalFree(wrapped_cookie);
+  return res;
+}
+
+INTERCEPTOR(__sanitizer_FILE *, funopen, void *cookie, funopen_readfn readfn,
+funopen_writefn writefn, funopen_seekfn seekfn,
+funopen_closefn closefn) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, funopen, cookie, readfn, writefn,
+   seekfn, closefn);
+
+  WrappedCookie *wrapped_cookie =
+  (WrappedCookie *)InternalAlloc(sizeof(WrappedCookie));
+  wrapped_cookie->real_cookie = cookie;
+  wrapped_cookie->real_read = readfn;
+  wrapped_cookie->real_write = writefn;
+  wrapped_cookie->real_seek = seekfn;
+  wrapped_cookie->real_close = closefn;
+
+  __sanitizer_FILE *res = REAL(funopen)(wrapped_cookie,
+readfn  ? wrapped_read  : nullptr,
+writefn ? wrapped_write : nullptr,
+seekfn  ? wrapped_seek  : nullptr,
+closefn ? wrapped_close : nullptr);
+  if (res) unpoison_file(res);
+  return res;
+}
+#define INIT_FUNOPEN COMMON_INTERCEPT_FUNCTION(funopen)
+#else
+#define INIT_FUNOPEN
+#endif
+
+#if SANITIZER_INTERCEPT_FUNOPEN2
+typedef SSIZE_T (*funopen2_readfn)(void *cookie, void *buf, SIZE_T len);
+typedef SSIZE_T (*funopen2_writefn)(void *cookie, const void *buf, SIZE_T len);
+typedef OFF_T (*funopen2_seekfn)(void *cookie, OFF_T offset, int whence);
+typedef int (*funopen2_flushfn)(void *cookie);
+typedef int (*funopen2_closefn)(void *cookie);
+
+struct WrappedCookie2 {
+  void *real_cookie;
+  funopen2_readfn real_read;
+  funopen2_writefn real_write;
+  funopen2_seekfn real_seek;
+  funopen2_flushfn real_flush;
+  funopen2_closefn real_close;
+};
+
+static SSIZE_T 

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

2018-12-29 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Shouldn't this follow SANITIZER_INTERCEPT_FOPENCOOKIE and implement a wrapper 
for operations?


Repository:
  rCRT Compiler Runtime

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56158/new/

https://reviews.llvm.org/D56158



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-12-29 Thread Michał Górny via Phabricator via cfe-commits
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;
 }


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)) {
+