diff options
author | Takashi Kokubun <[email protected]> | 2023-01-07 21:24:24 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 22:11:20 -0800 |
commit | d09c723975a4386d283ca914a7369340fd07d925 (patch) | |
tree | 6719e1e8fca066c4904a66d698d07e805ccaebbd /lib/ruby_vm | |
parent | f4cf737af8a863e4e232232503c40b0769b742e2 (diff) |
Just write bytes normally
Diffstat (limited to 'lib/ruby_vm')
-rw-r--r-- | lib/ruby_vm/mjit/assembler.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/ruby_vm/mjit/assembler.rb b/lib/ruby_vm/mjit/assembler.rb index c8d9da9f2d..543d94bef2 100644 --- a/lib/ruby_vm/mjit/assembler.rb +++ b/lib/ruby_vm/mjit/assembler.rb @@ -3,9 +3,6 @@ module RubyVM::MJIT # https://www.intel.com/content/dam/develop/public/us/en/documents/325383-sdm-vol-2abcd.pdf # Mostly an x86_64 assembler, but this also has some stuff that is useful for any architecture. class Assembler - # A thin Fiddle wrapper to write bytes to memory - ByteWriter = CType::Immediate.parse('char') - # rel8 jumps are made with labels class Label < Data.define(:id, :name); end @@ -40,12 +37,8 @@ module RubyVM::MJIT resolve_rel32(addr) resolve_labels - writer = ByteWriter.new(addr) - # If you pack bytes containing \x00, Ruby fails to recognize bytes after \x00. - # So writing byte by byte to avoid hitting that situation. - @bytes.each_with_index do |byte, index| - writer[index] = byte - end + write_bytes(addr) + @bytes.size ensure @bytes.clear @@ -652,5 +645,9 @@ module RubyVM::MJIT end end end + + def write_bytes(addr) + Fiddle::Pointer.new(addr)[0, @bytes.size] = @bytes.pack('c*') + end end end |