Skip to content

Commit

Permalink
Prefix asan_poison_object with rb
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Dec 18, 2024
1 parent ce60df9 commit fb9e573
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions ext/coverage/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
VALUE ncoverages = *(VALUE*)data, v;

for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
void *poisoned = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *poisoned = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (RB_TYPE_P(v, T_IMEMO) && imemo_type(v) == imemo_ment) {
const rb_method_entry_t *me = (rb_method_entry_t *) v;
Expand Down Expand Up @@ -287,7 +287,7 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
}

if (poisoned) {
asan_poison_object(v);
rb_asan_poison_object(v);
}
}
return 0;
Expand Down
6 changes: 3 additions & 3 deletions ext/objspace/objspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ heap_iter(void *vstart, void *vend, size_t stride, void *ptr)
VALUE v;

for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
void *poisoned = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *poisoned = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (RBASIC(v)->flags) {
(*ctx->cb)(v, ctx->data);
}

if (poisoned) {
asan_poison_object(v);
rb_asan_poison_object(v);
}
}

Expand Down
6 changes: 3 additions & 3 deletions ext/objspace/objspace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,15 @@ heap_i(void *vstart, void *vend, size_t stride, void *data)
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);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);
dc->cur_page_slot_size = stride;

if (dc->full_heap || RBASIC(v)->flags)
dump_object(v, dc);

if (ptr) {
asan_poison_object(v);
rb_asan_poison_object(v);
}
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ internal_object_p(VALUE obj)
}
}
if (ptr || !RBASIC(obj)->flags) {
asan_poison_object(obj);
rb_asan_poison_object(obj);
}
return 1;
}
Expand Down Expand Up @@ -4310,21 +4310,21 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
#undef C

void
asan_poison_object(VALUE obj)
rb_asan_poison_object(VALUE obj)
{
MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj;
asan_poison_memory_region(ptr, rb_gc_obj_slot_size(obj));
}

void
asan_unpoison_object(VALUE obj, bool newobj_p)
rb_asan_unpoison_object(VALUE obj, bool newobj_p)
{
MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj;
asan_unpoison_memory_region(ptr, rb_gc_obj_slot_size(obj), newobj_p);
}

void *
asan_poisoned_object_p(VALUE obj)
rb_asan_poisoned_object_p(VALUE obj)
{
MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj;
return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj));
Expand Down
32 changes: 16 additions & 16 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ static void heap_page_free(rb_objspace_t *objspace, struct heap_page *page);
static inline void
heap_page_add_freeobj(rb_objspace_t *objspace, struct heap_page *page, VALUE obj)
{
asan_unpoison_object(obj, false);
rb_asan_unpoison_object(obj, false);

asan_unlock_freelist(page);

Expand All @@ -1641,7 +1641,7 @@ heap_page_add_freeobj(rb_objspace_t *objspace, struct heap_page *page, VALUE obj
rb_bug("heap_page_add_freeobj: %p is not rvalue.", (void *)obj);
}

asan_poison_object(obj);
rb_asan_poison_object(obj);
gc_report(3, objspace, "heap_page_add_freeobj: add %p to freelist\n", (void *)obj);
}

