Skip to content

Commit

Permalink
Merge pull request #15 from bmarkiv/master
Browse files Browse the repository at this point in the history
In order to support file size over 4GB type off_t used for offset par…
  • Loading branch information
ozra committed Mar 8, 2019
2 parents dde403a + 6b6c73c commit ad5752d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/mman.h
Expand Up @@ -25,7 +25,7 @@
#define MADV_WILLNEED 0x03
#define MADV_DONTNEED 0x04

inline void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
inline void* mmap(void* addr, size_t length, int prot, int flags, int fd, size_t offset) {
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
return MAP_FAILED;
if (fd == -1) {
Expand All @@ -48,11 +48,11 @@ inline void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t
} else
protect = PAGE_READONLY;

off_t end = length + offset;
const DWORD dwEndLow = (sizeof(off_t) > sizeof(DWORD)) ? DWORD(end & 0xFFFFFFFFL) : DWORD(end);
const DWORD dwEndHigh = (sizeof(off_t) > sizeof(DWORD)) ? DWORD((end >> 32) & 0xFFFFFFFFL) : DWORD(0);
const DWORD dwOffsetLow = (sizeof(off_t) > sizeof(DWORD)) ? DWORD(offset & 0xFFFFFFFFL) : DWORD(offset);
const DWORD dwOffsetHigh = (sizeof(off_t) > sizeof(DWORD)) ? DWORD((offset >> 32) & 0xFFFFFFFFL) : DWORD(0);
size_t end = length + offset;
const DWORD dwEndLow = (sizeof(size_t) > sizeof(DWORD)) ? DWORD(end & 0xFFFFFFFFL) : DWORD(end);
const DWORD dwEndHigh = (sizeof(size_t) > sizeof(DWORD)) ? DWORD((end >> 32) & 0xFFFFFFFFL) : DWORD(0);
const DWORD dwOffsetLow = (sizeof(size_t) > sizeof(DWORD)) ? DWORD(offset & 0xFFFFFFFFL) : DWORD(offset);
const DWORD dwOffsetHigh = (sizeof(size_t) > sizeof(DWORD)) ? DWORD((offset >> 32) & 0xFFFFFFFFL) : DWORD(0);

HANDLE h = (fd != -1) ? HANDLE(uv_get_osfhandle(fd)) : INVALID_HANDLE_VALUE;
HANDLE fm = CreateFileMapping(h, nullptr, protect, dwEndHigh, dwEndLow, nullptr);
Expand Down
5 changes: 3 additions & 2 deletions src/mmap-io.cc
Expand Up @@ -68,7 +68,7 @@ JS_FN(mmap_map) {
const int protection = info[1]->IntegerValue();
const int flags = info[2]->ToInteger()->Value();
const int fd = info[3]->ToInteger()->Value();
const off_t offset = info[4]->ToInteger()->Value(); // ToInt64()->Value();
const size_t offset = info[4]->ToInteger()->Value(); // ToInt64()->Value();
const int advise = info[5]->ToInteger()->Value();

char* data = static_cast<char*>( mmap( hinted_address, size, protection, flags, fd, offset) );
Expand Down Expand Up @@ -100,7 +100,8 @@ JS_FN(mmap_map) {
}

auto map_info = new MMap(data, size);
Nan::MaybeLocal<Object> buf = Nan::NewBuffer(data, size, do_mmap_cleanup, static_cast<void*>(map_info));
Nan::MaybeLocal<Object> buf = node::Buffer::New(
v8::Isolate::GetCurrent(), data, size, do_mmap_cleanup, static_cast<void*>(map_info));
if (buf.IsEmpty()) {
return Nan::ThrowError(std::string("couldn't allocate Node Buffer()").c_str());
} else {
Expand Down

0 comments on commit ad5752d

Please sign in to comment.