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