summaryrefslogtreecommitdiff
path: root/glibc/mmap.mdwn
blob: 09b0b65df9affa1a557637f7f33f1abf7c4c98d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
[[!meta copyright="Copyright © 2012 Free Software Foundation, Inc."]]

[[!meta license="""[[!toggle id="license" text="GFDL 1.2+"]][[!toggleable
id="license" text="Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no Invariant
Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of the license
is included in the section entitled [[GNU Free Documentation
License|/fdl]]."]]"""]]

There are two implementations of `mmap` for GNU Hurd:
`sysdeps/mach/hurd/mmap.c` (main implementation) and
`sysdeps/mach/hurd/dl-sysdep.c` (*Minimal mmap implementation sufficient for
initial loading of shared libraries.*).

  * `MAP_COPY`

    What exactly is that?  `elf/dl-load.c` has some explanation.
    <http://lkml.indiana.edu/hypermail/linux/kernel/0110.1/1506.html>

    It is only handled in `dl-sysdep.c`, when `flags & (MAP_COPY|MAP_PRIVATE)`
    is used for `vm_map`'s `copy` parameter, and `mmap.c` uses `! (flags &
    MAP_SHARED)` instead, which seems inconsistent?


# `io_map` Failure

This is the [[libnetfs: `io_map`|open_issues/libnetfs_io_map]] issue.

[[!tag open_issue_glibc]]

Review of `mmap` usage in generic bits of glibc, based on
a1bcbd4035ac2483dc10da150d4db46f3e1744f8 (2012-03-11), listing these cases
where failure (due to `io_map` failing; that is, invocations where a `fd` is
passed) is not properly handled.

`catgets/open_catalog.c`, `iconv/gconv_cache.c`, `intl/loadmsgcat.c`,
`locale/loadlocale.c` have fallback code for the `MAP_FAILED` case.

[[tschwinge]]'s current plan is to make the following cases do the same (if
that is possible); probably by introducing a generic `mmap_or_read` function,
that first tries `mmap` (and that will succeed on Linux-based systems and also
on Hurd-based, if it's backed by [[hurd/libdiskfs]]), and if that fails tries
`mmap` on anonymous memory and then fills it by `read`ing the required data.
This is also what the [[hurd/exec]] server is doing (and is the reason that the
`./true` invocation on [[libnetfs: `io_map`|open_issues/libnetfs_io_map]]
works, to my understanding): see `exec.c:prepare`, if `io_map` fails,
`e->filemap == MACH_PORT_NULL`; then `exec.c:map` (as invoked from
`exec.c:load_section`, `exec.c:check_elf`, `exec.c:do_exec`, or
`hashexec.c:check_hashbang`) will use `io_read` instead.

Doing so potentially means reading in a lot of unused data -- but we probably
can't do any better?

In parallel (or even alternatively?), it should be researched how Linux (or any
other kernel) implements `mmap` on NFS and similar file systems, and then
implement the same in [[hurd/libnetfs]] and/or [[hurd/translator/nfs]], etc.

Here, also probably the whole mapping region [has to be
read](http://lists.gnu.org/archive/html/bug-hurd/2001-10/msg00306.html) at
`mmap` time.

List of files without fallback code for the *`MAP_FAILED` due to `io_map`
failed* case:

  * `elf/cache.c`

  * `elf/dl-load.c`

  * `elf/dl-misc.c`

  * `elf/dl-profile.c`

  * `elf/readlib.c`

  * `elf/sprof.c`

  * `locale/loadarchive.c`

  * `locale/programs/locale.c`

  * `locale/programs/locarchive.c`

  * `nscd/connections.c`

  * `nscd/nscd_helper.c`

  * `nss/makedb.c`

  * `nss/nss_db/db-open.c`

  * Omitted:

      * `nptl/`

      * `sysdeps/unix/sparc/`

      * `sysdepts/unix/sysv/linux/`