]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/binmiscctl/binmiscctl.8
bhyve: Add a slirp network backend
[FreeBSD/FreeBSD.git] / usr.sbin / binmiscctl / binmiscctl.8
1 .\"-
2 .\" Copyright (c) 2013 Stacey D. Son
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" Support for miscellaneous binary image activators
27 .\"
28 .Dd April 30, 2020
29 .Dt BINMISCCTL 8
30 .Os
31 .Sh NAME
32 .Nm binmiscctl
33 .Nd manage binary image activators
34 .Sh SYNOPSIS
35 .Nm
36 .Cm add
37 .Ar name
38 .Fl -interpreter
39 .Ar path
40 .Fl -magic
41 .Ar magic
42 .Fl -size
43 .Ar size
44 .Op Fl -mask Ar mask
45 .Op Fl -offset Ar offset
46 .Op Fl -set-enabled
47 .Op Fl -pre-open
48 .Nm
49 .Cm disable
50 .Ar name
51 .Nm
52 .Cm enable
53 .Ar name
54 .Nm
55 .Cm list
56 .Nm
57 .Cm lookup
58 .Ar name
59 .Nm
60 .Cm remove
61 .Ar name
62 .Sh DESCRIPTION
63 The
64 .Nm
65 utility
66 is the management utility for configuring miscellaneous binaries image
67 activators in the kernel.
68 It allows adding, deleting, disabling,
69 enabling, and looking up interpreters.
70 Also, all the interpreters can
71 be listed.
72 .Pp
73 The first argument on the command line indicates the operation to be
74 performed.
75 Operation must be one of the following:
76 .Bl -tag -width indent
77 .It Xo
78 .Cm add
79 .Ar name
80 .Fl -interpreter
81 .Ar path
82 .Fl -magic
83 .Ar magic
84 .Fl -size
85 .Ar size
86 .Op Fl -mask Ar mask
87 .Op Fl -offset Ar offset
88 .Op Fl -set-enabled
89 .Op Fl -pre-open
90 .Xc
91 Add a new activator entry in the kernel.
92 You must specify a
93 unique
94 .Ar name ,
95 a
96 .Ar path
97 to the interpreter,
98 header
99 .Ar magic
100 bytes that uniquely identify a suitable binary for the activator,
101 and the
102 .Ar size
103 of the
104 .Ar magic
105 in bytes.
106 .Pp
107 Optionally, you may specify a
108 .Ar mask
109 to do a bitwise AND with the header bytes.
110 This effectively allows you to ignore fields in the binary header that
111 do not uniquely indentify the binary file's type.
112 .Pp
113 An
114 .Ar offset
115 may be specified for the magic bytes using the
116 .Fl -offset
117 option.
118 By default the
119 .Ar offset
120 is zero.
121 .Pp
122 To enable the activator entry the
123 .Fl -set-enabled
124 option is used.
125 The activator default state is disabled.
126 .Pp
127 To make the interpreter automatically available in jails and chroots,
128 use the
129 .Fl -pre-open
130 option to allow the kernel to open the binary at configuration time
131 rather then lazily when the the interpreted program is started.
132 .Pp
133 The interpreter
134 .Ar path
135 may also contain arguments for the interpreter including
136 .Ar #a
137 which gets replaced by the old
138 .Dv argv0
139 value in the interpreter string.
140 .It Cm disable Ar name
141 Disable the activator entry identified with
142 .Ar name .
143 .It Cm enable Ar name
144 Enable the activator entry identified with
145 .Ar name .
146 .It Cm list
147 Take a snapshot and print all the activator entries currently configured.
148 .It Cm lookup Ar name
149 Look up and print out the activator entry identified with
150 .Ar name .
151 .It Cm remove Ar name
152 Remove the activator entry identified with
153 .Ar name .
154 .El
155 .Sh EXAMPLES
156 Add an image activator to run the LLVM interpreter
157 .Po
158 .Xr lli 1
159 .Pc
160 on bitcode
161 compiled files and set its state to enabled.
162 In this example
163 .Ar #a
164 is replaced with the old
165 .Dv argv0
166 value so that
167 .Xr lli 1
168 can fake its
169 .Dv argv0 :
170 .Bd -literal -offset indent
171 # binmiscctl add llvmbc --interpreter ''/usr/bin/lli \e
172   --fake-argv0=#a'' --magic ''BC\\xc0\\xde'' --size 4 \e
173   --set-enabled
174 .Ed
175 .Pp
176 Set the state of the
177 .Ar llvmbc
178 image activator to disabled:
179 .Bd -literal -offset indent
180 # binmiscctl disable llvmbc
181 .Ed
182 .Pp
183 Set the state of the
184 .Ar llvmbc
185 image activator to enabled:
186 .Bd -literal -offset indent
187 # binmiscctl enable llvmbc
188 .Ed
189 .Pp
190 Delete the
191 .Ar llvmbc
192 image activator:
193 .Bd -literal -offset indent
194 # binmiscctl remove llvmbc
195 .Ed
196 .Pp
197 Look up and list the record for the
198 .Ar llvmbc
199 image activator:
200 .Bd -literal -offset indent
201 # binmiscctl lookup llvmbc
202 .Ed
203 .Pp
204 Add QEMU bsd-user program as an image activator for ARM AARCH64 binaries:
205 .Bd -literal -offset indent
206 # binmiscctl add arm64 \e
207   --interpreter "/usr/local/bin/qemu-aarch64-static" \e
208   --magic "\ex7f\ex45\ex4c\ex46\ex02\ex01\ex01\ex00\ex00\ex00\e
209            \ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\exb7\ex00" \e
210   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
211            \exff\exff\exff\exff\exff\exff\exfe\exff\exff\exff" \e
212   --size 20 --set-enabled
213 .Ed
214 .Pp
215 Add QEMU bsd-user program as an image activator for ARM little-endian binaries:
216 .Bd -literal -offset indent
217 # binmiscctl add armelf \e
218   --interpreter "/usr/local/bin/qemu-arm-static" \e
219   --magic "\ex7f\ex45\ex4c\ex46\ex01\ex01\ex01\ex00\ex00\ex00\e
220            \ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex28\ex00" \e
221   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
222            \exff\exff\exff\exff\exff\exff\exfe\exff\exff\exff" \e
223   --size 20 --set-enabled
224 .Ed
225 .Pp
226 Add QEMU bsd-user program as an image activator for ARM big-endian binaries:
227 .Bd -literal -offset indent
228 # binmiscctl add armebelf \e
229   --interpreter "/usr/local/bin/qemu-arm-static" \e
230   --magic "\ex7f\ex45\ex4c\ex46\ex01\ex02\ex01\ex00\ex00\ex00\e
231            \ex00\ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex28" \e
232   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
233            \exff\exff\exff\exff\exff\exff\exff\exfe\exff\exff" \e
234   --size 20 --set-enabled
235 .Ed
236 .Pp
237 Add QEMU bsd-user program as an image activator for MIPS32 binaries:
238 .Bd -literal -offset indent
239 # binmiscctl add mips32 \e
240   --interpreter "/usr/local/bin/qemu-mips-static" \e
241   --magic "\ex7f\ex45\ex4c\ex46\ex01\ex02\ex01\ex00\ex00\ex00\e
242            \ex00\ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex08" \e
243   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
244            \exff\exff\exff\exff\exff\exff\exff\exfe\exff\exff" \e
245   --size 20 --set-enabled
246 .Ed
247 .Pp
248 Add QEMU bsd-user program as an image activator for MIPS64 binaries:
249 .Bd -literal -offset indent
250 # binmiscctl add mips64 \e
251   --interpreter "/usr/local/bin/qemu-mips64-static" \e
252   --magic "\ex7f\ex45\ex4c\ex46\ex02\ex02\ex01\ex00\ex00\ex00\e
253            \ex00\ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex08" \e
254   --mask "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
255           \exff\exff\exff\exff\exff\exff\exff\exfe\exff\exff" \e
256   --size 20 --set-enabled
257 .Ed
258 .Pp
259 Add QEMU bsd-user program as an image activator for PowerPC binaries:
260 .Bd -literal -offset indent
261 # binmiscctl add powerpc \e
262   --interpreter "/usr/local/bin/qemu-ppc-static" \e
263   --magic "\ex7f\ex45\ex4c\ex46\ex01\ex02\ex01\ex00\ex00\ex00\e
264            \ex00\ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex14" \e
265   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
266            \exff\exff\exff\exff\exff\exff\exff\exfe\exff\exff" \e
267   --size 20 --set-enabled
268 .Ed
269 .Pp
270 Add QEMU bsd-user program as an image activator for PowerPC64 binaries:
271 .Bd -literal -offset indent
272 # binmiscctl add powerpc64 \e
273   --interpreter "/usr/local/bin/qemu-ppc64-static" \e
274   --magic "\ex7f\ex45\ex4c\ex46\ex02\ex02\ex01\ex00\ex00\ex00\e
275            \ex00\ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\ex15" \e
276   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
277            \exff\exff\exff\exff\exff\exff\exff\exfe\exff\exff" \e
278   --size 20 --set-enabled
279 .Ed
280 .Pp
281 Add QEMU bsd-user program as an image activator for 64-bit RISC-V binaries:
282 .Bd -literal -offset indent
283 # binmiscctl add riscv64 \e
284   --interpreter "/usr/local/bin/qemu-riscv64-static" \e
285   --magic "\ex7f\ex45\ex4c\ex46\ex02\ex01\ex01\ex00\ex00\ex00\e
286            \ex00\ex00\ex00\ex00\ex00\ex00\ex02\ex00\exf3\ex00" \e
287   --mask  "\exff\exff\exff\exff\exff\exff\exff\ex00\exff\exff\e
288            \exff\exff\exff\exff\exff\exff\exfe\exff\exff\exff" \e
289   --size 20 --set-enabled
290 .Ed
291 .Ss "Create and use an ARMv6 chroot on an AMD64 host"
292 Use an existing source tree to build a chroot host with architecture
293 overrides:
294 .Bd -literal -offset ident
295 D=/path/to/chroot
296 cd /usr/src
297 mkdir -p $D
298 make world TARGET=arm TARGET_ARCH=armv6 DESTDIR=$D
299 make distribution TARGET=arm TARGET_ARCH=armv6 DESTDIR=$D
300 .Ed
301 .Pp
302 With
303 .Pa emulators/qemu-user-static
304 from the
305 .Fx
306 Ports Collection, the emulator must be copied into the jail path
307 specified in the
308 .Nm
309 command.
310 Using the example above:
311 .Bd -literal -offset -ident
312 mkdir $D/usr/local/bin
313 cp /usr/local/bin/qemu-arm-static $D/usr/local/bin
314 .Ed
315 .Pp
316 Now the user can chroot into the environment normally, as root:
317 .Bd -literal -offset -ident
318 chroot $D
319 .Ed
320 .Sh SEE ALSO
321 .Xr lli 1 ,
322 .Xr execve 2 ,
323 .Xr jail 8
324 .Sh HISTORY
325 The
326 .Nm
327 command was added in
328 .Fx 10.1 .
329 It was developed to support the imgact_binmisc kernel module.
330 .Sh AUTHORS
331 .An Stacey D Son Aq Mt sson@FreeBSD.org