ruby-changes:48313
From: mame <ko1@a...>
Date: Wed, 25 Oct 2017 22:19:52 +0900 (JST)
Subject: [ruby-changes:48313] mame:r60427 (trunk): Make imemo_alloc writebarrier-unprotected
mame 2017-10-25 22:19:45 +0900 (Wed, 25 Oct 2017) New Revision: 60427 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60427 Log: Make imemo_alloc writebarrier-unprotected imemo_alloc provides a memory buffer whose contents are marked by GC. C code can access imemo_alloc buffer freely, so imemo_alloc must be considered writebarrier-unprotected. But T_IMEMO is writebarrier- protected by default, which caused a GC bug. Modified files: trunk/gc.c trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 60426) +++ parse.y (revision 60427) @@ -11538,6 +11538,7 @@ rb_parser_malloc(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L11538 size_t cnt = HEAPCNT(1, size); rb_imemo_alloc_t *n = NEWHEAP(); void *ptr = xmalloc(size); + rb_gc_writebarrier_unprotect((VALUE)n); return ADD2HEAP(n, cnt, ptr); } @@ -11548,6 +11549,7 @@ rb_parser_calloc(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L11549 size_t cnt = HEAPCNT(nelem, size); rb_imemo_alloc_t *n = NEWHEAP(); void *ptr = xcalloc(nelem, size); + rb_gc_writebarrier_unprotect((VALUE)n); return ADD2HEAP(n, cnt, ptr); } @@ -11569,6 +11571,7 @@ rb_parser_realloc(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L11571 } n = NEWHEAP(); ptr = xrealloc(ptr, size); + rb_gc_writebarrier_unprotect((VALUE)n); return ADD2HEAP(n, cnt, ptr); } Index: gc.c =================================================================== --- gc.c (revision 60426) +++ gc.c (revision 60427) @@ -8118,6 +8118,7 @@ rb_alloc_tmp_buffer_with_count(volatile https://github.com/ruby/ruby/blob/trunk/gc.c#L8118 void *ptr; s = rb_imemo_new(imemo_alloc, 0, 0, 0, 0); + rb_gc_writebarrier_unprotect(s); ptr = ruby_xmalloc0(size); a = (rb_imemo_alloc_t*)s; a->ptr = (VALUE*)ptr; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/