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