Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005463OCaml~DO NOT USE (was: OCaml general)public2012-01-04 09:442013-08-31 12:49
ReporterMartin Jambon 
Assigned To 
PlatformOSLinuxOS Version2.6.34
Product Version3.12.1 
Target VersionFixed in Version4.00.0+dev 
Summary0005463: map_file fails to map to empty bigarray
DescriptionBigarray.Array1.map_file fails if the array to be created is empty. This is a slight annoyance because it is not documented in the manual. I don't know where the various implementations of mmap stand, but a warning note would be welcome if a fix is not possible.

On Linux, "man mmap" says in the ERRORS section:

       EINVAL (since Linux 2.6.12) length was 0.
Steps To Reproduce$ cat >
(* ocamlopt -o mapfile unix.cmxa bigarray.cmxa *)
let empty = Filename.temp_file "empty" ".dat";;
let fd = Unix.openfile empty [Unix.O_RDONLY] 0;;
Bigarray.Array1.map_file fd Bigarray.char Bigarray.c_layout false 0

$ ocamlopt -o mapfile unix.cmxa bigarray.cmxa
$ ./mapfile
Fatal error: exception Sys_error("Invalid argument")
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
dbuenzli (reporter)
2012-01-04 10:44


> uname -v
Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386

the man says :


     mmap() now returns with errno set to EINVAL in places that historically
     succeeded. The rules have changed as follows:

     o The flags parameter must specify either MAP_PRIVATE or MAP_SHARED.

     o The size parameter must not be 0.

     o The off parameter must be a multiple of pagesize, as returned by
gerd (reporter)
2012-01-04 14:18

@dbuenzli: map_file allows it to map files at offsets that are not a multiple of the pagesize. This is done by rounding down to the next multiple, and hiding the intitial part of the mapping from the user. What I want to say is that it does not necessarily matter what mmap allows when there is a way to emulate more general behavior.

I think an emulation for size=0 is very easy - just return the empty array instead (don't call mmap at all).
xleroy (administrator)
2012-01-17 16:31

Thanks for the analysis. The proposed fix looks good to me. To be implemented some day.
xleroy (administrator)
2012-04-09 12:26

Gerd's solution implemented in commit 12326 in version/4.00, 12327 in trunk.

- Issue History
Date Modified Username Field Change
2012-01-04 09:44 Martin Jambon New Issue
2012-01-04 10:44 dbuenzli Note Added: 0006587
2012-01-04 14:18 gerd Note Added: 0006588
2012-01-17 16:31 xleroy Note Added: 0006698
2012-01-17 16:31 xleroy Status new => confirmed
2012-04-09 12:26 xleroy Note Added: 0007299
2012-04-09 12:26 xleroy Status confirmed => resolved
2012-04-09 12:26 xleroy Resolution open => fixed
2012-04-09 12:26 xleroy Fixed in Version => 4.00.0+dev
2013-08-31 12:49 xleroy Status resolved => closed
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker