Jan Gray jsgray@acm.org
Fri, 20 Jul 2001 15:19:25 -0400

> Behalf Of Miguel de Icaza

> I wonder if mmap() is supported at all by Cygwin.  I am going to try
> this next.
> The code has special support for dealing with failing mmaps by loading
> the file into memory.  Can you single step through raw_buffer_load and
> see what it does?

Yes.  I just got back to this.  I modified raw_buffer_load() to fail the
mmap() call.  The alternate code which allocs some memory and loads it with
read() works fine.  The assembly loads OK and the SIGSEGV is gone.

However, for the following C# program, compiled with csc 7.00.9254,

class App {
	public static void Main() {
		System.Console.WriteLine("Hello world");

the resulting Main method has 11 bytes of IL.  monodis thinks it has 5.  The
problem appears to be in mono_metadata_parse_mh (metadata/metadata.c line
1209).  The case for format METHOD_HEADER_TINY_FORMAT1 sets mh->code_size to
5 when it should be 11 (e.g. flags is 46).

The current nonfunctioning code agrees with the Tiny Format table spec in
the ECMA draft Partition II Metadata, section 25.2.2.  But that spec looks
broken.  How can you have a format field which is 2 bits wide in some cases
and 3 in others?  Here the 3 LSBs are 0x6, which matches both TINY (0x6&0b11
== 0x2) and TINY1 (0x6&0b111 == 0x6).

Read literally, with an 11 byte method, the encoding should be (11<<3)|0x6
== 94 != 46 emitted by CSC.

Anyway, the following minimal change seems to make this case work, but the
resulting code looks broken -- probably the TINY and TINY1 cases should be

*** mono-0.4-0/mono/metadata/metadata.c	Tue Jul 17 11:19:54 2001
--- mono-0.4/mono/metadata/metadata.c	Fri Jul 20 14:47:06 2001
*** 1230,1236 ****
  		mh->max_stack = 8;
  		mh->local_var_sig_tok = 0;
! 		mh->code_size = flags >> 3;
  		mh->code = ptr;

--- 1230,1236 ----
  		mh->max_stack = 8;
  		mh->local_var_sig_tok = 0;
! 		mh->code_size = flags >> 2;
  		mh->code = ptr;

What is your process for reporting spec issues to ECMA and/or Microsoft?

Jan Gray, Gray Research LLC