=== removed file 'consts.c' --- consts.c 2010-11-27 18:50:51 +0000 +++ consts.c 1970-01-01 00:00:00 +0000 @@ -1,45 +0,0 @@ -#include -#include - -#define pcomment(COMMENT) printf("// %s\n", COMMENT) -#define ppackage(NAME) printf("package %s\n", NAME) -#define pconstblock(EXPS) { printf("\nconst (\n"); {EXPS} printf(")\n"); } -#define pconst(NAME) printf(" %-13s = 0x%x\n", #NAME, NAME) - -int main(int argc, char *argvc[]) { - pcomment("** This file is automatically generated from consts.c. **"); - ppackage("gommap"); - pconstblock( - pconst(PROT_NONE); - pconst(PROT_READ); - pconst(PROT_WRITE); - pconst(PROT_EXEC); - ) - pconstblock( - pconst(MAP_SHARED); - pconst(MAP_PRIVATE); - pconst(MAP_FIXED); - pconst(MAP_ANONYMOUS); - pconst(MAP_GROWSDOWN); - pconst(MAP_LOCKED); - pconst(MAP_NONBLOCK); - pconst(MAP_NORESERVE); - pconst(MAP_POPULATE); - ) - pconstblock( - pconst(MS_SYNC); - pconst(MS_ASYNC); - pconst(MS_INVALIDATE); - ) - pconstblock( - pconst(MADV_NORMAL); - pconst(MADV_RANDOM); - pconst(MADV_SEQUENTIAL); - pconst(MADV_WILLNEED); - pconst(MADV_DONTNEED); - pconst(MADV_REMOVE); - pconst(MADV_DONTFORK); - pconst(MADV_DOFORK); - ) - return 0; -} === modified file 'gommap.go' --- gommap.go 2011-04-25 22:11:03 +0000 +++ gommap.go 2012-04-06 21:19:57 +0000 @@ -28,7 +28,7 @@ // Create a new mapping in the virtual address space of the calling process. // This function will attempt to map the entire file by using the fstat system // call with the provided file descriptor to discover its length. -func Map(fd int, prot, flags uint) (MMap, os.Error) { +func Map(fd int, prot, flags uint) (MMap, error) { mmap, err := MapAt(0, fd, 0, -1, prot, flags) return mmap, err } @@ -37,7 +37,7 @@ // using the specified region of the provided file or device. If -1 is provided // as length, this function will attempt to map until the end of the provided // file descriptor by using the fstat system call to discover its length. -func MapRegion(fd int, offset, length int64, prot, flags uint) (MMap, os.Error) { +func MapRegion(fd int, offset, length int64, prot, flags uint) (MMap, error) { mmap, err := MapAt(0, fd, offset, length, prot, flags) return mmap, err } @@ -48,17 +48,18 @@ // position the memory mapped region. If -1 is provided as length, this // function will attempt to map until the end of the provided file descriptor // by using the fstat system call to discover its length. -func MapAt(addr uintptr, fd int, offset, length int64, prot, flags uint) (MMap, os.Error) { +func MapAt(addr uintptr, fd int, offset, length int64, prot, flags uint) (MMap, error) { if length == -1 { var stat syscall.Stat_t - if errno := syscall.Fstat(fd, &stat); errno != 0 { - return nil, os.Errno(errno) + if error := syscall.Fstat(fd, &stat); error != nil { + return nil, error } length = stat.Size } addr, errno := mmap_syscall(addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), offset) + if errno != 0 { - return nil, os.Errno(errno) + return nil, errno } mmap := MMap{} @@ -75,11 +76,11 @@ // // IMPORTANT: Please see note (1) in the package documentation regarding the way // in which this type behaves. -func (mmap MMap) UnsafeUnmap() os.Error { +func (mmap MMap) UnsafeUnmap() error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(rh.Data), uintptr(rh.Len), 0) if errno != 0 { - return os.Errno(errno) + return errno } return nil } @@ -90,55 +91,55 @@ // parameter specifies whether flushing should be done synchronously (before // the method returns) with MS_SYNC, or asynchronously (flushing is just // scheduled) with MS_ASYNC. -func (mmap MMap) Sync(flags uint) os.Error { +func (mmap MMap) Sync(flags uint) error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MSYNC, uintptr(rh.Data), uintptr(rh.Len), uintptr(flags)) if errno != 0 { - return os.Errno(errno) + return errno } return nil } // Advise the kernel about how to handle the mapped memory region in terms // of input/output paging within the memory region defined by the mmap slice. -func (mmap MMap) Advise(advice uint) os.Error { +func (mmap MMap) Advise(advice uint) error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MADVISE, uintptr(rh.Data), uintptr(rh.Len), uintptr(advice)) if errno != 0 { - return os.Errno(errno) + return errno } return nil } // Change protection flags for the memory mapped region defined by // the mmap slice. -func (mmap MMap) Protect(prot uint) os.Error { +func (mmap MMap) Protect(prot uint) error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MPROTECT, uintptr(rh.Data), uintptr(rh.Len), uintptr(prot)) if errno != 0 { - return os.Errno(errno) + return errno } return nil } // Lock the mapped region defined by the mmap slice, preventing it from // being swapped out. -func (mmap MMap) Lock() os.Error { +func (mmap MMap) Lock() error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MLOCK, uintptr(rh.Data), uintptr(rh.Len), 0) if errno != 0 { - return os.Errno(errno) + return errno } return nil } // Unlock the mapped region defined by the mmap slice, allowing it to // swap out again. -func (mmap MMap) Unlock() os.Error { +func (mmap MMap) Unlock() error { rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) _, _, errno := syscall.Syscall(syscall.SYS_MUNLOCK, uintptr(rh.Data), uintptr(rh.Len), 0) if errno != 0 { - return os.Errno(errno) + return errno } return nil } @@ -148,14 +149,14 @@ // not in memory at the time the call was made. Note that the higher bits // are reserved for future use, so do not simply run an equality test // with 1. -func (mmap MMap) InCore() ([]uint8, os.Error) { +func (mmap MMap) InCore() ([]uint8, error) { pageSize := os.Getpagesize() result := make([]uint8, (len(mmap)+pageSize-1)/pageSize) rh := *(*reflect.SliceHeader)(unsafe.Pointer(&mmap)) resulth := *(*reflect.SliceHeader)(unsafe.Pointer(&result)) _, _, errno := syscall.Syscall(syscall.SYS_MINCORE, uintptr(rh.Data), uintptr(rh.Len), uintptr(resulth.Data)) if errno != 0 { - return nil, os.Errno(errno) + return nil, errno } return result, nil } === modified file 'mmap_linux_amd64.go' --- mmap_linux_amd64.go 2011-04-25 22:11:03 +0000 +++ mmap_linux_amd64.go 2012-04-06 21:16:02 +0000 @@ -2,7 +2,7 @@ import "syscall" -func mmap_syscall(addr, length, prot, flags, fd uintptr, offset int64) (uintptr, uintptr) { +func mmap_syscall(addr, length, prot, flags, fd uintptr, offset int64) (uintptr, syscall.Errno) { addr, _, errno := syscall.Syscall6(syscall.SYS_MMAP, addr, length, prot, flags, fd, uintptr(offset)) return addr, errno }