[Mono-dev] Fixing KeventWatcher: dealing with 32 / 64 bit operating systems

Romain Tartière romain at blogreen.org
Fri Sep 18 23:51:35 EDT 2009


Hello

The KeventWatcher has been broken for a while on FreeBSD [*], and I
started to fix it.  So far, it works on amd64, but I can't find some
pieces of information I need to make it work both on 32 bit and 64 bit
computers.



According to svn log, mcs/class/System/System.IO/KeventWatcher.cs has
been modified for the last time in mid 2005, and according to the
comment at the beginning of the file, it was created for Mac OSX.

I don't run Mac OSX, and don't know anybody who run it so I can't check
that the code is still working on this operating system, however I guess
it should not run better than on FreeBSD because of typo such as missing
'0x' in front of or'ed numbers (e.g. ev.fflags = 20 | 2 | 1 | 8).

Because of these typos, I took the liberty to patch directly this file
so that KeventWatcher works on FreeBSD, hopping it will be okay for any
other system using kqueue (most *BSD and Mac OSX I guess).



So, the patch to fix KeventWatcher on FreeBSD amd64 is in the BSD#
repository, where we test Mono and .NET ports before the eventually
reach the official FreeBSD ports tree:
http://code.google.com/p/bsd-sharp/source/browse/trunk/lang/mono/files/patch-mcs_class_System_System.IO_KeventWatcher.cs

My problem is related to the various structs (kevent and timespec).

Basically, a 32 bit FreeBSD needs:
------8<------------------------
struct timespec {
	public int tv_sec;
	public int tv_usec;
}
------8<------------------------
while a 64 bit FreeBSD needs:
------8<------------------------
struct timespec {
	public long tv_sec;
	public long tv_usec;
}
------8<------------------------

I would like to know what would be the best way to handle this
difference.  I can't find any relevant information on the Internet (I am
probably missing the good keywords), and the solutions I see (duplicate
code or encapsulate) look a bit weak to my eyes.



Any suggestion and pointer to relevant documentation is welcome.



Thanks,
Romain, on behalf of the BSD# team.

[*] Yep! I know that *BSD is not a supported platform, I'm a maintainer
    of mono for FreeBSD...

-- 
Romain Tartière <romain at blogreen.org>        http://romain.blogreen.org/
pgp: 8DAB A124 0DA4 7024 F82A  E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43)
(plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090919/df00358f/attachment.bin 


More information about the Mono-devel-list mailing list