Skip to content
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

Bigarray.*.map_file doesn't work with some offsets on Windows #5184

Closed
vicuna opened this issue Nov 29, 2010 · 3 comments
Closed

Bigarray.*.map_file doesn't work with some offsets on Windows #5184

vicuna opened this issue Nov 29, 2010 · 3 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 29, 2010

Original bug ID: 5184
Reporter: Vadim_Z
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2012-09-25T18:06:17Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.2
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @ygrek

Bug description

The function map_file from submodules of Bigarray module doesn't work as expected on Windows platform with some values of ~pos argument. Here's the example:

(* ======================================================= *)
open Bigarray ;;
open Unix ;;

let fd= openfile "z.out" [O_RDWR; O_CREAT; O_TRUNC] 0o666 in
begin
let arr = Array1.map_file fd ~pos:(Int64.of_int 4096)
int c_layout true 1 in
arr.{0} <- 10
end;
close fd
;;
(* ======================================================= *)

Instead of writing the number to file the program yields:
Fatal error: exception Sys_error("The base address or the file offset specified does not have the proper alignment.
")

There's no such problem on Unix environment.

Additional information

The problem is caused by the following: dwPageSize is used instead of dwAllocationGranularity as a unit when offset is determined for CreateFileMapping in file mmap_win32.c.

Replacing dwPageSize by dwAllocationGranularity everywhere in mmap_win32.c and recompilation of Bigarray library solved the problem for me.

@vicuna
Copy link
Author

vicuna commented May 20, 2011

Comment author: @damiendoligez

I can't reproduce this on windows 7 and cygwin with 3.12.0 or 3.11.2.
Is this with mingw or the native MS port ?

@vicuna
Copy link
Author

vicuna commented May 20, 2011

Comment author: Vadim_Z

I've seen this behavior for native MS port. I expect that mingw port also fails there, as it uses the same file mmap_win32.c.

On the other side, Cygwin port doesn't have this deficiency as it uses file mmap_unix.c and mmap function provided by the Cygwin environment.

@vicuna
Copy link
Author

vicuna commented Jun 4, 2011

Comment author: @xavierleroy

Suggested fix to mmap_win32.c applied in 3.12 bugfix branch, will go in 3.12.1. Not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants