From: Tim Pease Date: 2006-09-07T04:23:51+09:00 Subject: mmap causing a bus error $ cat mmap-abort.rb require 'mmap' require 'fileutils' FileUtils.touch 'output.txt' File.open('mmap.bin', 'w') {|f| f.truncate 16} unless File.exist? 'mmap.bin' m = Mmap.new 'output.txt', 'rw' (0...4).each do |x| fork do mmap = Mmap.new 'mmap.bin', 'rw' range = (x*4)...(x*4+4) val = mmap[range].unpack('N')[0] mmap[range] = [val+x].pack('N') mmap.unmap end end m << "Done!\n" # EOF $ ruby mmap-abort.rb mmap-abort.rb:20: [BUG] Bus Error ruby 1.8.4 (2005-12-24) [powerpc-linux] Aborted (core dumped) $ The line at the end -- m << "Done!\n" -- is causing the abort. I'm seeing this behavior on all the Unix platforms I have access to ... SunOS ravenclaw 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-1500 Linux panic 2.6.17-1.2157_FC5 #1 SMP Tue Jul 11 23:03:20 EDT 2006 ppc64 ppc64 ppc64 GNU/Linux Linux pong 2.6.17-1.2142_FC4 #1 Tue Jul 11 22:41:14 EDT 2006 i686 i686 i386 GNU/Linux So, the interesting part is that if I open the "output.txt" file and add a single character to it, the problem disappears ... $ echo 'x' > output.txt $ ruby mmap-abort.rb $ cat output.txt x Done! $ I can also make the problem go away by creating the mmap to output.txt after the each/fork block. I can also make the problem go away by commenting out the "mmap.unmap" line at the end of the fork block. The bus error is being caused by a call to memcpy in the "mm_cat" method of the mmap source code -- line 1480 of mmap.c Any patches out there?