mmap.lisp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;; 'prot' protection flags for mmap.
  2. (defbitfield mmap-prot-flags
  3. (:prot-none #x00)
  4. (:prot-read #x04)
  5. (:prot-write #x02)
  6. (:prot-exec #x01))
  7. ;; Specifies the type of the object in mmap 'flags'.
  8. (defbitfield mmap-map-flags
  9. (:map-file #x0001)
  10. (:map-type #x000f)
  11. (:map-shared #x0010)
  12. (:map-private #x0000)
  13. (:map-fixed #x0100)
  14. (:map-noextend #x0200)
  15. (:map-hassemphore #x0400)
  16. (:map-inherit #x0800)
  17. (:map-anon #x0002))
  18. (defcfun ("mmap" %mmap)
  19. :pointer
  20. (addr :pointer)
  21. (len :unsigned-int)
  22. (prot mmap-prot-flags)
  23. (flags mmap-map-flags)
  24. (filedes :int)
  25. (off off-t))
  26. (defun mmap (addr len prot flags filedes off)
  27. "Map files or devices into memory."
  28. (let ((ptr (%mmap addr len prot flags filedes off)))
  29. ; Mmap returns -1 in case of error
  30. ; XXX 64-bit
  31. (if (= (pointer-address ptr) #xffffffff)
  32. #nil
  33. ptr)))
  34. (defcfun ("munmap" %munmap) :int
  35. (addr :pointer)
  36. (len :unsigned-int))
  37. (defun munmap (addr len)
  38. "Remove a mapping."
  39. (cond
  40. ((and (exact-integer? len)
  41. (= len 0)) #t)
  42. ((null? addr) #nil)
  43. (#t
  44. (let ((result (%munmap addr len)))
  45. ; In case of success, munmap returns 0.
  46. (= result 0)))))