1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
10 Mappable
* Mappable::Create(const char* path
) {
11 int fd
= open(path
, O_RDONLY
);
12 if (fd
!= -1) return new Mappable(fd
);
16 MemoryRange
Mappable::mmap(const void* addr
, size_t length
, int prot
, int flags
,
18 MOZ_ASSERT(fd
&& *fd
!= -1);
19 MOZ_ASSERT(!(flags
& MAP_SHARED
));
22 return MemoryRange::mmap(const_cast<void*>(addr
), length
, prot
, flags
, *fd
,
26 void Mappable::finalize() {
27 /* Close file ; equivalent to close(fd.forget()) */
31 size_t Mappable::GetLength() const {
33 return fstat(*fd
, &st
) ? 0 : st
.st_size
;