[compiler-rt] r241758 - UBSan: Simplify logic for locating the RTTI object.

Peter Collingbourne peter at pcc.me.uk
Wed Jul 8 16:22:39 PDT 2015


Author: pcc
Date: Wed Jul  8 18:22:39 2015
New Revision: 241758

URL: http://llvm.org/viewvc/llvm-project?rev=241758&view=rev
Log:
UBSan: Simplify logic for locating the RTTI object.

The image-relative complete object locator contains a reference to itself,
which we can use to compute the image base without using VirtualQuery.

Spotted by David Majnemer.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc

Modified: compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc?rev=241758&r1=241757&r2=241758&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc Wed Jul  8 18:22:39 2015
@@ -19,12 +19,23 @@
 #include "sanitizer_common/sanitizer_common.h"
 
 #include <typeinfo>
-#include <windows.h>
 
 struct CompleteObjectLocator {
   int is_image_relative;
   int offset_to_top;
   int vfptr_offset;
+  int rtti_addr;
+  int chd_addr;
+  int obj_locator_addr;
+};
+
+struct CompleteObjectLocatorAbs {
+  int is_image_relative;
+  int offset_to_top;
+  int vfptr_offset;
+  std::type_info *rtti_addr;
+  void *chd_addr;
+  CompleteObjectLocator *obj_locator_addr;
 };
 
 bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {
@@ -45,17 +56,15 @@ __ubsan::getDynamicTypeInfoFromVtable(vo
 
   CompleteObjectLocator *obj_locator = *obj_locator_ptr;
   if (!IsAccessibleMemoryRange((uptr)obj_locator,
-                               sizeof(CompleteObjectLocator)+sizeof(void*)))
+                               sizeof(CompleteObjectLocator)))
     return DynamicTypeInfo(0, 0, 0);
 
   std::type_info *tinfo;
   if (obj_locator->is_image_relative == 1) {
-    MEMORY_BASIC_INFORMATION mbi;
-    VirtualQuery(obj_locator, &mbi, sizeof(mbi));
-    tinfo = (std::type_info*)(*(int*)(obj_locator+1) +
-                              (char*)mbi.AllocationBase);
+    char *image_base = ((char *)obj_locator) - obj_locator->obj_locator_addr;
+    tinfo = (std::type_info *)(image_base + obj_locator->rtti_addr);
   } else if (obj_locator->is_image_relative == 0)
-    tinfo = *(std::type_info**)(obj_locator+1);
+    tinfo = ((CompleteObjectLocatorAbs *)obj_locator)->rtti_addr;
   else
     // Probably not a complete object locator.
     return DynamicTypeInfo(0, 0, 0);





More information about the llvm-commits mailing list