[compiler-rt] r204448 - [MSan] Add __msan_unpoison_string() to the public interface.
Sergey Matveev
earthdok at google.com
Fri Mar 21 03:12:17 PDT 2014
Author: smatveev
Date: Fri Mar 21 05:12:17 2014
New Revision: 204448
URL: http://llvm.org/viewvc/llvm-project?rev=204448&view=rev
Log:
[MSan] Add __msan_unpoison_string() to the public interface.
Using __msan_unpoison() on null-terminated strings is awkward because
strlen() can't be called on a poisoned string. This case warrants a special
interface function.
Added:
compiler-rt/trunk/test/msan/unpoison_string.cc
Modified:
compiler-rt/trunk/include/sanitizer/msan_interface.h
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/msan_interface_internal.h
Modified: compiler-rt/trunk/include/sanitizer/msan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/msan_interface.h?rev=204448&r1=204447&r2=204448&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/msan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/msan_interface.h Fri Mar 21 05:12:17 2014
@@ -38,6 +38,10 @@ extern "C" {
/* Make memory region fully initialized (without changing its contents). */
void __msan_unpoison(const volatile void *a, size_t size);
+ /* Make a null-terminated string fully initialized (without changing its
+ contents). */
+ void __msan_unpoison_string(const volatile char *a);
+
/* Make memory region fully uninitialized (without changing its contents). */
void __msan_poison(const volatile void *a, size_t size);
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=204448&r1=204447&r2=204448&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Fri Mar 21 05:12:17 2014
@@ -1372,6 +1372,11 @@ void *__msan_memmove(void *dest, const v
return res;
}
+void __msan_unpoison_string(const char* s) {
+ if (!MEM_IS_APP(s)) return;
+ __msan_unpoison(s, REAL(strlen)(s) + 1);
+}
+
namespace __msan {
void CopyOrigin(void *dst, const void *src, uptr size, StackTrace *stack) {
Modified: compiler-rt/trunk/lib/msan/msan_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=204448&r1=204447&r2=204448&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Fri Mar 21 05:12:17 2014
@@ -40,6 +40,8 @@ void __msan_warning_noreturn();
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_unpoison(const void *a, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE
+void __msan_unpoison_string(const char *s);
+SANITIZER_INTERFACE_ATTRIBUTE
void __msan_clear_and_unpoison(void *a, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE
void* __msan_memcpy(void *dst, const void *src, uptr size);
Added: compiler-rt/trunk/test/msan/unpoison_string.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/unpoison_string.cc?rev=204448&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/unpoison_string.cc (added)
+++ compiler-rt/trunk/test/msan/unpoison_string.cc Fri Mar 21 05:12:17 2014
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t
+// RUN: %t
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O3 %s -o %t
+// RUN: %t
+
+#include <assert.h>
+#include <string.h>
+#include <sanitizer/msan_interface.h>
+
+int main(int argc, char **argv) {
+ char s[20] = "string";
+ __msan_poison(s, sizeof(s));
+ __msan_unpoison_string(s);
+ assert(__msan_test_shadow(s, sizeof(s)) == strlen("string") + 1);
+ return 0;
+}
More information about the llvm-commits
mailing list