Allow '/dev/zero' to be mapped with unaligned length

PiperOrigin-RevId: 212321271
Change-Id: I79d71c2e6f4b8fcd3b9b923fe96c2256755f4c48
This commit is contained in:
Fabricio Voznika
2018-09-10 13:24:55 -07:00
committed by Shentubot
parent da9ecb748c
commit 7e9e6745ca
+7 -2
View File
@@ -138,10 +138,15 @@ func (m *SpecialMappable) Length() uint64 {
// uses an ephemeral file created by mm/shmem.c:shmem_zero_setup(); we should
// do the same to get non-zero device and inode IDs.
func NewSharedAnonMappable(length uint64, p platform.Platform) (*SpecialMappable, error) {
if length == 0 || length != uint64(usermem.Addr(length).RoundDown()) {
if length == 0 {
return nil, syserror.EINVAL
}
fr, err := p.Memory().Allocate(length, usage.Anonymous)
alignedLen, ok := usermem.Addr(length).RoundUp()
if !ok {
return nil, syserror.EINVAL
}
fr, err := p.Memory().Allocate(uint64(alignedLen), usage.Anonymous)
if err != nil {
return nil, err
}