vm-allocate.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. (define-module (mach vm-allocate)
  2. #:use-module (mach ffi)
  3. #:use-module (mach types)
  4. #:use-module ((mach task) #:select (task-self))
  5. #:export (vm-allocate vm-deallocate))
  6. (define-ffi ("vm_allocate" %vm-allocate)
  7. (err identity) ; FIXME ???
  8. (target-task ffi:pointer %unwrap-task)
  9. (address ffi:pointer make-pointer)
  10. (size vm-size identity)
  11. ;; FIXME really a bool FIXME what's this?
  12. (anywhere ffi:int bool->ffi-int))
  13. (define* (vm-allocate address size anywhere #:optional (task (task-self)))
  14. "Allocate a region of virtual memory in @var{task}, starting at @var{address}
  15. and of length @var{size}.
  16. By default, @var{task} is ourself. ADDRESS must be passed as an integer."
  17. (%vm-allocate task address size anywhere))
  18. (define-ffi ("vm_deallocate" %vm-deallocate)
  19. (err identity)
  20. (task ffi:pointer %unwrap-vm-task)
  21. (address ffi:pointer make-pointer)
  22. (size vm-size identity))
  23. (define* (vm-deallocate address size #:optional (task (task-self)))
  24. "Relinquishes access to a region of the address space of @var{task},
  25. starting at @var{address} (an integer) and of length @var{size},
  26. causing further access to that memory to fail.
  27. By default, @var{task} is ourself."
  28. (%vm-deallocate task address size))