[PATCH] D104275: [compiler-rt][hwasan] Add SHADOW_OFFSET macro

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 14 18:29:33 PDT 2021


leonardchan created this revision.
leonardchan added reviewers: vitalybuka, eugenis.
leonardchan added a project: Sanitizers.
Herald added a subscriber: dberris.
leonardchan requested review of this revision.
Herald added a subscriber: Sanitizers.

Similar to `SHADOW_OFFSET` on asan, we can use this for hwasan so platforms that use a constant value for the start of shadow memory can just use the constant rather than access a global.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104275

Files:
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_mapping.h


Index: compiler-rt/lib/hwasan/hwasan_mapping.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan_mapping.h
+++ compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -37,6 +37,12 @@
 constexpr uptr kShadowScale = 4;
 constexpr uptr kShadowAlignment = 1ULL << kShadowScale;
 
+#if SANITIZER_FUCHSIA
+#  define SHADOW_OFFSET (0)
+#else
+#  define SHADOW_OFFSET __hwasan_shadow_memory_dynamic_address
+#endif
+
 namespace __hwasan {
 
 extern uptr kLowMemStart;
@@ -51,11 +57,10 @@
 extern uptr kAliasRegionStart;
 
 inline uptr MemToShadow(uptr untagged_addr) {
-  return (untagged_addr >> kShadowScale) +
-         __hwasan_shadow_memory_dynamic_address;
+  return (untagged_addr >> kShadowScale) + SHADOW_OFFSET
 }
 inline uptr ShadowToMem(uptr shadow_addr) {
-  return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale;
+  return (shadow_addr - SHADOW_OFFSET) << kShadowScale;
 }
 inline uptr MemToShadowSize(uptr size) {
   return size >> kShadowScale;
Index: compiler-rt/lib/hwasan/hwasan_allocator.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan_allocator.h
+++ compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -114,7 +114,7 @@
   // Aliases are mapped next to shadow so that the upper bits match the shadow
   // base.
   return (addr >> kTaggableRegionCheckShift) ==
-         (__hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+         (SHADOW_OFFSET >> kTaggableRegionCheckShift);
 #endif
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104275.352025.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210615/2371253d/attachment.bin>


More information about the cfe-commits mailing list