[前][次][番号順一覧][スレッド一覧]

ruby-changes:63180

From: Aaron <ko1@a...>
Date: Tue, 29 Sep 2020 00:20:47 +0900 (JST)
Subject: [ruby-changes:63180] 18b3f0f54c (master): Make ext/objspace ASAN friendly

https://git.ruby-lang.org/ruby.git/commit/?id=18b3f0f54c

From 18b3f0f54c66632b1039a27634a8a449a7812e34 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Fri, 25 Sep 2020 14:50:54 -0700
Subject: Make ext/objspace ASAN friendly

ext/objspace iterates over the heap, but some slots in the heap are
poisoned, so we need to take care of that when running with ASAN

diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 3bfb79d..074dfbd 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -18,6 +18,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L18
 #include "internal/compilers.h"
 #include "internal/hash.h"
 #include "internal/imemo.h"
+#include "internal/sanitizers.h"
 #include "node.h"
 #include "ruby/io.h"
 #include "ruby/re.h"
@@ -58,6 +59,9 @@ total_i(void *vstart, void *vend, size_t stride, void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L59
     struct total_data *data = (struct total_data *)ptr;
 
     for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (RBASIC(v)->flags) {
 	    switch (BUILTIN_TYPE(v)) {
 	      case T_NONE:
@@ -72,6 +76,10 @@ total_i(void *vstart, void *vend, size_t stride, void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L76
 		}
 	    }
 	}
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
 
     return 0;
@@ -155,9 +163,16 @@ cos_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L163
     VALUE v = (VALUE)vstart;
 
     for (;v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (RBASIC(v)->flags) {
 	    counts[BUILTIN_TYPE(v)] += rb_obj_memsize_of(v);
 	}
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
     return 0;
 }
@@ -261,6 +276,9 @@ cs_i(void *vstart, void *vend, size_t stride, void *n) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L276
     VALUE v = (VALUE)vstart;
 
     for (; v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_SYMBOL) {
 	    ID id = RSYMBOL(v)->id;
 	    if ((id & ~ID_SCOPE_MASK) == 0) {
@@ -270,6 +288,10 @@ cs_i(void *vstart, void *vend, size_t stride, void *n) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L288
 		counts->immortal++;
 	    }
 	}
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
 
     return 0;
@@ -500,6 +522,9 @@ cto_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L522
     VALUE v = (VALUE)vstart;
 
     for (; v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_DATA) {
 	    VALUE counter;
 	    VALUE key = RBASIC(v)->klass;
@@ -520,6 +545,10 @@ cto_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L545
 
 	    rb_hash_aset(hash, key, counter);
 	}
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
 
     return 0;
@@ -574,6 +603,9 @@ count_imemo_objects_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L603
     VALUE v = (VALUE)vstart;
 
     for (; v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_IMEMO) {
 	    VALUE counter;
 	    VALUE key = ID2SYM(imemo_type_ids[imemo_type(v)]);
@@ -589,6 +621,10 @@ count_imemo_objects_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L621
 
 	    rb_hash_aset(hash, key, counter);
 	}
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
 
     return 0;
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index e12b553..7a5f44a 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -16,6 +16,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L16
 #include "internal.h"
 #include "internal/hash.h"
 #include "internal/string.h"
+#include "internal/sanitizers.h"
 #include "node.h"
 #include "objspace.h"
 #include "ruby/debug.h"
@@ -508,8 +509,15 @@ heap_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L509
     struct dump_config *dc = (struct dump_config *)data;
     VALUE v = (VALUE)vstart;
     for (; v != (VALUE)vend; v += stride) {
+        void *ptr = asan_poisoned_object_p(v);
+        asan_unpoison_object(v, false);
+
 	if (dc->full_heap || RBASIC(v)->flags)
 	    dump_object(v, dc);
+
+        if (ptr) {
+            asan_poison_object(v);
+        }
     }
     return 0;
 }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]