Debian Codegraph @

doc/detectors

raw
1 From: Colin Watson <[email protected]>
2 To: Ove Kaaven
3 Cc: Alp Toker
4 Subject: Cooperation between Mono and Wine for binary formats
5
6 The following is a specification for extended binary format
7 specifications in binfmt-support. It is being written to support the
8 needs of the Mono packages. The .NET binary format is sufficiently
9 similar to that used by Wine for ordinary Win32 executables that the
10 decision on which to use is beyond the support provided by the
11 binfmt_misc kernel module and needs to be delegated to a userspace
12 process.
13
14 (This necessarily involves making things a little more convoluted, but I
15 hope not by too much. Bear with me.)
16
17
18 A new command-line option, and corresponding format file option, is
19 added, namely --detector. If this option is present, it is to be
20 followed by the full path to an executable. If all other conditions in a
21 binary format specification succeed, this executable will be run with
22 the path to the binary in question as its first argument before the
23 interpreter is considered for execution.
24
25 Several different detector/interpreter pairs may be present with
26 otherwise identical format strings. Each detector is run in turn, in a
27 currently unspecified order, until one succeeds, i.e. returns a zero
28 exit status. The corresponding interpreter will then be run as normal.
29 If several identical format strings are present with no detector, they
30 will be considered to have a detector of /bin/true which is run last of
31 all (this may help with transitions).
32
33 Implementation notes: If any detectors are present for a given
34 kernel-level format, then /usr/lib/binfmt-support/run-detectors (or
35 similar) is called instead of the usual interpreter. This calls each
36 configured detector in turn and then execv()'s the first interpreter
37 that succeeds. If none succeed, it prints an error message and exits
38 non-zero.
39
40 As far as wine is concerned, the modification should be as follows: add
41 /usr/lib/wine/binfmt-detector-wine or similar with the Win32 format
42 detection code (Alp has the details of this, it's a few dozen lines of
43 C), and add 'detector /usr/lib/wine/binfmt-detector-wine' to
44 /usr/share/binfmts/wine.
45
46
47 The intention of all this is that users can run a random Windows
48 executable with the MZ magic string and it will be passed off
49 transparently to the appropriate interpreter, while keeping the
50 packaging as simple as possible and avoiding the need for extra bridging
51 packages (the original idea of having a single program that knows how to
52 tell between Win32 and .NET executables and hands them off accordingly
53 would have required an extra package and associated cruft in
54 dependencies/suggestions).
55
56 The Wine package doesn't need to be modified under this scheme in order
57 for Mono to work, due to the /bin/true shim for format strings without
58 detectors, so the transition can be quite painless. However, unless it
59 is modified, binfmt_misc will attempt to run Wine over .NET executables
60 if Mono is not installed.