[Mono-docs-list] Question about EXE binaries and kernels?

Felipe Alfaro Solana felipe_alfaro@linuxmail.org
Wed, 07 Apr 2004 01:20:50 +0200


On Tue, 2004-04-06 at 23:57, Aaron Weber wrote:

> Thanks for the explanation. How's this sound?

This looks really good. Please take a look at the end of the e-mail for
some additional comments.

> 
> 
> The normal way to run a Mono application is to invoke it through the
> interpreter, like so:
> 
> mono myprogram.exe

> However, there are two things you can do to make it more convenient to
> run Mono applications. The first is to use a shell script instead of
> the EXE file. For example, if you had "myprogram.exe" you could create
> a shell script called "myprogram" that had the contents: 
> 
>        #!/bin/sh
>        /usr/bin/mono myprogram.exe
>      
> If you installed mono to a different location, substitute that for
> /usr/bin/mono. You can check with the "which mono" command. 
> 
> You can also make a systemwide change, and use binfmt to register the
> exe files as non-native binaries. Then, when trying to launch an exe
> file, the kernel will run the mono interpreter to handle the command.
> Binfmt can also be used to launch Windows executables using WINE, or
> Java .class files using a JVM. To register exe with the kernel: 

>      1. Turn on binfmt in your kernel. 
      1.1. If you choose to enable binfmt as a module, you'll need
           to manually load it by running

           modprobe binfmt

           as root. Usually, you will want to place the previous
           command inside the boot script, for example /etc/rc.local
           so the module gets loaded during boot.

>      1. Add the line below to your fstab: 
>         binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc none
>      2. Then, have your system run the following command on boot: 
>         echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register

          This is usually placed inside a boot script, like
          /etc/rc.local, for example, so it gets invoked automatically
          at startup.

>      1. Be sure to mark your .exe files as executable in the
>         filesystem as well:
>         chmod +x myprogram.exe

Also, it would be interesing to state that enabling BINFMT support
shouldn't create any compatibility or interaction problem between EXE
files, the MONO CLR and the kernel, and shouldn't pose any problems when
upgrading MONO CLR or the kernel itself, since the process of launching
and running the EXE file is handled by a userspace program,
/usr/bin/mono, that is, the MONO CLR. Thus, this will work with any
BINFMT-enabled kernel, such as 2.4.x and 2.6.x kernels.

Recently, I submitted a patch against the 2.6.5 kernel that describes
process exactly in the same way as you did in the previous e-mail. It's
already upstream so anyone working with a 2.6.5 kernel can also have
this handy steps at a well-known place: Documentation/mono.txt and
inside the kernel config help text.

Thanks!