1 ;; This newlisp module implements mmap access to file regions.
4 (unless foop (load "foop.lsp"))
8 (FOOP base len prot flags fd offset)
10 (constant 'LIBC (exists file? '("/lib/x86_64-linux-gnu/libc.so.6")))
11 (unless LIBC (die "cannot find libc"))
13 (import LIBC "mmap" "void*"
15 "long" ; size_t length
21 (import LIBC "munmap" "int"
23 "long" ; size_t length
25 (import LIBC "lseek" "long"
27 "long" ; off_t offset,
31 (import LIBC "msync" "int"
33 "long" ; size_t length
44 ;; Creates a new mapping in the virtual address space of the calling
46 (define (MMap:MMap FD LENGTH (OFFSET 0) (PROT PROT_READ))
47 (when (string? FD) (setf FD (open FD "r")))
48 (let ((D (list (context) nil LENGTH 0 0 FD OFFSET)))
49 (when (< LENGTH) (setf (D 2) (lseek FD 0 SEEK_END)))
50 (setf (D 1) (mmap 0 (D 2) PROT MAP_SHARED FD OFFSET))
54 (munmap (%base) (%len)))