Skip to content

Commit

Permalink
Scan windows address space marginally more cleverly (less dumbly?)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffleyland committed Dec 20, 2016
1 parent 4a37b59 commit 30b478b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src-lua/mmapfile/windows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ local function mmap_4G(
local base = 4 * 1024 * 1024 * 1024
local step = 0x10000
local addr
for _ = 1, 16 do
for _ = 1, 32 do
addr = ffi.C.MapViewOfFileEx(map, access, 0, offset, size, ffi.cast("void*", base))

if addr >= ffi.cast("void*", 4 * 1024 * 1024 * 1024) then break end
if addr ~= nil then
ffi.C.UnmapViewOfFile(addr)
end
base = base + step
step = step * 2
step = math.min(2^26, step * 2) -- 64MB should be a pretty good step, right?
end
return addr
end
Expand Down Expand Up @@ -308,12 +308,12 @@ local function open(

local map = ffi.C.CreateFileMappingA(fd, nil, mapmode, 0, size, nil)
if map == nil then
error(("mmapfile.create: Error creating %s: %s"):format(filename, last_error_string()))
error(("mmapfile.open: Error opening %s: %s"):format(filename, last_error_string()))
end

local addr = mmap_4G(map, 0, ptrmode, offset)
if addr == nil then
error(("mmapfile.create: Error creating %s: %s"):format(filename, last_error_string()))
error(("mmapfile.open: Error opening %s: %s"):format(filename, last_error_string()))
end

open_fds[tostring(ffi.cast("void*", addr))] = { fd = fd, map = map }
Expand Down

0 comments on commit 30b478b

Please sign in to comment.