linux-old/Documentation/binfmt_misc.txt
<<
>>
Prefs
   1     Kernel Support for miscellaneous (your favourite) Binary Formats v1.1
   2     =====================================================================
   3
   4This Kernel feature allows you to invoke almost (for restrictions see below)
   5every program by simply typing its name in the shell.
   6This includes for example compiled Java(TM), Python or Emacs programs.
   7
   8To achieve this you must tell binfmt_misc which interpreter has to be invoked
   9with which binary. Binfmt_misc recognises the binary-type by matching some bytes
  10at the beginning of the file with a magic byte sequence (masking out specified
  11bits) you have supplied. Binfmt_misc can also recognise a filename extension
  12aka '.com' or '.exe'.
  13
  14To 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
  16your needs) and echo it to /proc/sys/fs/binfmt_misc/register.
  17Here 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
  35There 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
  41You may want to add the binary formats in one of your /etc/rc scripts during
  42boot-up. Read the manual of your init program to figure out how to do this
  43right.
  44
  45Think about the order of adding entries! Later added entries are matched first!
  46
  47
  48A 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
  60For java support see Documentation/java.txt
  61
  62
  63You can enable/disable binfmt_misc or one binary type by echoing 0 (to disable)
  64or 1 (to enable) to /proc/sys/fs/binfmt_misc/status or /proc/.../the_name.
  65Catting the file tells you the current status of binfmt_misc/the entry.
  66
  67You can remove one entry or all entries by echoing -1 to /proc/.../the_name
  68or /proc/sys/fs/binfmt_misc/status.
  69
  70
  71HINTS:
  72======
  73
  74If you want to pass special arguments to your interpreter, you can
  75write a wrapper script for it. See Documentation/java.txt for an
  76example.
  77
  78Your interpreter should NOT look in the PATH for the filename; the
  79kernel passes it the full filename to use.  Using the PATH can cause
  80unexpected behaviour and be a security hazard.
  81
  82
  83There is a web page about binfmt_misc at
  84http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html
  85
  86Richard Günther <rguenth@tat.physik.uni-tuebingen.de>
  87
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.