From d7dc9a47d59c44b8ec0e2bd3923b42d10ac37506 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 31 Aug 2025 12:25:41 -0700 Subject: add more posix tests --- test/fuse_integration/mmap_unix.go | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 test/fuse_integration/mmap_unix.go (limited to 'test/fuse_integration/mmap_unix.go') diff --git a/test/fuse_integration/mmap_unix.go b/test/fuse_integration/mmap_unix.go new file mode 100644 index 000000000..702a1c032 --- /dev/null +++ b/test/fuse_integration/mmap_unix.go @@ -0,0 +1,85 @@ +//go:build unix + +package fuse + +import ( + "syscall" + "unsafe" +) + +// Memory mapping support for Unix-like systems + +func mmapFile(fd int, offset int64, length int, prot int, flags int) ([]byte, error) { + addr, _, errno := syscall.Syscall6(syscall.SYS_MMAP, + 0, // addr (let kernel choose) + uintptr(length), + uintptr(prot), + uintptr(flags), + uintptr(fd), + uintptr(offset)) + + if errno != 0 { + return nil, errno + } + + // Convert the address to a byte slice + return (*[1 << 30]byte)(unsafe.Pointer(addr))[:length:length], nil +} + +func munmapFile(data []byte) error { + if len(data) == 0 { + return nil + } + + _, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, + uintptr(unsafe.Pointer(&data[0])), + uintptr(len(data)), + 0) + + if errno != 0 { + return errno + } + return nil +} + +func msyncFile(data []byte, flags int) error { + if len(data) == 0 { + return nil + } + + _, _, errno := syscall.Syscall(syscall.SYS_MSYNC, + uintptr(unsafe.Pointer(&data[0])), + uintptr(len(data)), + uintptr(flags)) + + if errno != 0 { + return errno + } + return nil +} + +func isMmapSupported() bool { + return true +} + +// Memory protection flags +const ( + PROT_READ = syscall.PROT_READ + PROT_WRITE = syscall.PROT_WRITE + PROT_EXEC = syscall.PROT_EXEC + PROT_NONE = syscall.PROT_NONE +) + +// Memory mapping flags +const ( + MAP_SHARED = syscall.MAP_SHARED + MAP_PRIVATE = syscall.MAP_PRIVATE + MAP_ANONYMOUS = syscall.MAP_ANON +) + +// Memory sync flags +const ( + MS_ASYNC = syscall.MS_ASYNC + MS_SYNC = syscall.MS_SYNC + MS_INVALIDATE = syscall.MS_INVALIDATE +) -- cgit v1.2.3