[compiler-rt] r348654 - Add a new interceptor for fparseln(3) from NetBSD
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 7 13:50:44 PST 2018
Author: kamil
Date: Fri Dec 7 13:50:44 2018
New Revision: 348654
URL: http://llvm.org/viewvc/llvm-project?rev=348654&view=rev
Log:
Add a new interceptor for fparseln(3) from NetBSD
Summary:
fparseln - returns the next logical line from a stream.
Add a dedicated test for this API.
Reviewers: vitalybuka, joerg
Reviewed By: vitalybuka
Subscribers: kubamracek, mgorny, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D55019
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/fparseln.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=348654&r1=348653&r2=348654&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Dec 7 13:50:44 2018
@@ -7752,6 +7752,30 @@ INTERCEPTOR(long long, strtonum, const c
#define INIT_STRTONUM
#endif
+#if SANITIZER_INTERCEPT_FPARSELN
+INTERCEPTOR(char *, fparseln, __sanitizer_FILE *stream, SIZE_T *len,
+ SIZE_T *lineno, const char delim[3], int flags) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, fparseln, stream, len, lineno, delim, flags);
+ if (lineno)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, lineno, sizeof(*lineno));
+ if (delim)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, delim, sizeof(delim[0]) * 3);
+ char *ret = REAL(fparseln)(stream, len, lineno, delim, flags);
+ if (ret) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, REAL(strlen)(ret) + 1);
+ if (len)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, len, sizeof(*len));
+ if (lineno)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lineno, sizeof(*lineno));
+ }
+ return ret;
+}
+#define INIT_FPARSELN COMMON_INTERCEPT_FUNCTION(fparseln)
+#else
+#define INIT_FPARSELN
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -8017,6 +8041,7 @@ static void InitializeCommonInterceptors
INIT_NL_LANGINFO;
INIT_MODCTL;
INIT_STRTONUM;
+ INIT_FPARSELN;
INIT___PRINTF_CHK;
}
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=348654&r1=348653&r2=348654&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Dec 7 13:50:44 2018
@@ -530,5 +530,6 @@
#define SANITIZER_INTERCEPT_NL_LANGINFO (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_MODCTL SI_NETBSD
#define SANITIZER_INTERCEPT_STRTONUM SI_NETBSD
+#define SANITIZER_INTERCEPT_FPARSELN SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/fparseln.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/fparseln.cc?rev=348654&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/fparseln.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/fparseln.cc Fri Dec 7 13:50:44 2018
@@ -0,0 +1,25 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ printf("fparseln\n");
+
+ FILE *fp = fopen("/etc/fstab", "r");
+ assert(fp);
+
+ int flags = FPARSELN_UNESCALL;
+ const char *delim = "\\\\#";
+ size_t lineno = 0, len;
+ char *line;
+ while ((line = fparseln(fp, &len, &lineno, delim, flags))) {
+ printf("lineno: %zu, length: %zu, line: %s\n", lineno, len, line);
+ free(line);
+ }
+
+ // CHECK: fparseln
+
+ return 0;
+}
More information about the llvm-commits
mailing list