summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2018-12-22 11:17:27 +0000
committerDavid Carlier <devnexen@gmail.com>2018-12-22 11:17:27 +0000
commit58d38230867528b2cc376a99c2147c89c7af6fcb (patch)
treeb5a864e4552454fd7d5b4289fc7ad340a29ac3c0
parenta70184ba92b8bdbb27d16321a656353abf955b82 (diff)
downloadbcm5719-llvm-58d38230867528b2cc376a99c2147c89c7af6fcb.tar.gz
bcm5719-llvm-58d38230867528b2cc376a99c2147c89c7af6fcb.zip
[Sanitizer] Enable POSIX regex api on FreeBSD.
Reviewers: krytarowski Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D56009 M lib/sanitizer_common/sanitizer_common_interceptors.inc M lib/sanitizer_common/sanitizer_platform_interceptors.h M lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc M lib/sanitizer_common/sanitizer_platform_limits_freebsd.h D test/sanitizer_common/TestCases/NetBSD/regex.cc A + test/sanitizer_common/TestCases/Posix/regex.cc llvm-svn: 350002
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc20
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h2
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc (renamed from compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc)42
5 files changed, 27 insertions, 43 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index ff378e1e93b..1f446febac2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7421,6 +7421,16 @@ INTERCEPTOR(void, regfree, const void *preg) {
COMMON_INTERCEPTOR_READ_RANGE(ctx, preg, struct_regex_sz);
REAL(regfree)(preg);
}
+#define INIT_REGEX \
+ COMMON_INTERCEPT_FUNCTION(regcomp); \
+ COMMON_INTERCEPT_FUNCTION(regexec); \
+ COMMON_INTERCEPT_FUNCTION(regerror); \
+ COMMON_INTERCEPT_FUNCTION(regfree);
+#else
+#define INIT_REGEX
+#endif
+
+#if SANITIZER_INTERCEPT_REGEXSUB
INTERCEPTOR(SSIZE_T, regnsub, char *buf, SIZE_T bufsiz, const char *sub,
const struct __sanitizer_regmatch *rm, const char *str) {
void *ctx;
@@ -7455,15 +7465,12 @@ INTERCEPTOR(SSIZE_T, regasub, char **buf, const char *sub,
}
return res;
}
-#define INIT_REGEX \
- COMMON_INTERCEPT_FUNCTION(regcomp); \
- COMMON_INTERCEPT_FUNCTION(regexec); \
- COMMON_INTERCEPT_FUNCTION(regerror); \
- COMMON_INTERCEPT_FUNCTION(regfree); \
+
+#define INIT_REGEXSUB \
COMMON_INTERCEPT_FUNCTION(regnsub); \
COMMON_INTERCEPT_FUNCTION(regasub);
#else
-#define INIT_REGEX
+#define INIT_REGEXSUB
#endif
#if SANITIZER_INTERCEPT_FTS
@@ -9297,6 +9304,7 @@ static void InitializeCommonInterceptors() {
INIT_SETVBUF;
INIT_GETVFSSTAT;
INIT_REGEX;
+ INIT_REGEXSUB;
INIT_FTS;
INIT_SYSCTL;
INIT_ASYSCTL;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index a914d20a09e..f3a32073212 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -522,7 +522,8 @@
#define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
#define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
-#define SANITIZER_INTERCEPT_REGEX SI_NETBSD
+#define SANITIZER_INTERCEPT_REGEX (SI_NETBSD || SI_FREEBSD)
+#define SANITIZER_INTERCEPT_REGEXSUB SI_NETBSD
#define SANITIZER_INTERCEPT_FTS SI_NETBSD
#define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD || SI_MAC)
#define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
index 3eaa695ae16..8bca8f4459c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
@@ -25,6 +25,7 @@
#include <poll.h>
#include <pthread.h>
#include <pwd.h>
+#include <regex.h>
#include <signal.h>
#include <stddef.h>
#include <sys/mman.h>
@@ -125,6 +126,8 @@ namespace __sanitizer {
unsigned struct_statvfs_sz = sizeof(struct statvfs);
unsigned struct_shminfo_sz = sizeof(struct shminfo);
unsigned struct_shm_info_sz = sizeof(struct shm_info);
+ unsigned struct_regmatch_sz = sizeof(regmatch_t);
+ unsigned struct_regex_sz = sizeof(regex_t);
const uptr sig_ign = (uptr)SIG_IGN;
const uptr sig_dfl = (uptr)SIG_DFL;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
index b212c005c74..d383bceb07a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -62,6 +62,8 @@ namespace __sanitizer {
extern unsigned struct_rlimit_sz;
extern unsigned struct_utimbuf_sz;
extern unsigned struct_timespec_sz;
+ extern unsigned struct_regmatch_sz;
+ extern unsigned struct_regex_sz;
extern const int unvis_valid;
extern const int unvis_validpush;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc
index 8a4fb3885e7..a6f19f39bf9 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc
@@ -1,10 +1,16 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+//
+// UNSUPPORTED: linux, darwin, solaris
#include <assert.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
+#ifndef __arraycount
+#define __arraycount(a) ((sizeof(a) / sizeof(a[0])))
+#endif
+
void test_matched(const regex_t *preg, const char *string) {
int rv = regexec(preg, string, 0, NULL, 0);
if (!rv)
@@ -33,37 +39,6 @@ void test_print_matches(const regex_t *preg, const char *string) {
abort();
}
-void test_nsub(const regex_t *preg, const char *string) {
- regmatch_t rm[10];
- int rv = regexec(preg, string, __arraycount(rm), rm, 0);
- if (!rv) {
- char buf[1024];
- ssize_t ss = regnsub(buf, __arraycount(buf), "\\1xyz", rm, string);
- assert(ss != -1);
-
- printf("'%s' -> '%s'\n", string, buf);
- } else if (rv == REG_NOMATCH)
- printf("%s: not-matched\n", string);
- else
- abort();
-}
-
-void test_asub(const regex_t *preg, const char *string) {
- regmatch_t rm[10];
- int rv = regexec(preg, string, __arraycount(rm), rm, 0);
- if (!rv) {
- char *buf;
- ssize_t ss = regasub(&buf, "\\1xyz", rm, string);
- assert(ss != -1);
-
- printf("'%s' -> '%s'\n", string, buf);
- free(buf);
- } else if (rv == REG_NOMATCH)
- printf("%s: not-matched\n", string);
- else
- abort();
-}
-
int main(void) {
printf("regex\n");
@@ -76,9 +51,6 @@ int main(void) {
test_print_matches(&regex, "ABC");
- test_nsub(&regex, "ABC DEF");
- test_asub(&regex, "GHI JKL");
-
regfree(&regex);
rv = regcomp(&regex, "[[:upp:]]", 0);
@@ -93,8 +65,6 @@ int main(void) {
// CHECK: ABC: matched
// CHECK: matched[0]='AB'
// CHECK: matched[1]='B'
- // CHECK: 'ABC DEF' -> 'Bxyz'
- // CHECK: 'GHI JKL' -> 'Hxyz'
// CHECK: error:{{.*}}
return 0;
OpenPOWER on IntegriCloud