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
This commit is contained in:
parent
ac414139ec
commit
18b3f0f54c
Notes:
git
2020-09-29 00:21:01 +09:00
@ -18,6 +18,7 @@
|
|||||||
#include "internal/compilers.h"
|
#include "internal/compilers.h"
|
||||||
#include "internal/hash.h"
|
#include "internal/hash.h"
|
||||||
#include "internal/imemo.h"
|
#include "internal/imemo.h"
|
||||||
|
#include "internal/sanitizers.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "ruby/io.h"
|
#include "ruby/io.h"
|
||||||
#include "ruby/re.h"
|
#include "ruby/re.h"
|
||||||
@ -58,6 +59,9 @@ total_i(void *vstart, void *vend, size_t stride, void *ptr)
|
|||||||
struct total_data *data = (struct total_data *)ptr;
|
struct total_data *data = (struct total_data *)ptr;
|
||||||
|
|
||||||
for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
|
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) {
|
if (RBASIC(v)->flags) {
|
||||||
switch (BUILTIN_TYPE(v)) {
|
switch (BUILTIN_TYPE(v)) {
|
||||||
case T_NONE:
|
case T_NONE:
|
||||||
@ -72,6 +76,10 @@ total_i(void *vstart, void *vend, size_t stride, void *ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -155,9 +163,16 @@ cos_i(void *vstart, void *vend, size_t stride, void *data)
|
|||||||
VALUE v = (VALUE)vstart;
|
VALUE v = (VALUE)vstart;
|
||||||
|
|
||||||
for (;v != (VALUE)vend; v += stride) {
|
for (;v != (VALUE)vend; v += stride) {
|
||||||
|
void *ptr = asan_poisoned_object_p(v);
|
||||||
|
asan_unpoison_object(v, false);
|
||||||
|
|
||||||
if (RBASIC(v)->flags) {
|
if (RBASIC(v)->flags) {
|
||||||
counts[BUILTIN_TYPE(v)] += rb_obj_memsize_of(v);
|
counts[BUILTIN_TYPE(v)] += rb_obj_memsize_of(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -261,6 +276,9 @@ cs_i(void *vstart, void *vend, size_t stride, void *n)
|
|||||||
VALUE v = (VALUE)vstart;
|
VALUE v = (VALUE)vstart;
|
||||||
|
|
||||||
for (; v != (VALUE)vend; v += stride) {
|
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) {
|
if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_SYMBOL) {
|
||||||
ID id = RSYMBOL(v)->id;
|
ID id = RSYMBOL(v)->id;
|
||||||
if ((id & ~ID_SCOPE_MASK) == 0) {
|
if ((id & ~ID_SCOPE_MASK) == 0) {
|
||||||
@ -270,6 +288,10 @@ cs_i(void *vstart, void *vend, size_t stride, void *n)
|
|||||||
counts->immortal++;
|
counts->immortal++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -500,6 +522,9 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
|
|||||||
VALUE v = (VALUE)vstart;
|
VALUE v = (VALUE)vstart;
|
||||||
|
|
||||||
for (; v != (VALUE)vend; v += stride) {
|
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) {
|
if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_DATA) {
|
||||||
VALUE counter;
|
VALUE counter;
|
||||||
VALUE key = RBASIC(v)->klass;
|
VALUE key = RBASIC(v)->klass;
|
||||||
@ -520,6 +545,10 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
|
|||||||
|
|
||||||
rb_hash_aset(hash, key, counter);
|
rb_hash_aset(hash, key, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -574,6 +603,9 @@ count_imemo_objects_i(void *vstart, void *vend, size_t stride, void *data)
|
|||||||
VALUE v = (VALUE)vstart;
|
VALUE v = (VALUE)vstart;
|
||||||
|
|
||||||
for (; v != (VALUE)vend; v += stride) {
|
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) {
|
if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_IMEMO) {
|
||||||
VALUE counter;
|
VALUE counter;
|
||||||
VALUE key = ID2SYM(imemo_type_ids[imemo_type(v)]);
|
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)
|
|||||||
|
|
||||||
rb_hash_aset(hash, key, counter);
|
rb_hash_aset(hash, key, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "internal/hash.h"
|
#include "internal/hash.h"
|
||||||
#include "internal/string.h"
|
#include "internal/string.h"
|
||||||
|
#include "internal/sanitizers.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "objspace.h"
|
#include "objspace.h"
|
||||||
#include "ruby/debug.h"
|
#include "ruby/debug.h"
|
||||||
@ -508,8 +509,15 @@ heap_i(void *vstart, void *vend, size_t stride, void *data)
|
|||||||
struct dump_config *dc = (struct dump_config *)data;
|
struct dump_config *dc = (struct dump_config *)data;
|
||||||
VALUE v = (VALUE)vstart;
|
VALUE v = (VALUE)vstart;
|
||||||
for (; v != (VALUE)vend; v += stride) {
|
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)
|
if (dc->full_heap || RBASIC(v)->flags)
|
||||||
dump_object(v, dc);
|
dump_object(v, dc);
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
asan_poison_object(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user