[compiler-rt] a11aea6 - [compiler-rt][hwasan] Define fuchsia implementations of required hwasan functions

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 10:24:51 PDT 2021


Author: Leonard Chan
Date: 2021-07-08T10:24:27-07:00
New Revision: a11aea68a4b31e72bc0b84bde5f3210048287d28

URL: https://github.com/llvm/llvm-project/commit/a11aea68a4b31e72bc0b84bde5f3210048287d28
DIFF: https://github.com/llvm/llvm-project/commit/a11aea68a4b31e72bc0b84bde5f3210048287d28.diff

LOG: [compiler-rt][hwasan] Define fuchsia implementations of required hwasan functions

This contains all the definitions required by hwasan for the fuchsia
implementation and can be landed independently from the remaining parts of D91466.

Differential Revision: https://reviews.llvm.org/D103936

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
index b8e67c4c48221..e61f6ada72fc4 100644
--- a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -30,6 +30,19 @@ THREADLOCAL uptr __hwasan_tls;
 
 namespace __hwasan {
 
+bool InitShadow() {
+  __sanitizer::InitShadowBounds();
+  CHECK_NE(__sanitizer::ShadowBounds.shadow_limit, 0);
+
+  return true;
+}
+
+bool MemIsApp(uptr p) {
+  CHECK(GetTagFromPointer(p) == 0);
+  return __sanitizer::ShadowBounds.shadow_limit <= p &&
+         p <= (__sanitizer::ShadowBounds.memory_limit - 1);
+}
+
 // These are known parameters passed to the hwasan runtime on thread creation.
 struct Thread::InitState {
   uptr stack_bottom, stack_top;
@@ -130,6 +143,26 @@ static void ThreadExitHook(void *hook, thrd_t self) {
   hwasanThreadList().ReleaseThread(thread);
 }
 
+// Not implemented because Fuchsia does not use signal handlers.
+void HwasanOnDeadlySignal(int signo, void *info, void *context) {}
+
+// Not implemented because Fuchsia does not use interceptors.
+void InitializeInterceptors() {}
+
+// Not implemented because this is only relevant for Android.
+void AndroidTestTlsSlot() {}
+
+// TSD was normally used on linux as a means of calling the hwasan thread exit
+// handler passed to pthread_key_create. This is not needed on Fuchsia because
+// we will be using __sanitizer_thread_exit_hook.
+void HwasanTSDInit() {}
+void HwasanTSDThreadInit() {}
+
+// On linux, this just would call `atexit(HwasanAtExit)`. The functions in
+// HwasanAtExit are unimplemented for Fuchsia and effectively no-ops, so this
+// function is unneeded.
+void InstallAtExitHandler() {}
+
 }  // namespace __hwasan
 
 extern "C" {

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
index 4f692f99c207c..70a5e7e251eee 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
@@ -156,8 +156,10 @@ uptr GetMmapGranularity() { return _zx_system_get_page_size(); }
 
 sanitizer_shadow_bounds_t ShadowBounds;
 
+void InitShadowBounds() { ShadowBounds = __sanitizer_shadow_bounds(); }
+
 uptr GetMaxUserVirtualAddress() {
-  ShadowBounds = __sanitizer_shadow_bounds();
+  InitShadowBounds();
   return ShadowBounds.memory_limit - 1;
 }
 


        


More information about the llvm-commits mailing list