Test that mmap size doesn't exceed system memory address width

Should fix http://paste.ubuntu.com/26074620/
This commit is contained in:
Matt Joiner 2017-12-02 10:26:09 +11:00
parent 27253eb0d0
commit 520da249a1
1 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package storage package storage
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -142,15 +143,18 @@ func mmapFile(name string, size int64) (ret mmap.MMap, err error) {
// Can't mmap() regions with length 0. // Can't mmap() regions with length 0.
return return
} }
ret, err = mmap.MapRegion(file, intLen := int(size)
int(size), // Probably not great on <64 bit systems. if int64(intLen) != size {
mmap.RDWR, 0, 0) err = errors.New("size too large for system")
return
}
ret, err = mmap.MapRegion(file, intLen, mmap.RDWR, 0, 0)
if err != nil { if err != nil {
err = fmt.Errorf("mapping file %q, length %d: %s", file.Name(), size, err) err = fmt.Errorf("error mapping region: %s", err)
return return
} }
if int64(len(ret)) != size { if int64(len(ret)) != size {
panic("mmap has wrong length") panic(len(ret))
} }
return return
} }