mmap_linux_32.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE-GO file.
  4. //go:build linux && (386 || arm || mips || mipsle)
  5. // +build linux
  6. // +build 386 arm mips mipsle
  7. package memory
  8. import (
  9. "syscall"
  10. )
  11. // Function syscall.mmap and syscall.mmap2 are same for linux/386, linux/arm,
  12. // linux/mips and linux/mipsle
  13. // https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/syscall_linux_386.go;l=99-105
  14. func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
  15. page := uintptr(offset / 4096)
  16. if offset != int64(page)*4096 {
  17. return 0, syscall.EINVAL
  18. }
  19. return mmap2Syscall(addr, length, prot, flags, fd, page)
  20. }
  21. // https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_linux_386.go;l=1361-1370
  22. func mmap2Syscall(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) {
  23. r0, _, e1 := syscall.Syscall6(syscall.SYS_MMAP2, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(pageOffset))
  24. xaddr = uintptr(r0)
  25. if e1 != 0 {
  26. err = e1
  27. }
  28. return
  29. }