-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix mmap_array with offset on Windows #7242
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,25 +127,29 @@ function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::IO, offset::File | |
ro = isreadonly(s) | ||
flprotect = ro ? 0x02 : 0x04 | ||
len = prod(dims)*sizeof(T) | ||
const granularity::Int = ccall(:jl_getallocationgranularity, Clong, ()) | ||
if len < 0 | ||
error("requested size is negative") | ||
end | ||
if len > typemax(Int) | ||
if len > typemax(Int)-granularity | ||
error("file is too large to memory-map on this platform") | ||
end | ||
# Set the offset to a page boundary | ||
offset_page::FileOffset = ifloor(offset/granularity)*granularity | ||
szarray = convert(Csize_t, len) | ||
szfile = szarray + convert(Csize_t, offset) | ||
szfile = szarray + convert(Csize_t, offset-offset_page) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is szfile? Looks like it used to be a pointer to the last byte, and now is a length? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dwMaximumSize - quoting MSDN, "maximum size of the file mapping object" You probably know more about this stuff than I do, I'm not 100% sure I did this right. Still some trouble with HDF5, and when I tried a large offset, but at least this was able to fix the simple case that's currently broken. |
||
mmaphandle = ccall(:CreateFileMappingW, stdcall, Ptr{Void}, (Ptr{Void}, Ptr{Void}, Cint, Cint, Cint, Ptr{Uint16}), | ||
shandle.handle, C_NULL, flprotect, szfile>>32, szfile&0xffffffff, C_NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from reading msdn, it appears that szfile here should = offset + szarray or it can equal 0, without any actual cost (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366542(v=vs.85).aspx) |
||
if mmaphandle == C_NULL | ||
error("could not create file mapping") | ||
end | ||
access = ro ? 4 : 2 | ||
viewhandle = ccall(:MapViewOfFile, stdcall, Ptr{Void}, (Ptr{Void}, Cint, Cint, Cint, Csize_t), mmaphandle, access, offset>>32, offset&0xffffffff, szarray) | ||
viewhandle = ccall(:MapViewOfFile, stdcall, Ptr{Void}, (Ptr{Void}, Cint, Cint, Cint, Csize_t), | ||
mmaphandle, access, offset_page>>32, offset_page&0xffffffff, szarray) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from reading msdn, it appears that szarray here should be szarray+offset-offset_page
|
||
if viewhandle == C_NULL | ||
error("could not create mapping view") | ||
end | ||
A = pointer_to_array(pointer(T, viewhandle), dims) | ||
A = pointer_to_array(pointer(T, viewhandle+offset-offset_page), dims) | ||
finalizer(A, x->munmap(viewhandle, mmaphandle)) | ||
return A | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,24 @@ long jl_getpagesize(void) | |
} | ||
#endif | ||
|
||
#ifdef _OS_WINDOWS_ | ||
static long cachedAllocationGranularity = 0; | ||
long jl_getallocationgranularity(void) | ||
{ | ||
if (!cachedAllocationGranularity) { | ||
SYSTEM_INFO systemInfo; | ||
GetSystemInfo (&systemInfo); | ||
cachedAllocationGranularity = systemInfo.dwAllocationGranularity; | ||
} | ||
return cachedAllocationGranularity; | ||
} | ||
#else | ||
long jl_getallocationgranularity(void) | ||
{ | ||
return jl_getpagesize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just merge these two functions, since they are only used on their respective platforms? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern there was whether anyone currently uses the page size on Windows. Technically it would be a breaking change to start giving a different answer. |
||
} | ||
#endif | ||
|
||
DLLEXPORT long jl_SC_CLK_TCK(void) | ||
{ | ||
#ifndef _OS_WINDOWS_ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use idiv instead?