diff --git a/package.json b/package.json index e02992b..f352963 100644 --- a/package.json +++ b/package.json @@ -17,23 +17,19 @@ "bugs": { "url" : "http://github.com/ozra/mmap-io/issues" }, - "scripts": { - "prepublish": "make ls", + "prepare": "lsc -b -c -o ./ src/mmap-io.ls src/test.ls", "install": "node-gyp configure && node-gyp rebuild", "test": "node ./test.js" }, - "devDependencies": { "errno": "*", "LiveScript": "1.*.*" }, - "dependencies": { "bindings": "1.*.*", "nan": "2.*.*" }, - "main": "mmap-io", "engines": { "node": ">=0.10.0" diff --git a/src/mman.h b/src/mman.h index 7b8e979..78540dc 100644 --- a/src/mman.h +++ b/src/mman.h @@ -50,11 +50,11 @@ inline void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t 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 & 0xFFFFFFFFL) : DWORD(0); + 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 & 0xFFFFFFFFL) : DWORD(0); + const DWORD dwOffsetHigh = (sizeof(off_t) > sizeof(DWORD)) ? DWORD((offset >> 32) & 0xFFFFFFFFL) : DWORD(0); - HANDLE h = (fd == -1) ? HANDLE(_get_osfhandle(fd)) : INVALID_HANDLE_VALUE; + HANDLE h = (fd != -1) ? HANDLE(uv_get_osfhandle(fd)) : INVALID_HANDLE_VALUE; HANDLE fm = CreateFileMapping(h, nullptr, protect, dwEndHigh, dwEndLow, nullptr); if (fm == nullptr) return MAP_FAILED; @@ -94,3 +94,8 @@ inline int msync(void* addr, size_t length, int flags) { inline int madvise(void* addr, size_t length, int advice) { return 0; // Unsupported on Windows } + +inline int mincore(void *addr, size_t length, unsigned char *vec) { + errno = ENOSYS; + return -1; +} diff --git a/src/mmap-io.cc b/src/mmap-io.cc index df8252d..86aad2c 100644 --- a/src/mmap-io.cc +++ b/src/mmap-io.cc @@ -183,10 +183,13 @@ JS_FN(mmap_incore) { } int ret = mincore(data, size, resultData); - if (ret) { free(resultData); - return Nan::ThrowError((std::string("mincore() failed, ") + std::to_string(errno)).c_str()); + if (errno == ENOSYS) { + return Nan::ThrowError("mincore() not implemented"); + } else { + return Nan::ThrowError((std::string("mincore() failed, ") + std::to_string(errno)).c_str()); + } } // Now we want to check all of the pages diff --git a/src/test.ls b/src/test.ls index dabcbdd..ca6a545 100644 --- a/src/test.ls +++ b/src/test.ls @@ -3,6 +3,7 @@ # Some lines snatched from Ben Noordhuis test-script of "node-mmap" fs = require "fs" +os = require "os" #mmap = require "./build/Release/mmap-io.node" mmap = require "./mmap-io" assert = require "assert" @@ -46,13 +47,15 @@ try for ix from (size - 1) to 0 by -1 out += String.from-char-code(buffer[ix]) + # not implemented on Win32 incore_stats = mmap.incore(buffer) assert.equal(incore_stats[0], 0) assert.equal(incore_stats[1], 2) #say out, "\n\n" catch e - assert false, "Shit happened while reading from buffer" + if e.message != 'mincore() not implemented' + assert false, "Shit happened while reading from buffer" try say "read out of bounds test" @@ -82,10 +85,14 @@ assert.equal(buffer.length, size) # Snatched from Ben Noordhuis test-script: # page size is almost certainly >= 4K and this script isn't that large... -fd = fs.open-sync(process.argv[1], 'r') -buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, PAGESIZE) -say "buflen test 3 = ", buffer.length -assert.equal(buffer.length, size); # ...but this is according to spec +if os.type() != 'Windows_NT' + # XXX: this will always fail on Windows, as it requires that offset be a + # multiple of the dwAllocationGranularity, which is NOT the same as the + # pagesize. In addition, the offset+length can't exceed the file size. + fd = fs.open-sync(process.argv[1], 'r') + buffer = mmap.map(size, PROT_READ, MAP_SHARED, fd, PAGESIZE) + say "buflen test 3 = ", buffer.length + assert.equal(buffer.length, size); # ...but this is according to spec # non int param should throw exception fd = fs.open-sync(process.argv[1], 'r')