ruby-changes:72491
From: Nobuyoshi <ko1@a...>
Date: Sun, 10 Jul 2022 16:38:48 +0900 (JST)
Subject: [ruby-changes:72491] b1b8172328 (master): Add `asan_unpoisoning_object` to execute the block with unpoisoning
https://git.ruby-lang.org/ruby.git/commit/?id=b1b8172328 From b1b8172328e384008bd17431335f512536c297f8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 6 Jul 2022 09:39:04 +0900 Subject: Add `asan_unpoisoning_object` to execute the block with unpoisoning --- gc.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gc.c b/gc.c index 86e1885fec..af3b6ec054 100644 --- a/gc.c +++ b/gc.c @@ -1409,6 +1409,21 @@ asan_unpoison_object_temporary(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L1409 return ptr; } +static inline void * +asan_poison_object_restore(VALUE obj, void *ptr) +{ + if (ptr) { + asan_poison_object(obj); + } + return NULL; +} + +#define asan_unpoisoning_object(obj) \ + for (void *poisoned = asan_unpoison_object_temporary(obj), \ + *unpoisoning = &poisoned; /* flag to loop just once */ \ + unpoisoning; \ + unpoisoning = asan_poison_object_restore(obj, poisoned)) + #define FL_CHECK2(name, x, pred) \ ((RGENGC_CHECK_MODE && SPECIAL_CONST_P(x)) ? \ (rb_bug(name": SPECIAL_CONST (%p)", (void *)(x)), 0) : (pred)) @@ -13945,14 +13960,10 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L13960 const char * rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) { - void *poisoned = asan_unpoison_object_temporary(obj); - - size_t pos = rb_raw_obj_info_common(buff, buff_size, obj); - pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos); - if (pos >= buff_size) {} // truncated - - if (poisoned) { - asan_poison_object(obj); + asan_unpoisoning_object(obj) { + size_t pos = rb_raw_obj_info_common(buff, buff_size, obj); + pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos); + if (pos >= buff_size) {} // truncated } return buff; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/