Skip to content

Commit

Permalink
Ensure the VM is alive before accessing objspace in C API (Feature #…
Browse files Browse the repository at this point in the history
…19627)

[Feature #19627]
  • Loading branch information
ianks committed May 4, 2023
1 parent e135a21 commit 2f9f44f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gc.c
Expand Up @@ -1007,6 +1007,11 @@ asan_unlock_freelist(struct heap_page *page)
/* Aliases */
#define rb_objspace (*rb_objspace_of(GET_VM()))
#define rb_objspace_of(vm) ((vm)->objspace)
#define unless_objspace(objspace) \
rb_objspace_t *objspace; \
rb_vm_t *unless_objspace_vm = GET_VM(); \
if (unless_objspace_vm) objspace = unless_objspace_vm->objspace; \
else /* return; or objspace will be warned uninitialized */

#define ruby_initial_gc_stress gc_params.gc_stress

Expand Down Expand Up @@ -10914,15 +10919,15 @@ rb_gc_start(void)
void
rb_gc(void)
{
rb_objspace_t *objspace = &rb_objspace;
unless_objspace(objspace) { return; }
unsigned int reason = GPR_DEFAULT_REASON;
garbage_collect(objspace, reason);
}

int
rb_during_gc(void)
{
rb_objspace_t *objspace = &rb_objspace;
unless_objspace(objspace) { return FALSE; }
return during_gc;
}

Expand Down Expand Up @@ -12740,7 +12745,8 @@ gc_malloc_allocations(VALUE self)
void
rb_gc_adjust_memory_usage(ssize_t diff)
{
rb_objspace_t *objspace = &rb_objspace;
unless_objspace(objspace) { return; }

if (diff > 0) {
objspace_malloc_increase(objspace, 0, diff, 0, MEMOP_TYPE_REALLOC);
}
Expand Down

0 comments on commit 2f9f44f

Please sign in to comment.