Expand Down Expand Up @@ -2291,7 +2291,7 @@ ractor_cache_allocate_slot(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *ca

if (RB_LIKELY(p)) {
VALUE obj = (VALUE)p;
asan_unpoison_object(obj, true);
rb_asan_unpoison_object(obj, true);
heap_cache->freelist = p->next;
#if RGENGC_CHECK_MODE
GC_ASSERT(rb_gc_impl_obj_slot_size(obj) == heap_slot_size(heap_idx));
Expand Down Expand Up @@ -2341,9 +2341,9 @@ ractor_cache_set_page(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache,
page->free_slots = 0;
page->freelist = NULL;

asan_unpoison_object((VALUE)heap_cache->freelist, false);
rb_asan_unpoison_object((VALUE)heap_cache->freelist, false);
GC_ASSERT(RB_TYPE_P((VALUE)heap_cache->freelist, T_NONE));
asan_poison_object((VALUE)heap_cache->freelist);
rb_asan_poison_object((VALUE)heap_cache->freelist);
}

static inline size_t
Expand Down Expand Up @@ -2926,7 +2926,7 @@ finalize_list(rb_objspace_t *objspace, VALUE zombie)
while (zombie) {
VALUE next_zombie;
struct heap_page *page;
asan_unpoison_object(zombie, false);
rb_asan_unpoison_object(zombie, false);
next_zombie = RZOMBIE(zombie)->next;
page = GET_HEAP_PAGE(zombie);

Expand Down Expand Up @@ -3247,7 +3247,7 @@ try_move(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *free_page,
VALUE dest = (VALUE)free_page->freelist;
asan_lock_freelist(free_page);
if (dest) {
asan_unpoison_object(dest, false);
rb_asan_unpoison_object(dest, false);
}
else {
/* if we can't get something from the freelist then the page must be
Expand Down Expand Up @@ -3514,7 +3514,7 @@ gc_sweep_plane(rb_objspace_t *objspace, rb_heap_t *heap, uintptr_t p, bits_t bit
VALUE vp = (VALUE)p;
GC_ASSERT(vp % BASE_SLOT_SIZE == 0);

asan_unpoison_object(vp, false);
rb_asan_unpoison_object(vp, false);
if (bitset & 1) {
switch (BUILTIN_TYPE(vp)) {
default: /* majority case */
Expand Down Expand Up @@ -3663,9 +3663,9 @@ gc_sweep_page(rb_objspace_t *objspace, rb_heap_t *heap, struct gc_sweep_context
struct free_slot *ptr = sweep_page->freelist;
while (ptr) {
freelist_len++;
asan_unpoison_object((VALUE)ptr, false);
rb_asan_unpoison_object((VALUE)ptr, false);
struct free_slot *next = ptr->next;
asan_poison_object((VALUE)ptr);
rb_asan_poison_object((VALUE)ptr);
ptr = next;
}
asan_lock_freelist(sweep_page);
Expand Down Expand Up @@ -3712,15 +3712,15 @@ heap_page_freelist_append(struct heap_page *page, struct free_slot *freelist)
asan_unlock_freelist(page);
if (page->freelist) {
struct free_slot *p = page->freelist;
asan_unpoison_object((VALUE)p, false);
rb_asan_unpoison_object((VALUE)p, false);
while (p->next) {
struct free_slot *prev = p;
p = p->next;
asan_poison_object((VALUE)prev);
asan_unpoison_object((VALUE)p, false);
rb_asan_poison_object((VALUE)prev);
rb_asan_unpoison_object((VALUE)p, false);
}
p->next = freelist;
asan_poison_object((VALUE)p);
rb_asan_poison_object((VALUE)p);
}
else {
page->freelist = freelist;
Expand Down Expand Up @@ -5143,12 +5143,12 @@ gc_verify_heap_pages_(rb_objspace_t *objspace, struct ccan_list_head *head)
while (p) {
VALUE vp = (VALUE)p;
VALUE prev = vp;
asan_unpoison_object(vp, false);
rb_asan_unpoison_object(vp, false);
if (BUILTIN_TYPE(vp) != T_NONE) {
fprintf(stderr, "freelist slot expected to be T_NONE but was: %s\n", rb_obj_info(vp));
}
p = p->next;
asan_poison_object(prev);
rb_asan_poison_object(prev);
}
asan_lock_freelist(page);

Expand Down
4 changes: 2 additions & 2 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ vm_ccs_free(struct rb_class_cc_entries *ccs, int alive, VALUE klass)
}
else {
if (ptr) {
asan_poison_object((VALUE)cc);
rb_asan_poison_object((VALUE)cc);
}
continue;
}
if (ptr) {
asan_poison_object((VALUE)cc);
rb_asan_poison_object((VALUE)cc);
}
}

Expand Down
14 changes: 7 additions & 7 deletions internal/sanitizers.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ asan_poison_memory_region(const volatile void *ptr, size_t size)

#ifdef RUBY_ASAN_ENABLED
#define asan_poison_object_if(ptr, obj) do { \
if (ptr) asan_poison_object(obj); \
if (ptr) rb_asan_poison_object(obj); \
} while (0)
#else
#define asan_poison_object_if(ptr, obj) ((void)(ptr), (void)(obj))
Expand All @@ -133,7 +133,7 @@ RUBY_SYMBOL_EXPORT_BEGIN
*
* @param[in] obj target object.
*/
void asan_poison_object(VALUE obj);
void rb_asan_poison_object(VALUE obj);

/**
* This function predicates if the given object is fully addressable or not.
Expand All @@ -142,15 +142,15 @@ void asan_poison_object(VALUE obj);
* @retval 0 the given object is fully addressable.
* @retval otherwise pointer to first such byte who is poisoned.
*/
void *asan_poisoned_object_p(VALUE obj);
void *rb_asan_poisoned_object_p(VALUE obj);

/**
* This is a variant of asan_unpoison_memory_region that takes a VALUE.
*
* @param[in] obj target object.
* @param[in] malloc_p if the memory region is like a malloc's return value or not.
*/
void asan_unpoison_object(VALUE obj, bool newobj_p);
void rb_asan_unpoison_object(VALUE obj, bool newobj_p);

RUBY_SYMBOL_EXPORT_END

Expand Down Expand Up @@ -184,16 +184,16 @@ asan_unpoison_memory_region(const volatile void *ptr, size_t size, bool malloc_p
static inline void *
asan_unpoison_object_temporary(VALUE obj)
{
void *ptr = asan_poisoned_object_p(obj);
asan_unpoison_object(obj, false);
void *ptr = rb_asan_poisoned_object_p(obj);
rb_asan_unpoison_object(obj, false);
return ptr;
}

static inline void *
asan_poison_object_restore(VALUE obj, void *ptr)
{
if (ptr) {
asan_poison_object(obj);
rb_asan_poison_object(obj);
}
return NULL;
}
Expand Down
16 changes: 8 additions & 8 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,8 @@ remove_coverage_i(void *vstart, void *vend, size_t stride, void *data)
{
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (rb_obj_is_iseq(v)) {
rb_iseq_t *iseq = (rb_iseq_t *)v;
Expand Down Expand Up @@ -4035,8 +4035,8 @@ clear_attr_ccs_i(void *vstart, void *vend, size_t stride, void *data)
{
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);
clear_attr_cc(v);
asan_poison_object_if(ptr, v);
}
Expand All @@ -4054,8 +4054,8 @@ clear_bf_ccs_i(void *vstart, void *vend, size_t stride, void *data)
{
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);
clear_bf_cc(v);
asan_poison_object_if(ptr, v);
}
Expand All @@ -4075,8 +4075,8 @@ trace_set_i(void *vstart, void *vend, size_t stride, void *data)

VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (rb_obj_is_iseq(v)) {
rb_iseq_trace_set(rb_iseq_check((rb_iseq_t *)v), turnon_events);
Expand Down
4 changes: 2 additions & 2 deletions rjit_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ for_each_iseq_i(void *vstart, void *vend, size_t stride, void *data)
VALUE block = (VALUE)data;
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (rb_obj_is_iseq(v)) {
extern VALUE rb_rjit_iseq_new(rb_iseq_t *iseq);
Expand Down
6 changes: 3 additions & 3 deletions vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ invalidate_all_refinement_cc(void *vstart, void *vend, size_t stride, void *data
{
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (RBASIC(v)->flags) { // liveness check
if (imemo_type_p(v, imemo_callcache)) {
Expand All @@ -327,7 +327,7 @@ invalidate_all_refinement_cc(void *vstart, void *vend, size_t stride, void *data
}

if (ptr) {
asan_poison_object(v);
rb_asan_poison_object(v);
}
}
return 0; // continue to iteration
Expand Down
4 changes: 2 additions & 2 deletions yjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,8 @@ for_each_iseq_i(void *vstart, void *vend, size_t stride, void *data)
const struct iseq_callback_data *callback_data = (struct iseq_callback_data *)data;
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
void *ptr = asan_poisoned_object_p(v);
asan_unpoison_object(v, false);
void *ptr = rb_asan_poisoned_object_p(v);
rb_asan_unpoison_object(v, false);

if (rb_obj_is_iseq(v)) {
rb_iseq_t *iseq = (rb_iseq_t *)v;
Expand Down

0 comments on commit fb9e573

Please sign in to comment.