The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/Documentation/binfmt_misc.txt

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1      Kernel Support for miscellaneous (your favourite) Binary Formats v1.1
    2      =====================================================================
    3 
    4 This Kernel feature allows you to invoke almost (for restrictions see below)
    5 every program by simply typing its name in the shell.
    6 This includes for example compiled Java(TM), Python or Emacs programs.
    7 
    8 To achieve this you must tell binfmt_misc which interpreter has to be invoked
    9 with which binary. Binfmt_misc recognises the binary-type by matching some bytes
   10 at the beginning of the file with a magic byte sequence (masking out specified
   11 bits) you have supplied. Binfmt_misc can also recognise a filename extension
   12 aka '.com' or '.exe'.
   13 
   14 To actually register a new binary type, you have to set up a string looking like
   15 :name:type:offset:magic:mask:interpreter: (where you can choose the ':' upon
   16 your needs) and echo it to /proc/sys/fs/binfmt_misc/register.
   17 Here is what the fields mean:
   18  - 'name' is an identifier string. A new /proc file will be created with this
   19    name below /proc/sys/fs/binfmt_misc
   20  - 'type' is the type of recognition. Give 'M' for magic and 'E' for extension.
   21  - 'offset' is the offset of the magic/mask in the file, counted in bytes. This
   22    defaults to 0 if you omit it (i.e. you write ':name:type::magic...')
   23  - 'magic' is the byte sequence binfmt_misc is matching for. The magic string
   24    may contain hex-encoded characters like \x0a or \xA4. In a shell environment
   25    you will have to write \\x0a to prevent the shell from eating your \.
   26    If you chose filename extension matching, this is the extension to be
   27    recognised (without the '.', the \x0a specials are not allowed). Extension
   28    matching is case sensitive!
   29  - 'mask' is an (optional, defaults to all 0xff) mask. You can mask out some
   30    bits from matching by supplying a string like magic and as long as magic.
   31    The mask is anded with the byte sequence of the file.
   32  - 'interpreter' is the program that should be invoked with the binary as first
   33    argument (specify the full path)
   34 
   35 There are some restrictions:
   36  - the whole register string may not exceed 255 characters
   37  - the magic must reside in the first 128 bytes of the file, i.e.
   38    offset+size(magic) has to be less than 128
   39  - the interpreter string may not exceed 127 characters
   40 
   41 You may want to add the binary formats in one of your /etc/rc scripts during
   42 boot-up. Read the manual of your init program to figure out how to do this
   43 right.
   44 
   45 Think about the order of adding entries! Later added entries are matched first!
   46 
   47 
   48 A few examples (assumed you are in /proc/sys/fs/binfmt_misc):
   49 
   50 - enable support for em86 (like binfmt_em86, for Alpha AXP only):
   51   echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register
   52   echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register
   53 
   54 - enable support for packed DOS applications (pre-configured dosemu hdimages):
   55   echo ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > register
   56 
   57 - enable support for Windows executables using wine:
   58   echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register
   59 
   60 For java support see Documentation/java.txt
   61 
   62 
   63 You can enable/disable binfmt_misc or one binary type by echoing 0 (to disable)
   64 or 1 (to enable) to /proc/sys/fs/binfmt_misc/status or /proc/.../the_name.
   65 Catting the file tells you the current status of binfmt_misc/the entry.
   66 
   67 You can remove one entry or all entries by echoing -1 to /proc/.../the_name
   68 or /proc/sys/fs/binfmt_misc/status.
   69 
   70 
   71 HINTS:
   72 ======
   73 
   74 If you want to pass special arguments to your interpreter, you can
   75 write a wrapper script for it. See Documentation/java.txt for an
   76 example.
   77 
   78 Your interpreter should NOT look in the PATH for the filename; the
   79 kernel passes it the full filename to use.  Using the PATH can cause
   80 unexpected behaviour and be a security hazard.
   81 
   82 
   83 There is a web page about binfmt_misc at
   84 http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html
   85 
   86 Richard Günther <rguenth@tat.physik.uni-tuebingen.de>

Cache object: 5c1fd5299ffed21f7b8f0d9120f1d895


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.