[ruby-cvs:70450] k0kubun:r63360 (trunk): _mjit_compile_pc_and_sp.erb: make sure no uninitialized

k0kubun at ruby-lang.org k0kubun at ruby-lang.org
Wed May 9 00:06:11 JST 2018


k0kubun	2018-05-09 00:06:11 +0900 (Wed, 09 May 2018)

  New Revision: 63360

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63360

  Log:
    _mjit_compile_pc_and_sp.erb: make sure no uninitialized
    
    area on VM stack to prevent SEGV on GC. GC may mark every value in VM
    stack.
    
    Unfortunately I couldn't write a test for it... So let me explain the
    situation.
    
    SEGV example:
    https://gist.github.com/k0kubun/c7cea2b5761ffdff29ec79ea1a8f7f91
    
    ```
    $ ruby --dump=insns -e 'def oct(num, len); "%0#{len}o" % num; end'
    == disasm: #<ISeq:oct at -e:1 (1,0)-(1,41)> (catch: FALSE)
    local table (size: 2, argc: 2 [opts: 0, rest: -1, post: 0, block: -1, kw: -1 at -1, kwrest: -1])
    [ 2] num at 0<Arg> [ 1] len at 1<Arg>
    0000 putobject                    "%0"                                (   1)[LiCa]
    0002 getlocal_WC_0                len at 1
    0004 dup
    0005 checktype                    T_STRING
    0007 branchif                     14
    0009 dup
    0010 opt_send_without_block       <callinfo!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
    0013 tostring
    0014 putobject                    "o"
    0016 concatstrings                3
    0018 getlocal_WC_0                num at 0
    0020 opt_mod                      <callinfo!mid:%, argc:1, ARGS_SIMPLE>, <callcache>
    0023 leave                        [Re]
    ```
    
    Prior to this commit, after arguments are pushed on 0010, stacks were:
    VM stack: [uninitialized, uninitialized, len]
    JIT stack: ["%0", len, len]
    
    And then, when GC is invoked on 0016, VM stack will be [uninitialized, uninitialized]
    and those uninitialized values will be marked by GC.
    
    With this commit, after arguments are pushed on 0010, stacks will be:
    VM stack: [len]
    JIT stack: ["%0", len, len]
    
    And VM stack will be [] on 0016.

  Modified files:
    trunk/tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb


More information about the ruby-cvs mailing list