;;; example-mmap.scm 0123456789 ;;; test.scm (use posix) (use lolevel) ;; Reading (let* ((fd (file-open "example-mmap.scm" (+ open/read open/nonblock))) (size (file-size fd)) (mmap (map-file-to-memory #f size prot/read (+ map/file map/shared) fd)) (buf (memory-mapped-file-pointer mmap)) (str (make-string size))) (move-memory! buf str size) (display str)) ;; Writing - SEGFAULTS! (let* ((fd (file-open "example-mmap.scm" open/wronly)) (size (file-size fd)) (mmap (map-file-to-memory #f size prot/write map/file fd)) (buf (memory-mapped-file-pointer mmap))) (move-memory! "0123456789\n" buf size)) ;;; OUTPUT #;1> (load "test") ; loading test.scm ... ; loading /usr/local/lib/chicken/6/posix.import.so ... ; loading library posix ... ; loading /usr/local/lib/chicken/6/lolevel.import.so ... ; loading library lolevel ... 0123456789 Process scheme segmentation fault ;;; SETTINGS ;; OS Linux 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:35:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux ;; Chicken (c) 2008-2013, The Chicken Team (c) 2000-2007, Felix L. Winkelmann Version 4.8.0.4 (stability/4.8.0) (rev 578619b) linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ] compiled 2013-07-15 on aeryn.xorinia.dim (Darwin)