Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 mono (3.0.6+dfsg2-10) unstable; urgency=low
 .
   [ Marek Safar ]
   * [3fc971b] Add test from Jb Evain to test biner with user method types
     (cherry picked from commit 80d342ff7555e95bfa3917543ce66910175cf61d)
 .
   [ Jo Shields ]
   * [fae7653] Really remove SPARC from list of architectures (Closes: #731253)
Author: Jo Shields <directhex@apebox.org>
Bug-Debian: http://bugs.debian.org/731253

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- mono-3.0.6+dfsg2.orig/configure.in
+++ mono-3.0.6+dfsg2/configure.in
@@ -150,6 +150,17 @@ case "$host" in
 		with_sigaltstack=no
 		use_sigposix=yes
 		;;
+	*-*-kfreebsd*-gnu)
+		platform_win32=no
+		CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP -DTHREAD_LOCAL_ALLOC -pthread"
+		libmono_cflags="-D_REENTRANT -DTHREAD_LOCAL_ALLOC -pthread"
+		libmono_ldflags="-lpthread -pthread"
+		libdl="-ldl"
+		libgc_threads=pthreads
+		need_link_unlink=yes
+		with_sigaltstack=no
+		use_sigposix=yes
+		;;
 	*-*-*freebsd*)
 		host_win32=no
 		if test "x$PTHREAD_CFLAGS" = "x"; then
@@ -2448,7 +2459,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 		        ;;
 		esac
@@ -2462,7 +2473,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 			;;
 		esac
@@ -2791,6 +2802,11 @@ case "$host" in
 	LIBC="libc.so.12"
 	INTL="libintl.so.0"
 	;;
+     *-*-kfreebsd*-gnu)
+	LIBC="libc.so.0.1"
+	INTL="libc.so.0.1"
+	X11="libX11.so.6"
+	;;
     *-*-*freebsd*)
     	LIBC="libc.so"
 	INTL="libintl.so"
@@ -2806,7 +2822,7 @@ case "$host" in
     *-*-*linux*)
 	AC_PATH_X
 	AC_MSG_CHECKING(for the soname of libX11.so)
-	for i in $x_libraries /usr/lib /usr/lib64; do
+	for i in $x_libraries /usr/lib /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/; do
 		for r in 4 5 6; do
 			if test -f $i/libX11.so.$r; then
 				X11=libX11.so.$r
@@ -2914,32 +2930,32 @@ if test "x$with_tls" = "x__thread"; then
 	])
 fi
 
-if test ${TARGET} = ARM && test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
+AC_ARG_WITH(fpu, [ --with-fpu=FPA,VFP,VFP_HARD,NONE    Select fpu to use on arm],[fpu=$withval])
+
+if test ${TARGET} = ARM; then
 	dnl ******************************************
 	dnl *** Check to see what FPU is available ***
 	dnl ******************************************
 	AC_MSG_CHECKING(which FPU to use)
 
-	fpu=NONE
-	if gcc -v 2>&1 | grep -q -- '--with-float=hard'; then
+	if test x$fpu = x && gcc -v 2>&1 | grep -q -- '--with-float=hard'; then
 	   fpu=VFP_HARD
 	fi
 
-	if test x$fpu = xNONE; then
+	if test x$fpu = x; then
 	   ORIG_CFLAGS=$CFLAGS
 	   CFLAGS="$CFLAGS -mfpu=vfp -mfloat-abi=softfp"
 	   AC_TRY_RUN([
 				int main () { __asm__ ("faddd	d7, d6, d7"); return 0; }
-				], fpu=VFP, fpu=NONE)
+				], fpu=VFP, fpu=)
 	   CFLAGS=$ORIG_CFLAGS
 	fi
 
-	if test x$fpu = xNONE; then
+	if test x$fpu = x; then
 		AC_TRY_COMPILE([], [
 			__asm__ ("ldfd f0, [r0]");
 			], fpu=FPA, fpu=NONE)
 	fi
-
 	AC_MSG_RESULT($fpu)
 	CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu=1"
 	unset fpu
--- mono-3.0.6+dfsg2.orig/Makefile.am
+++ mono-3.0.6+dfsg2/Makefile.am
@@ -4,7 +4,7 @@ MOONLIGHT_SUBDIRS = $(libgc_dir) eglib/s
 MONOTOUCH_SUBDIRS = $(libgc_dir) eglib/src mono
 
 if CROSS_COMPILING
-SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) data runtime scripts man samples msvc $(docs_dir)
+SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) data runtime scripts man samples msvc
 # Keep in sync with SUBDIRS
 ## 'tools' is not normally built
 DIST_SUBDIRS = m4 po libgc eglib mono ikvm-native data runtime scripts man samples tools msvc docs
@@ -15,7 +15,7 @@ else
 if ONLY_MOONLIGHT
 SUBDIRS = $(MOONLIGHT_SUBDIRS) runtime
 else
-SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) support data runtime scripts man samples msvc $(docs_dir)
+SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) support data runtime scripts man samples msvc
 # Keep in sync with SUBDIRS
 ## 'tools' is not normally built
 DIST_SUBDIRS = m4 po libgc eglib mono ikvm-native support data runtime scripts man samples tools msvc docs
--- mono-3.0.6+dfsg2.orig/support/syslog.c
+++ mono-3.0.6+dfsg2/support/syslog.c
@@ -38,7 +38,16 @@ Mono_Posix_Syscall_closelog (void)
 int
 Mono_Posix_Syscall_syslog (int priority, const char* message)
 {
+#ifdef __GNUC__
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wformat-security"
+#endif
+
 	syslog (priority, message);
+
+#ifdef __GNUC__
+	#pragma GCC diagnostic pop
+#endif
 	return 0;
 }
 
--- mono-3.0.6+dfsg2.orig/mono/tests/Makefile.am
+++ mono-3.0.6+dfsg2/mono/tests/Makefile.am
@@ -340,7 +340,6 @@ BASE_TEST_CS_SRC=		\
 	modules.cs	\
 	bug-81673.cs	\
 	bug-81691.cs	\
-	bug-80307.cs	\
 	bug-415577.cs	\
 	filter-stack.cs	\
 	vararg2.cs	\
--- mono-3.0.6+dfsg2.orig/mono/metadata/sgen-os-posix.c
+++ mono-3.0.6+dfsg2/mono/metadata/sgen-os-posix.c
@@ -35,7 +35,7 @@
 #include "metadata/sgen-archdep.h"
 #include "metadata/object-internals.h"
 
-#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 const static int suspend_signal_num = SIGXFSZ;
 #else
 const static int suspend_signal_num = SIGPWR;
--- mono-3.0.6+dfsg2.orig/mono/metadata/security.c
+++ mono-3.0.6+dfsg2/mono/metadata/security.c
@@ -13,6 +13,7 @@
 
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/assembly.h>
 #include <mono/metadata/image.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/object-internals.h>
--- mono-3.0.6+dfsg2.orig/mono/io-layer/io.c
+++ mono-3.0.6+dfsg2/mono/io-layer/io.c
@@ -4194,7 +4194,7 @@ get_fstypename (gchar *utfpath)
 }
 
 /* Linux has struct statfs which has a different layout */
-#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__)
+#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__) || defined(__FreeBSD_kernel__)
 gboolean
 GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesize, int *outserial, int *maxcomp, int *fsflags, gunichar2 *fsbuffer, int fsbuffersize)
 {
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-sparc.c
+++ mono-3.0.6+dfsg2/mono/mini/mini-sparc.c
@@ -4361,8 +4361,10 @@ mono_arch_get_lmf_addr (void)
 #endif
 
 void
-mono_arch_finish_init (void)
+mono_arch_tls_init (void)
 {
+	MonoJitTlsData *jit_tls;
+
 	if (!lmf_addr_key_inited) {
 		int res;
 
@@ -4377,14 +4379,21 @@ mono_arch_finish_init (void)
 
 	}
 
+	jit_tls = pthread_getspecific (mono_get_jit_tls_key ());
+
 #ifdef MONO_SPARC_THR_TLS
-	thr_setspecific (lmf_addr_key, &tls->lmf);
+	thr_setspecific (lmf_addr_key, &jit_tls->lmf);
 #else
-	pthread_setspecific (lmf_addr_key, &tls->lmf);
+	pthread_setspecific (lmf_addr_key, &jit_tls->lmf);
 #endif
 }
 
 void
+mono_arch_finish_init (void)
+{
+}
+
+void
 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
 {
 }
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-sparc.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-sparc.h
@@ -105,6 +105,9 @@ typedef struct MonoCompileArch {
 #define MONO_ARCH_HAVE_IMT 1
 #define MONO_ARCH_IMT_REG sparc_g1
 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
+#define MONO_ARCH_HAVE_TLS_INIT 1
+
+void mono_arch_tls_init (void);
 
 #ifdef SPARCV9
 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-x86.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-x86.h
@@ -48,7 +48,7 @@ struct sigcontext {
 #endif /* __HAIKU__ */
 
 #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \
-       defined(__FreeBSD__) || defined(__OpenBSD__)
+       defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 #define MONO_ARCH_USE_SIGACTION
 #endif
 
--- mono-3.0.6+dfsg2.orig/mono/mini/cpu-s390x.md
+++ mono-3.0.6+dfsg2/mono/mini/cpu-s390x.md
@@ -70,7 +70,7 @@ call_reg: dest:o src1:i len:8 clob:c
 ceq: dest:i len:12
 cgt.un: dest:i len:12
 cgt: dest:i len:12
-checkthis: src1:b len:10
+checkthis: src1:b len:16
 ckfinite: dest:f src1:f len:22
 clt.un: dest:i len:12
 clt: dest:i len:12
--- mono-3.0.6+dfsg2.orig/mono/mini/Makefile.am
+++ mono-3.0.6+dfsg2/mono/mini/Makefile.am
@@ -169,12 +169,12 @@ mono_sgen_CFLAGS = $(AM_CFLAGS)
 # link was done
 if SUPPORT_BOEHM
 buildver.h: libmini-static.la
-	@echo "const char *build_date = \"`date`\";" > buildver.h
+	@echo "const char *build_date;" > buildver.h
 mono-main.$(OBJEXT): buildver.h
 endif
 
 buildver-sgen.h: libmini-static.la
-	@echo "const char *build_date = \"`date`\";" > buildver-sgen.h
+	@echo "const char *build_date;" > buildver-sgen.h
 mono_sgen-main.$(OBJEXT): buildver-sgen.h
 
 if DTRACE_G_REQUIRED
@@ -738,16 +738,7 @@ EXTRA_DIST = TestDriver.cs ldscript ldsc
 	$(posix_sources)
 
 version.h: Makefile
-	if test -d $(top_srcdir)/.git; then \
-		(cd $(top_srcdir); \
-			LANG=C; export LANG; \
-			branch=`git branch | grep '^\*' | cut -d ' ' -f 2`; \
-			version=`git log --no-color --first-parent -n1 --pretty=format:%h`; \
-			echo "#define FULL_VERSION \"$$branch/$$version\""; \
-		); \
-	else \
-		echo "#define FULL_VERSION \"tarball\""; \
-	fi > version.h
+	echo "#define FULL_VERSION \"Debian $$(dpkg-parsechangelog -l$(top_srcdir)/debian/changelog | grep ^Vers | cut -d\  -f2)\"" > version.h
 
 # Utility target for patching libtool to speed up linking
 patch-libtool:
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-s390x.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-s390x.h
@@ -117,6 +117,8 @@ typedef struct
 #define MONO_ARCH_HAVE_TLS_GET				1
 #define MONO_ARCH_ENABLE_MONO_LMF_VAR			1
 #define MONO_ARCH_IMT_REG				s390_r9
+#define MONO_ARCH_VTABLE_REG				MONO_ARCH_IMT_REG
+#define MONO_ARCH_RGCTX_REG				MONO_ARCH_IMT_REG
 #define MONO_ARCH_THIS_AS_FIRST_ARG     		1
 #define MONO_ARCH_HAVE_XP_UNWIND			1
 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX		1
@@ -124,6 +126,8 @@ typedef struct
 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG		1
 #define MONO_ARCH_USE_SIGACTION 			1
 #define MONO_ARCH_GC_MAPS_SUPPORTED			1
+#define MONO_ARCH_GSHARED_SUPPORTED			1
+#define MONO_ARCH_MONITOR_ENTER_ADJUSTMENT		1
 
 #define S390_STACK_ALIGNMENT		 8
 #define S390_FIRST_ARG_REG 		s390_r2
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-gc.c
+++ mono-3.0.6+dfsg2/mono/mini/mini-gc.c
@@ -2547,11 +2547,6 @@ mini_gc_set_slot_type_from_cfa (MonoComp
 
 #endif /* DISABLE_JIT */
 
-void
-mini_gc_enable_gc_maps_for_aot (void)
-{
-}
-
 #endif
 
 #ifndef DISABLE_JIT
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-s390x.c
+++ mono-3.0.6+dfsg2/mono/mini/mini-s390x.c
@@ -246,6 +246,9 @@ if (ins->inst_target_bb->native_offset)
 #define JUMP_SIZE	6
 #define ENABLE_WRONG_METHOD_CHECK 0
 
+#define mono_mini_arch_lock() EnterCriticalSection (&mini_arch_mutex)
+#define mono_mini_arch_unlock() LeaveCriticalSection (&mini_arch_mutex)
+
 /*========================= End of Defines =========================*/
 
 /*------------------------------------------------------------------*/
@@ -365,7 +368,7 @@ static gboolean is_regsize_var (MonoType
 static inline void add_general (guint *, size_data *, ArgInfo *);
 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
 static inline void add_float (guint *, size_data *, ArgInfo *);
-static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
+static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
 static void catch_SIGILL(int, siginfo_t *, void *);
@@ -414,6 +417,11 @@ static gpointer bp_trigger_page;
 
 breakpoint_t breakpointCode;
 
+/* 
+ * This mutex protects architecture specific caches 
+ */
+static CRITICAL_SECTION mini_arch_mutex;
+
 /*====================== End of Global Variables ===================*/
 
 /*------------------------------------------------------------------*/
@@ -916,7 +924,7 @@ enter_method (MonoMethod *method, RegPar
 	
 	sig = mono_method_signature (method);
 	
-	cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
+	cinfo = get_call_info (NULL, NULL, sig);
 
 	if (cinfo->struct_ret) {
 		printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
@@ -1623,12 +1631,13 @@ add_float (guint *fr,  size_data *sz, Ar
 /*------------------------------------------------------------------*/
 
 static CallInfo *
-get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
+get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
 {
 	guint i, fr, gr, size, pstart;
 	int nParm = sig->hasthis + sig->param_count;
 	MonoType *ret_type;
-	guint32 simpletype, align;
+	guint32 simpleType, align;
+	gboolean is_pinvoke = sig->pinvoke;
 	CallInfo *cinfo;
 	size_data *sz;
 	MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
@@ -1659,11 +1668,11 @@ get_call_info (MonoCompile *cfg, MonoMem
 	/* area that the callee will use.			    */
 	/*----------------------------------------------------------*/
 
-	ret_type = mono_type_get_underlying_type (sig->ret);
+	ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
 	ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
-	simpletype = ret_type->type;
+	simpleType = ret_type->type;
 enum_retvalue:
-	switch (simpletype) {
+	switch (simpleType) {
 		case MONO_TYPE_BOOLEAN:
 		case MONO_TYPE_I1:
 		case MONO_TYPE_U1:
@@ -1704,13 +1713,10 @@ enum_retvalue:
 		case MONO_TYPE_VALUETYPE: {
 			MonoClass *klass = mono_class_from_mono_type (sig->ret);
 			if (klass->enumtype) {
-				simpletype = mono_class_enum_basetype (klass)->type;
+				simpleType = mono_class_enum_basetype (klass)->type;
 				goto enum_retvalue;
 			}
-			if (sig->pinvoke)
-				size = mono_class_native_size (klass, &align);
-			else
-				size = mono_class_value_size (klass, &align);
+			size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
 	
 			cinfo->struct_ret = 1;
 			cinfo->ret.size   = size;
@@ -1803,11 +1809,10 @@ enum_retvalue:
 			continue;
 		}
 
-		ptype = mono_type_get_underlying_type (sig->params [i]);
-		ptype = mini_get_basic_type_from_generic (gsctx, ptype);
-		simpletype = ptype->type;
-		cinfo->args[nParm].type = simpletype;
-		switch (simpletype) {
+		ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
+		simpleType = ptype->type;
+		cinfo->args[nParm].type = simpleType;
+		switch (simpleType) {
 		case MONO_TYPE_BOOLEAN:
 		case MONO_TYPE_I1:
 		case MONO_TYPE_U1:
@@ -1858,7 +1863,7 @@ enum_retvalue:
 			nParm++;
 			break;
 		case MONO_TYPE_GENERICINST:
-			if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
+			if (!mono_type_generic_inst_is_valuetype (ptype)) {
 				cinfo->args[nParm].size = sizeof(gpointer);
 				add_general (&gr, sz, cinfo->args+nParm);
 				nParm++;
@@ -1867,30 +1872,29 @@ enum_retvalue:
 			/* Fall through */
 		case MONO_TYPE_VALUETYPE: {
 			MonoMarshalType *info;
-			MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
-			if (sig->pinvoke)
-				size = mono_class_native_size (klass, &align);
-			else
-				size = mono_class_value_size (klass, &align);
-	
-			info = mono_marshal_load_type_info (klass);
+			MonoClass *klass = mono_class_from_mono_type (ptype);
 
-			if ((info->native_size == sizeof(float)) &&
-			    (info->num_fields  == 1) &&
-			    (info->fields[0].field->type->type == MONO_TYPE_R4)) {
-				cinfo->args[nParm].size = sizeof(float);
-				add_float(&fr, sz, cinfo->args+nParm);
-				nParm ++;
-				break;
-			}
+			size = mini_type_stack_size_full(gsctx, &klass->byval_arg, NULL, sig->pinvoke);
+			if (simpleType != MONO_TYPE_GENERICINST) {
+				info = mono_marshal_load_type_info(klass);
 
-			if ((info->native_size == sizeof(double)) &&
-			    (info->num_fields  == 1) &&
-			    (info->fields[0].field->type->type == MONO_TYPE_R8)) {
-				cinfo->args[nParm].size = sizeof(double);
-				add_float(&fr, sz, cinfo->args+nParm);
-				nParm ++;
-				break;
+				if ((info->native_size == sizeof(float)) &&
+				    (info->num_fields  == 1) &&
+				    (info->fields[0].field->type->type == MONO_TYPE_R4)) {
+					cinfo->args[nParm].size = sizeof(float);
+					add_float(&fr, sz, cinfo->args+nParm);
+					nParm ++;
+					break;
+				}
+
+				if ((info->native_size == sizeof(double)) &&
+				    (info->num_fields  == 1) &&
+				    (info->fields[0].field->type->type == MONO_TYPE_R8)) {
+					cinfo->args[nParm].size = sizeof(double);
+					add_float(&fr, sz, cinfo->args+nParm);
+					nParm ++;
+					break;
+				}
 			}
 
 			cinfo->args[nParm].vtsize  = 0;
@@ -1949,7 +1953,7 @@ enum_retvalue:
 		}
 			break;
 		default:
-			g_error ("Can't trampoline 0x%x", sig->params [i]->type);
+			g_error ("Can't trampoline 0x%x", ptype);
 		}
 	}
 
@@ -2043,7 +2047,7 @@ mono_arch_allocate_vars (MonoCompile *cf
 
 	sig     = mono_method_signature (cfg->method);
 	
-	cinfo   = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo   = get_call_info (cfg, cfg->mempool, sig);
 
 	if (!cinfo->struct_ret) {
 		switch (mono_type_get_underlying_type (sig->ret)->type) {
@@ -2272,7 +2276,7 @@ mono_arch_create_vars (MonoCompile *cfg)
 
 	sig = mono_method_signature (cfg->method);
 
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	if (cinfo->struct_ret) {
 		cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
@@ -2387,7 +2391,7 @@ mono_arch_emit_call (MonoCompile *cfg, M
 	n = sig->param_count + sig->hasthis;
 	DEBUG (g_print ("Call requires: %d parameters\n",n));
 	
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	stackSize         = cinfo->sz.stack_size + cinfo->sz.local_size + 
 			    cinfo->sz.parm_size + cinfo->sz.offset;
@@ -4161,6 +4165,7 @@ mono_arch_output_basic_block (MonoCompil
 			/* ensure ins->sreg1 is not NULL */
 			s390_lg   (code, s390_r0, 0, ins->sreg1, 0);
 			s390_ltgr (code, s390_r0, s390_r0);
+			EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
 		}
 			break;
 		case OP_ARGLIST: {
@@ -4979,8 +4984,11 @@ mono_arch_patch_code (MonoMethod *method
 			case MONO_PATCH_INFO_EXC:
 			case MONO_PATCH_INFO_ABS:
 			case MONO_PATCH_INFO_METHOD:
+			case MONO_PATCH_INFO_RGCTX_FETCH:
 			case MONO_PATCH_INFO_INTERNAL_METHOD:
 			case MONO_PATCH_INFO_CLASS_INIT:
+			case MONO_PATCH_INFO_JIT_ICALL_ADDR:
+			case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
 				s390_patch_addr (ip, (guint64) target);
 				continue;
 			case MONO_PATCH_INFO_SWITCH: 
@@ -5037,7 +5045,7 @@ emit_load_volatile_arguments (guint8 *co
 	int pos = 0, i;
 	CallInfo *cinfo;
 
-	cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
+	cinfo = get_call_info (NULL, NULL, sig);
 
 	if (cinfo->struct_ret) {
 		ArgInfo *ainfo = &cinfo->ret;
@@ -5191,6 +5199,15 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 
 	mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
 
+	/* store runtime generic context */
+	if (cfg->rgctx_var) {
+		g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
+
+		s390_stg  (code, MONO_ARCH_RGCTX_REG, 0, 
+			   cfg->rgctx_var->inst_basereg, 
+			   cfg->rgctx_var->inst_offset);
+	}
+
         /* compute max_offset in order to use short forward jumps
 	 * we always do it on s390 because the immediate displacement
 	 * for jumps is too small 
@@ -5211,7 +5228,7 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 	sig = mono_method_signature (method);
 	pos = 0;
 
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	if (cinfo->struct_ret) {
 		ArgInfo *ainfo     = &cinfo->ret;
@@ -6230,6 +6247,44 @@ mono_arch_find_imt_method (mgreg_t *regs
 }
 
 /*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_find_static_call_vtable                 */
+/*                                                                  */
+/* Function	- Find the static call vtable.                      */
+/*		                               			    */
+/*------------------------------------------------------------------*/
+
+MonoVTable*
+mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
+{
+	mgreg_t *r = (mgreg_t*)regs;
+
+	return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_get_cie_program                         */
+/*                                                                  */
+/* Function	- Find the static call vtable.                      */
+/*		                               			    */
+/*------------------------------------------------------------------*/
+
+GSList*
+mono_arch_get_cie_program (void)
+{
+	GSList *l = NULL;
+
+	mono_add_unwind_op_def_cfa (l, NULL, NULL, STK_BASE, 0);
+
+	return(l);
+}
+
+/*========================= End of Function ========================*/
 
 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
 
--- mono-3.0.6+dfsg2.orig/mono/mini/tramp-s390x.c
+++ mono-3.0.6+dfsg2/mono/mini/tramp-s390x.c
@@ -27,6 +27,9 @@
 #define CREATE_FP_OFFSET	CREATE_GR_OFFSET+GR_SAVE_SIZE
 #define CREATE_LMF_OFFSET	CREATE_FP_OFFSET+FP_SAVE_SIZE
 #define CREATE_STACK_SIZE	(CREATE_LMF_OFFSET+2*sizeof(long)+sizeof(MonoLMF))
+#define GENERIC_REG_OFFSET	CREATE_STACK_SIZE + \
+				S390_REG_SAVE_OFFSET + \
+				3*sizeof(long)
 
 /*------------------------------------------------------------------*/
 /* Method-specific trampoline code fragment sizes		    */
@@ -343,10 +346,11 @@ mono_arch_create_generic_trampoline (Mon
 		s390_lg   (buf, s390_r3, 0, s390_r11, S390_RET_ADDR_OFFSET);
 	}
 
-	/* Arg 3: MonoMethod *method. It was put in r1 by the
-	   method-specific trampoline code, and then saved before the call
-	   to mono_get_lmf_addr()'. */
-	s390_lg  (buf, s390_r4, 0, STK_BASE, METHOD_SAVE_OFFSET);
+	/* Arg 3: Trampoline argument */
+	if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
+		s390_lg (buf, s390_r4, 0, STK_BASE, GENERIC_REG_OFFSET);
+	else
+		s390_lg (buf, s390_r4, 0, STK_BASE, METHOD_SAVE_OFFSET);
 
 	/* Arg 4: trampoline address. Ignore for now */
 		
@@ -387,10 +391,12 @@ mono_arch_create_generic_trampoline (Mon
 	s390_lgr  (buf, STK_BASE, s390_r11);
 	s390_lmg  (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
 
-	if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT || tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
-		s390_br (buf, s390_r14);
-	else
-		s390_br (buf, s390_r1);
+	if (MONO_TRAMPOLINE_TYPE_MUST_RETURN(tramp_type)) {
+		s390_lgr (buf, s390_r2, s390_r1);
+		s390_br  (buf, s390_r14);
+	} else {
+		s390_br  (buf, s390_r1);
+	}
 
 	/* Flush instruction cache, since we've generated code */
 	mono_arch_flush_icache (code, buf - code);
@@ -435,7 +441,7 @@ mono_arch_create_specific_trampoline (gp
 	s390_llong(buf, arg1);
 	s390_lg   (buf, s390_r1, 0, s390_r1, 4);
 	displace = (tramp - buf) / 2;
-	s390_jcl  (buf, S390_CC_UN, displace);
+	s390_jg   (buf, displace);
 
 	/* Flush instruction cache, since we've generated code */
 	mono_arch_flush_icache (code, buf - code);
@@ -462,9 +468,201 @@ mono_arch_create_specific_trampoline (gp
 gpointer
 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
 {
-	/* FIXME: implement! */
+#ifdef MONO_ARCH_VTABLE_REG
+	guint8 *tramp;
+	guint8 *code, *buf;
+	guint8 **rgctx_null_jumps;
+	gint32 displace;
+	int tramp_size,
+	    depth, 
+	    index, 
+	    iPatch = 0,
+	    i;
+	gboolean mrgctx;
+	MonoJumpInfo *ji = NULL;
+	GSList *unwind_ops = NULL;
+
+	mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
+	index = MONO_RGCTX_SLOT_INDEX (slot);
+	if (mrgctx)
+		index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
+	for (depth = 0; ; ++depth) {
+		int size = mono_class_rgctx_get_array_size (depth, mrgctx);
+
+		if (index < size - 1)
+			break;
+		index -= size - 1;
+	}
+
+	tramp_size = 48 + 16 * depth;
+	if (mrgctx)
+		tramp_size += 4;
+	else
+		tramp_size += 12;
+
+	code = buf = mono_global_codeman_reserve (tramp_size);
+
+	unwind_ops = mono_arch_get_cie_program ();
+
+	rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
+
+	if (mrgctx) {
+		/* get mrgctx ptr */
+		s390_lgr (code, s390_r1, s390_r2);
+	} else {
+		/* load rgctx ptr from vtable */
+		s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoVTable, runtime_generic_context));
+		/* is the rgctx ptr null? */
+		s390_ltgr (code, s390_r1, s390_r1);
+		/* if yes, jump to actual trampoline */
+		rgctx_null_jumps [iPatch++] = code;
+		s390_jge (code, 0);
+	}
+
+	for (i = 0; i < depth; ++i) {
+		/* load ptr to next array */
+		if (mrgctx && i == 0)
+			s390_lg (code, s390_r1, 0, s390_r1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
+		else
+			s390_lg (code, s390_r1, 0, s390_r1, 0);
+		s390_ltgr (code, s390_r1, s390_r1);
+		/* if the ptr is null then jump to actual trampoline */
+		rgctx_null_jumps [iPatch++] = code;
+		s390_jge (code, 0);
+	}
+
+	/* fetch slot */
+	s390_lg (code, s390_r1, 0, s390_r1, (sizeof (gpointer) * (index  + 1)));
+	/* is the slot null? */
+	s390_ltgr (code, s390_r1, s390_r1);
+	/* if yes, jump to actual trampoline */
+	rgctx_null_jumps [iPatch++] = code;
+	s390_jge (code, 0);
+	/* otherwise return r1 */
+	s390_lgr (code, s390_r2, s390_r1);
+	s390_br  (code, s390_r14);
+
+	for (i = 0; i < iPatch; i++) {
+		displace = ((uintptr_t) code - (uintptr_t) rgctx_null_jumps[i]) / 2;
+		s390_patch_rel ((rgctx_null_jumps [i] + 2), displace);
+	}
+
+	g_free (rgctx_null_jumps);
+
+	/* move the rgctx pointer to the VTABLE register */
+	s390_lgr (code, MONO_ARCH_VTABLE_REG, s390_r2);
+
+	tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
+		MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
+
+	/* jump to the actual trampoline */
+	displace = (tramp - code) / 2;
+	s390_jg (code, displace);
+
+	mono_arch_flush_icache (buf, code - buf);
+
+	g_assert (code - buf <= tramp_size);
+
+	if (info)
+		*info = mono_tramp_info_create (mono_get_rgctx_fetch_trampoline_name (slot), buf, code - buf, ji, unwind_ops);
+
+	return(buf);
+#else
 	g_assert_not_reached ();
-	return NULL;
+#endif
+	return(NULL);
 }	
 
 /*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name    	- mono_arch_get_static_rgctx_trampoline		    */
+/*                                                                  */
+/* Function	- Create a trampoline which sets RGCTX_REG to MRGCTX*/
+/*		  then jumps to ADDR.				    */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_get_static_rgctx_trampoline (MonoMethod *m, 
+					MonoMethodRuntimeGenericContext *mrgctx, 
+					gpointer addr)
+{
+	guint8 *code, *start;
+	gint32 displace;
+	int buf_len;
+
+	MonoDomain *domain = mono_domain_get ();
+
+	buf_len = 32;
+
+	start = code = mono_domain_code_reserve (domain, buf_len);
+
+	s390_basr (code, s390_r1, 0);
+	s390_j    (code, 6);
+	s390_llong(code, mrgctx);
+	s390_lg   (code, MONO_ARCH_RGCTX_REG, 0, s390_r1, 4);
+	displace = ((uintptr_t) addr - (uintptr_t) code) / 2;
+	s390_jg   (code, displace);
+	g_assert ((code - start) < buf_len);
+
+	mono_arch_flush_icache (start, code - start);
+
+	return(start);
+}	
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_create_generic_class_init_trampoline    */
+/*                                                                  */
+/* Function	- 						    */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+	guint8 *tramp;
+	guint8 *code, *buf;
+	static int byte_offset = -1;
+	static guint8 bitmask;
+	guint8 *jump;
+	gint32 displace;
+	int tramp_size;
+	GSList *unwind_ops = NULL;
+	MonoJumpInfo *ji = NULL;
+
+	tramp_size = 48;
+
+	code = buf = mono_global_codeman_reserve (tramp_size);
+
+	unwind_ops = mono_arch_get_cie_program ();
+
+	if (byte_offset < 0)
+		mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
+
+	s390_llgc(code, s390_r0, 0, MONO_ARCH_VTABLE_REG, byte_offset);
+	s390_nill(code, s390_r0, bitmask);
+	s390_bnzr(code, s390_r14);
+
+	tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
+		mono_get_root_domain (), NULL);
+
+	/* jump to the actual trampoline */
+	displace = (tramp - code) / 2;
+	s390_jg (code, displace);
+
+	mono_arch_flush_icache (buf, code - buf);
+
+	g_assert (code - buf <= tramp_size);
+
+	if (info)
+		*info = mono_tramp_info_create (g_strdup_printf ("generic_class_init_trampoline"), buf, code - buf, ji, unwind_ops);
+
+	return(buf);
+}
+
+/*========================= End of Function ========================*/
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-amd64.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-amd64.h
@@ -282,7 +282,7 @@ typedef struct MonoCompileArch {
 
 #define MONO_ARCH_NOMAP32BIT
 
-#elif defined (__FreeBSD__)
+#elif defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
 
 #define REG_RAX 7
 #define REG_RCX 4
--- mono-3.0.6+dfsg2.orig/mono/mini/mini.c
+++ mono-3.0.6+dfsg2/mono/mini/mini.c
@@ -2730,6 +2730,10 @@ setup_jit_tls_data (gpointer stack_start
 	jit_tls->lmf = lmf;
 #endif
 
+#ifdef MONO_ARCH_HAVE_TLS_INIT
+	mono_arch_tls_init ();
+#endif
+
 	mono_setup_altstack (jit_tls);
 
 	return jit_tls;
@@ -6851,9 +6855,9 @@ mini_init (const char *filename, const c
 			mono_install_imt_thunk_builder (mono_arch_build_imt_thunk);
 	}
 #endif
+
 	/*Init arch tls information only after the metadata side is inited to make sure we see dynamic appdomain tls keys*/
 	mono_arch_finish_init ();
-	
 
 	/* This must come after mono_init () in the aot-only case */
 	mono_exceptions_init ();
--- mono-3.0.6+dfsg2.orig/mono/utils/mono-sigcontext.h
+++ mono-3.0.6+dfsg2/mono/utils/mono-sigcontext.h
@@ -16,14 +16,14 @@
 
 #if defined(TARGET_X86)
 
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__DragonFly__)
 #include <ucontext.h>
 #endif
 #if defined(__APPLE__)
 #include <AvailabilityMacros.h>
 #endif
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 	#define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_eax)
 	#define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ebx)
 	#define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ecx)
@@ -154,7 +154,7 @@ typedef struct ucontext {
 
 #elif defined(TARGET_AMD64)
 
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <ucontext.h>
 #endif
 
@@ -176,7 +176,7 @@ typedef struct ucontext {
 	#define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r13)
 	#define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r14)
 	#define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r15)
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 	#define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rax)
 	#define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rbx)
 	#define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rcx)
--- mono-3.0.6+dfsg2.orig/mono/arch/s390x/s390x-codegen.h
+++ mono-3.0.6+dfsg2/mono/arch/s390x/s390x-codegen.h
@@ -593,11 +593,14 @@ typedef struct {
 #define s390_basr(c, r1, r2)		S390_RR(c, 0x0d, r1, r2)
 #define s390_bctr(c, r1, r2)		S390_RR(c, 0x06, r1, r2)
 #define s390_bctrg(c, r1, r2)		S390_RRE(c, 0xb946, r1, r2)
+#define s390_bnzr(c, r)			S390_RR(c, 0x07, 0x07, r)
 #define s390_bras(c, r, o)		S390_RI(c, 0xa75, r, o)
 #define s390_brasl(c, r, o)		S390_RIL_1(c, 0xc05, r, o)
 #define s390_brc(c, m, d)		S390_RI(c, 0xa74, m, d)
+#define s390_brcl(c, m, d)		S390_RIL_2(c, 0xc04, m, d)
 #define s390_br(c, r)			S390_RR(c, 0x07, 0xf, r)
 #define s390_break(c)			S390_RR(c, 0, 0, 0)
+#define s390_bzr(c, r)			S390_RR(c, 0x07, 0x08, r)
 #define s390_c(c, r, x, b, d)		S390_RX(c, 0x59, r, x, b, d)
 #define s390_cdb(c, r, x, b, d)		S390_RXE(c, 0xed19, r, x, b, d)
 #define s390_cdbr(c, r1, r2)		S390_RRE(c, 0xb319, r1, r2)
@@ -636,7 +639,7 @@ typedef struct {
 #define s390_icy(c, r, x, b, d)		S390_RXY(c, 0xe373, r, x, b, d)
 #define s390_j(c,d)			s390_brc(c, S390_CC_UN, d)
 #define s390_jc(c, m, d)		s390_brc(c, m, d)
-#define s390_jcl(c, m, d)		S390_RIL_2(c, 0xc04, m, d)
+#define s390_jcl(c, m, d)		s390_brcl(c, m, d)
 #define s390_jcy(c, d)			s390_brc(c, S390_CC_CY, d)
 #define s390_je(c, d)			s390_brc(c, S390_CC_EQ, d)
 #define s390_jeo(c, d)			s390_brc(c, S390_CC_ZR|S390_CC_OV, d)
@@ -654,6 +657,24 @@ typedef struct {
 #define s390_jno(c, d)			s390_brc(c, S390_CC_NO, d)
 #define s390_jp(c, d)			s390_brc(c, S390_CC_GT, d)
 #define s390_jz(c, d)			s390_brc(c, S390_CC_ZR, d)
+#define s390_jg(c,d)			s390_brcl(c, S390_CC_UN, d)
+#define s390_jgcy(c, d)			s390_brcl(c, S390_CC_CY, d)
+#define s390_jge(c, d)			s390_brcl(c, S390_CC_EQ, d)
+#define s390_jgeo(c, d)			s390_brcl(c, S390_CC_ZR|S390_CC_OV, d)
+#define s390_jgh(c, d)			s390_brcl(c, S390_CC_GT, d)
+#define s390_jgho(c, d)			s390_brcl(c, S390_CC_GT|S390_CC_OV, d)
+#define s390_jgl(c, d)			s390_brcl(c, S390_CC_LT, d)
+#define s390_jglo(c, d)			s390_brcl(c, S390_CC_LT|S390_CC_OV, d)
+#define s390_jgm(c, d)			s390_brcl(c, S390_CC_LT, d)
+#define s390_jgnc(c, d)			s390_brcl(c, S390_CC_NC, d)
+#define s390_jgne(c, d)			s390_brcl(c, S390_CC_NZ, d)
+#define s390_jgnh(c, d)			s390_brcl(c, S390_CC_LE, d)
+#define s390_jgnl(c, d)			s390_brcl(c, S390_CC_GE, d)
+#define s390_jgnz(c, d)			s390_brcl(c, S390_CC_NZ, d)
+#define s390_jgo(c, d)			s390_brcl(c, S390_CC_OV, d)
+#define s390_jgno(c, d)			s390_brcl(c, S390_CC_NO, d)
+#define s390_jgp(c, d)			s390_brcl(c, S390_CC_GT, d)
+#define s390_jgz(c, d)			s390_brcl(c, S390_CC_ZR, d)
 #define s390_l(c, r, x, b, d)		S390_RX(c, 0x58, r, x, b, d)
 #define s390_ly(c, r, x, b, d)		S390_RXY(c, 0xe358, r, x, b, d)
 #define s390_la(c, r, x, b, d)		S390_RX(c, 0x41, r, x, b, d)
--- mono-3.0.6+dfsg2.orig/eglib/src/giconv.c
+++ mono-3.0.6+dfsg2/eglib/src/giconv.c
@@ -894,7 +894,7 @@ eg_utf8_to_utf16_general (const gchar *s
 	size_t inleft;
 	char *inptr;
 	gunichar c;
-	int n;
+	int u, n;
 	
 	g_return_val_if_fail (str != NULL, NULL);
 	
@@ -903,6 +903,7 @@ eg_utf8_to_utf16_general (const gchar *s
 			g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, "Conversions with embedded nulls must pass the string length");
 			return NULL;
 		}
+		
 		len = strlen (str);
 	}
 	
@@ -910,29 +911,18 @@ eg_utf8_to_utf16_general (const gchar *s
 	inleft = len;
 	
 	while (inleft > 0) {
-		if ((n = decode_utf8 (inptr, inleft, &c)) < 0) {
-			if (errno == EILSEQ) {
-				g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
-					     "Illegal byte sequence encounted in the input.");
-			} else if (items_read) {
-				/* partial input is ok if we can let our caller know... */
-				break;
-			} else {
-				g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
-					     "Partial byte sequence encountered in the input.");
-			}
-			
-			if (items_read)
-				*items_read = inptr - str;
-			
-			if (items_written)
-				*items_written = 0;
-			
-			return NULL;
-		} else if (c == 0 && !include_nuls)
+		if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
+			goto error;
+		
+		if (c == 0 && !include_nuls)
 			break;
 		
-		outlen += g_unichar_to_utf16 (c, NULL);
+		if ((u = g_unichar_to_utf16 (c, NULL)) < 0) {
+			errno = EILSEQ;
+			goto error;
+		}
+		
+		outlen += u;
 		inleft -= n;
 		inptr += n;
 	}
@@ -950,7 +940,8 @@ eg_utf8_to_utf16_general (const gchar *s
 	while (inleft > 0) {
 		if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
 			break;
-		else if (c == 0 && !include_nuls)
+		
+		if (c == 0 && !include_nuls)
 			break;
 		
 		outptr += g_unichar_to_utf16 (c, outptr);
@@ -961,6 +952,25 @@ eg_utf8_to_utf16_general (const gchar *s
 	*outptr = '\0';
 	
 	return outbuf;
+	
+ error:
+	if (errno == EILSEQ) {
+		g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
+			     "Illegal byte sequence encounted in the input.");
+	} else if (items_read) {
+		/* partial input is ok if we can let our caller know... */
+	} else {
+		g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
+			     "Partial byte sequence encountered in the input.");
+	}
+	
+	if (items_read)
+		*items_read = inptr - str;
+	
+	if (items_written)
+		*items_written = 0;
+	
+	return NULL;
 }
 
 gunichar2 *
--- mono-3.0.6+dfsg2.orig/data/reactive.pc.in
+++ mono-3.0.6+dfsg2/data/reactive.pc.in
@@ -1,12 +1,4 @@
 Name: Reactive Extensions
 Description: Reactive Extensions
 Version: @VERSION@
-Libs: 
--r:@prefix@/lib/mono/4.5/System.Reactive.Interfaces.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Core.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Linq.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.PlatformServices.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Providers.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Debugger.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Experimental.dll
--r:@prefix@/lib/mono/4.5/System.Reactive.Runtime.Remoting.dll
+Libs: -r:@prefix@/lib/mono/4.5/System.Reactive.Interfaces.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Core.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Linq.dll -r:@prefix@/lib/mono/4.5/System.Reactive.PlatformServices.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Providers.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Debugger.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Experimental.dll -r:@prefix@/lib/mono/4.5/System.Reactive.Runtime.Remoting.dll
--- mono-3.0.6+dfsg2.orig/data/mono.pc.in
+++ mono-3.0.6+dfsg2/data/mono.pc.in
@@ -1,5 +1,5 @@
-prefix=${pcfiledir}/../..
-exec_prefix=${pcfiledir}/../..
+prefix=@prefix@
+exec_prefix=${prefix}
 libdir=${prefix}/@reloc_libdir@
 includedir=${prefix}/include/mono-@API_VER@
 sysconfdir=@sysconfdir@
--- mono-3.0.6+dfsg2.orig/data/mono-cairo.pc.in
+++ mono-3.0.6+dfsg2/data/mono-cairo.pc.in
@@ -1,5 +1,5 @@
-prefix=${pcfiledir}/../..
-exec_prefix=${pcfiledir}/../..
+prefix=@prefix@
+exec_prefix=${prefix}
 libdir=${prefix}/@reloc_libdir@
 includedir=${prefix}/include
 
--- mono-3.0.6+dfsg2.orig/libgc/configure.in
+++ mono-3.0.6+dfsg2/libgc/configure.in
@@ -114,6 +114,17 @@ case "$THREADS" in
 	AC_DEFINE(THREAD_LOCAL_ALLOC)
 	THREADDLLIBS="-lpthread -lrt"
 	;;
+     *-*-kfreebsd*-gnu)
+	AC_DEFINE(GC_FREEBSD_THREADS)
+	INCLUDES="$INCLUDES -pthread"
+	THREADDLLIBS=-pthread
+	AC_DEFINE(_REENTRANT)
+	if test "${enable_parallel_mark}" = yes; then
+		AC_DEFINE(PARALLEL_MARK)
+	fi
+	AC_DEFINE(THREAD_LOCAL_ALLOC)
+	AC_DEFINE(USE_COMPILER_TLS)
+	;;
       *-*-freebsd*)
 	AC_DEFINE(GC_FREEBSD_THREADS)
 	if test "x$PTHREAD_CFLAGS" != "x"; then
--- mono-3.0.6+dfsg2.orig/libgc/dyn_load.c
+++ mono-3.0.6+dfsg2/libgc/dyn_load.c
@@ -26,7 +26,7 @@
  * None of this is safe with dlclose and incremental collection.
  * But then not much of anything is safe in the presence of dlclose.
  */
-#if defined(__linux__) && !defined(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__GLIBC__)) && !defined(_GNU_SOURCE)
     /* Can't test LINUX, since this must be define before other includes */
 #   define _GNU_SOURCE
 #endif
@@ -394,7 +394,7 @@ GC_bool GC_register_main_static_data()
 /* For glibc 2.2.4+.  Unfortunately, it doesn't work for older	*/
 /* versions.  Thanks to Jakub Jelinek for most of the code.	*/
 
-# if defined(LINUX) /* Are others OK here, too? */ \
+# if (defined(LINUX) || defined (__GLIBC__)) /* Are others OK here, too? */ \
      && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
          || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG))) 
 
--- mono-3.0.6+dfsg2.orig/libgc/include/gc.h
+++ mono-3.0.6+dfsg2/libgc/include/gc.h
@@ -493,7 +493,7 @@ GC_API GC_PTR GC_malloc_atomic_ignore_of
 #   define GC_RETURN_ADDR (GC_word)__return_address
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
 # include <features.h>
 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
      && !defined(__ia64__)
--- mono-3.0.6+dfsg2.orig/libgc/include/private/gcconfig.h
+++ mono-3.0.6+dfsg2/libgc/include/private/gcconfig.h
@@ -55,7 +55,7 @@
 # endif
 
 /* And one for FreeBSD: */
-# if defined(__FreeBSD__) && !defined(FREEBSD)
+# if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
 #    define FREEBSD
 # endif
 
@@ -1368,8 +1368,15 @@
 #	ifndef GC_FREEBSD_THREADS
 #	    define MPROTECT_VDB
 #	endif
-#      define SIG_SUSPEND SIGTSTP
-#      define SIG_THR_RESTART SIGCONT
+#       ifdef __GLIBC__
+#           define SIG_SUSPEND          (32+6)
+#           define SIG_THR_RESTART      (32+5)
+            extern int _end[];
+#           define DATAEND (_end)
+#       else
+#           define SIG_SUSPEND SIGTSTP
+#           define SIG_THR_RESTART SIGCONT
+#       endif
 #	define FREEBSD_STACKBOTTOM
 #	ifdef __ELF__
 #	    define DYNAMIC_LOADING
@@ -2136,6 +2143,28 @@
 	extern char * GC_FreeBSDGetDataStart();
 #	define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
 #   endif
+#   ifdef FREEBSD
+#	define OS_TYPE "FREEBSD"
+#	ifndef GC_FREEBSD_THREADS
+#	    define MPROTECT_VDB
+#	endif
+#	ifdef __GLIBC__
+#	    define SIG_SUSPEND		(32+6)
+#	    define SIG_THR_RESTART	(32+5)
+	    extern int _end[];
+#	    define DATAEND (_end)
+#	else
+#	    define SIG_SUSPEND SIGUSR1
+#	    define SIG_THR_RESTART SIGUSR2
+#	endif
+#	define FREEBSD_STACKBOTTOM
+#	ifdef __ELF__
+#	    define DYNAMIC_LOADING
+#	endif
+	extern char etext[];
+	extern char * GC_FreeBSDGetDataStart();
+#	define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
+#   endif
 #   ifdef NETBSD
 #	define OS_TYPE "NETBSD"
 #	ifdef __ELF__
@@ -2223,7 +2252,7 @@
 #   define SUNOS5SIGS
 # endif
 
-# if defined(FREEBSD) && (__FreeBSD__ >= 4)
+# if defined(FREEBSD) && ((__FreeBSD__ >= 4) || (__FreeBSD_kernel__ >= 4))
 #   define SUNOS5SIGS
 # endif
 
@@ -2286,7 +2315,7 @@
 #   define CACHE_LINE_SIZE 32	/* Wild guess	*/
 # endif
 
-# ifdef LINUX
+# if defined(LINUX) || defined(__GLIBC__)
 #   define REGISTER_LIBRARIES_EARLY
     /* We sometimes use dl_iterate_phdr, which may acquire an internal	*/
     /* lock.  This isn't safe after the world has stopped.  So we must	*/
@@ -2367,7 +2396,7 @@
 #if defined(SPARC)
 # define CAN_SAVE_CALL_ARGS
 #endif
-#if (defined(I386) || defined(X86_64)) && defined(LINUX)
+#if (defined(I386) || defined(X86_64)) && (defined(LINUX) || defined(__GLIBC__))
 	    /* SAVE_CALL_CHAIN is supported if the code is compiled to save	*/
 	    /* frame pointers by default, i.e. no -fomit-frame-pointer flag.	*/
 # define CAN_SAVE_CALL_ARGS
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/build-rx-dll-sources.sh
@@ -0,0 +1,180 @@
+
+// useful grep
+// grep -h "#if" /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*.cs /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*/*.cs /svn/mono/external/rx/Rx/NET/Source/System.Reactive.*/*/*/*.cs | sort | uniq
+
+using System.Diagnostics;
+using System.IO;
+using System.Xml.Linq;
+using System.Xml.XPath;
+
+var template_android = File.ReadAllText ("project_template_android.txt");
+var template_ios = File.ReadAllText ("project_template_ios.txt");
+
+var guids_android = new string [] { "4fa878dc-6e88-43c4-b37b-8c1151cec56f", "fef62c23-10cd-4def-a5ae-54a8b309e970", "d263c126-9d3c-4299-a0c1-f25c703d07c9", "ec704077-ea31-4852-ad24-6732244174c0", "9360e845-d79d-4288-9100-63a80fad2bf0", "00dc3654-e373-4e3f-80fe-109f795adf1f", "e662282b-4341-4f86-aaaa-a942335b47fb", "a153a379-670c-42c2-9018-fc0d933a4f7f", "b29d45a6-0b8c-49c5-82a2-457e4d3cbc33", "3a3b5e76-029f-46b0-9ccf-fefe06eb61e7", "cb2ab716-bfcb-43bc-a03b-a3bda427746c", "73c5260f-8972-4e7c-822b-1a3a0358fa0b" };
+var guids_ios = new string [] { "6f2675f5-fcc7-4a28-9dc3-657b4613dcc5", "a67f34b5-75c1-4319-a93e-93df87e728a4", "79a43ceb-1a18-49ea-aac4-b72b9c90bf5a", "0a977063-0796-4cd4-84b8-aedb2d648b26", "b41cb61a-dca0-4539-8f99-7b3499e18e6d", "24f995bd-7075-489c-b7a5-7fde08c304b6", "894021ec-14fb-430a-8572-bea9569ae435", "92857c8e-0e83-4d02-a831-8af3fed43336", "912e14a2-7bdf-4600-8d55-e8c4f33a2063", "0f6c2933-8d0c-41e6-9f77-e8714ab8c4ab", "47d85a91-e8e2-4088-bf5a-68a161754d48", "45377009-1425-47fc-985e-05f98022f9e3" };
+
+var asses = new string [] {
+	"System.Reactive.Interfaces",
+	"System.Reactive.Core",
+	"System.Reactive.PlatformServices",
+	"System.Reactive.Linq",
+	"System.Reactive.Debugger", // maybe needed for testing assembly.
+	"System.Reactive.Experimental", // needed for testing assembly.
+	"System.Reactive.Providers",
+	"System.Reactive.Runtime.Remoting",
+	"System.Reactive.Windows.Forms",
+	"System.Reactive.Windows.Threading",
+	"Microsoft.Reactive.Testing",
+	"Tests.System.Reactive",
+	};
+
+var excluded_android_asses = new string [] {
+	"System.Reactive.Windows.Forms",
+	"System.Reactive.Windows.Threading",
+	};
+var excluded_ios_asses = new string [] {
+	"System.Reactive.Providers",
+	"System.Reactive.Windows.Forms",
+	"System.Reactive.Windows.Threading",
+	}
+
+var blacklist = new string [] {
+	// WPF Dispatcher.Invoke() is not implemented.
+	"DispatcherSchedulerTest.cs",
+	// This is not limited to Dispatcher, but many of them are relevant to it, or Winforms (we filter it out by not defining HAS_WINFORMS)
+	"ObservableConcurrencyTest.cs",
+	};
+
+var dstAndroid = "../../external/rx/Rx/NET/Source/Rx_Xamarin/android";
+var dstIOS = "../../external/rx/Rx/NET/Source/Rx_Xamarin/iOS";
+
+int guid_idx = 0;
+foreach (var ass in asses) {
+
+	var monoass = ass == "Microsoft.Reactive.Testing" ?
+		"Mono.Reactive.Testing" : ass;
+	var basePath = "../../external/rx/Rx/NET/Source";
+	var csproj = Path.Combine (basePath, ass, ass + ".csproj");
+	var pathPrefix = ass == "Tests.System.Reactive" ? "../" : "";
+
+	var android_dir = Path.GetFullPath (Path.Combine (csproj, "..", "..", "Rx_Xamarin", "android", "rx", monoass));
+	var ios_dir = Path.GetFullPath (Path.Combine (csproj, "..", "..", "Rx_Xamarin", "iOS", "rx", monoass));
+	var android_proj = Path.Combine (android_dir, "android_" + monoass + ".csproj");
+	var ios_proj = Path.Combine (ios_dir, "ios_" + monoass + ".csproj");
+	if (!Directory.Exists (android_dir))
+		Directory.CreateDirectory (android_dir);
+	if (!Directory.Exists (ios_dir))
+		Directory.CreateDirectory (ios_dir);
+
+	// tests are built under Mono.Reactive.Testing directory.
+	
+	var sources =
+		monoass == "Tests.System.Reactive" ?
+		Path.Combine ("Mono.Reactive.Testing", "Mono.Reactive.Testing_test.dll.sources") :
+		Path.Combine (monoass, monoass + ".dll.sources");
+
+	var assdir = Path.Combine (monoass, "Assembly");
+	var assinfo = Path.Combine (monoass, "Assembly", "AssemblyInfo.cs");
+
+	var projectRefs = "";
+
+	if (monoass != "Tests.System.Reactive") {
+		if (!Directory.Exists (assdir))
+			Directory.CreateDirectory (assdir);
+		using (var tw = File.CreateText (assinfo)) {
+			tw.WriteLine ("[assembly:System.Reflection.AssemblyVersion (\"2.1.30214.0\")]");
+			tw.WriteLine ("[assembly:System.Reflection.AssemblyFileVersion (\"2.1.30214.0\")]");
+		}
+	}
+
+	var sourcesXml = "";
+	var projectRefsXml = "";
+	var resourcesXml = "";
+
+	var signing_xml_template = "<SignAssembly>True</SignAssembly>\n    <DelaySign>True</DelaySign>\n    <AssemblyOriginatorKeyFile>../../../reactive.pub</AssemblyOriginatorKeyFile>\n";
+	var signingXml = ass.StartsWith ("System") ? signing_xml_template : "";
+	
+
+	var doc = XDocument.Load (csproj);
+	var rootNS = doc.XPathSelectElement ("//*[local-name()='RootNamespace']").Value;
+	var guid = doc.XPathSelectElement ("//*[local-name()='ProjectGuid']").Value;
+
+	foreach (var e in doc.XPathSelectElements ("//*[local-name()='ProjectReference']"))
+		projectRefsXml += e;
+
+	Console.WriteLine ("Writing " + sources + " ...");
+	using (var tw = File.CreateText (sources)) {
+		if (monoass != "Tests.System.Reactive")
+			tw.WriteLine ("Assembly/AssemblyInfo.cs");
+		foreach (var path in doc.XPathSelectElements ("//*[local-name()='Compile']")
+			.Select (el => el.Attribute ("Include").Value)
+			.Select (s => s.Replace ("\\", "/"))) {
+			if (!blacklist.Any (b => path.Contains (b))) {
+				var p = Path.Combine ("..", basePath, ass, path);
+				tw.WriteLine (Path.Combine (pathPrefix, p));
+				sourcesXml += "    <Compile Include='..\\..\\..\\..\\..\\..\\" + p.Replace ('/', '\\') + "'>\n      <Link>" + path + "</Link>\n    </Compile>\n";
+			}
+		}
+	}
+
+	Console.WriteLine ("Writing more_build_args...");
+	var argsPath = Path.Combine (Path.GetDirectoryName (sources), "more_build_args");
+	using (var tw = File.CreateText (argsPath)) {
+		if (ass.StartsWith ("System")) {
+			tw.WriteLine ("-d:SIGNED");
+			tw.WriteLine ("-delaysign");
+			tw.WriteLine ("-keyfile:../reactive.pub");
+		}
+
+		foreach (var path in doc.XPathSelectElements ("//*[local-name()='EmbeddedResource']")) {
+			var res = path.Attribute ("Include").Value;
+			var resx = Path.Combine (basePath, ass, res);
+			var resFileName = res.Replace ("resx", "resources");
+			var resxDest = Path.Combine (monoass, res);
+			var resPath = Path.Combine (monoass, resFileName);
+			if (File.Exists (resxDest))
+				File.Delete (resxDest);
+			File.Copy (resx, resxDest);
+			//Process.Start ("resgen", String.Format ("{0} {1}", resx, resPath));
+			tw.WriteLine ("-resource:{0},{1}.{2}", resFileName, rootNS, resFileName);
+			var p = Path.Combine ("..", basePath, ass, res);
+			resourcesXml += "    <EmbeddedResource Include='..\\..\\..\\..\\..\\..\\" + p + "'>\n      <Link>" + res + "</Link>\n    </EmbeddedResource>\n";
+		}
+	}
+	foreach (var f in new string [] { android_proj, ios_proj}) {
+		string prj_guid;
+		string template, prj_prefix, nunitProjRef, nunitRef;
+		var androidNUnit = "<ProjectReference Include=\"..\\..\\Andr.Unit\\Android.NUnitLite\\Android.NUnitLite.csproj\"><Project>{6A005891-A3D6-4398-A729-F645397D573A}</Project><Name>Android.NUnitLite</Name></ProjectReference>";
+		if (f == android_proj) {
+			prj_guid = guids_android [guid_idx];
+			template = template_android;
+			prj_prefix ="android_";
+			nunitProjRef = ass.Contains ("Test") ? androidNUnit : "";
+			nunitRef = "";
+		} else {
+			prj_guid = guids_ios [guid_idx];
+			template = template_ios;
+			prj_prefix ="ios_";
+			nunitProjRef = "";
+			nunitRef = ass.Contains ("Test") ? "<Reference Include='MonoTouch.NUnitLite' />" : "";
+		}
+		using (var tw = File.CreateText (f)) {
+			tw.Write (template
+				.Replace ("PROJECT_GUID_GOES_HERE", '{' + prj_guid + '}')
+				.Replace ("ASSEMBLY_NAME_GOES_HERE", monoass)
+				.Replace ("OPTIONAL_ANDROID_NUNITLITE", nunitProjRef)
+				.Replace ("OPTIONAL_MONOTOUCH_NUNITLITE", nunitRef)
+				.Replace ("PROJECT_REFERENCES_GO_HERE",
+					projectRefsXml
+						.Replace ("Microsoft.Reactive.Testing", "Mono.Reactive.Testing")
+						.Replace ("System", prj_prefix + "System")
+						.Replace ("Mono", prj_prefix + "Mono")
+						.Replace ("Include=\"..\\" + prj_prefix, "Include=\"..\\"))
+				.Replace ("RESOURCES_GO_HERE", sourcesXml.Replace ('\\', f == ios_proj ? '/' : '\\')) // whoa, BACKSLASH doesn't work only on android on MD/mac...!
+				.Replace ("SOURCES_GO_HERE", resourcesXml.Replace ('\\', f == ios_proj ? '/' : '\\')) // whoa, BACKSLASH doesn't work only on android on MD/mac...!
+				.Replace ("SIGNING_SPEC_GOES_HERE", signingXml));
+		}
+	}
+	guid_idx++;
+}
+
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Forms/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Forms/Reactive/Linq/ControlObservable.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Forms/Reactive/Concurrency/ControlScheduler.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Windows.Forms/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Net/Makefile
+++ mono-3.0.6+dfsg2/mcs/class/System.Net/Makefile
@@ -3,7 +3,7 @@ SUBDIRS =
 include ../../build/rules.make
 
 LIBRARY = System.Net.dll
-LIB_MCS_FLAGS =  -unsafe -r:System.dll -r:System.Core.dll -r:System.Xml.dll -d:NET_2_1 -d:NET_2_0 -d:NET_1_1
+LIB_MCS_FLAGS =  -unsafe -r:System.dll -r:System.Core.dll -r:System.Xml.dll
 
 ifneq (2.1, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720
--- mono-3.0.6+dfsg2.orig/mcs/class/Mono.WebBrowser/Mono.WebBrowser.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/Mono.WebBrowser/Mono.WebBrowser.dll.sources
@@ -133,6 +133,9 @@ Mono.Mozilla/interfaces/nsIWebNavigation
 Mono.Mozilla/interfaces/extras/NodeType.cs
 Mono.Mozilla/interfaces/extras/nsIWriteSegmentFun.cs
 Mono.Mozilla/interfaces/extras/Options.cs
+Mono.NullBrowser/Base.cs
+Mono.NullBrowser/WebBrowser.cs
+Mono.NullBrowser/DOM/Navigation.cs
 Mono.WebBrowser/DOM/IDocumentType.cs
 Mono.WebBrowser/DOM/IDOMImplementation.cs
 Mono.WebBrowser/DOM/IMediaList.cs
--- mono-3.0.6+dfsg2.orig/mcs/class/Mono.WebBrowser/Mono.WebBrowser/Manager.cs
+++ mono-3.0.6+dfsg2/mcs/class/Mono.WebBrowser/Mono.WebBrowser/Manager.cs
@@ -52,8 +52,15 @@ namespace Mono.WebBrowser
 				}
 			}
 #endif
-			if (browserEngine == null || browserEngine == "mozilla")
-				return new Mono.Mozilla.WebBrowser (platform);
+			if (browserEngine == "mozilla") {
+				try {
+					return new Mono.Mozilla.WebBrowser (platform);
+				} catch {
+					browserEngine = null;
+				}
+			}
+			if (browserEngine == null)
+				return new Mono.NullBrowser.WebBrowser (platform);
 			throw new Exception (Mono.WebBrowser.Exception.ErrorCodes.EngineNotSupported, browserEngine);
 		}
 
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/Mono.WebBrowser/Mono.NullBrowser/WebBrowser.cs
@@ -0,0 +1,414 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+// Copyright (c) 2013 Jo Shields
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//	Jo Shields (directhex@apebox.org)
+//
+
+#undef debug
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Diagnostics;
+using Mono.WebBrowser;
+using Mono.WebBrowser.DOM;
+
+namespace Mono.NullBrowser
+{
+	internal class WebBrowser : IWebBrowser
+	{
+		bool loaded;
+		internal bool created = false;
+		bool creating = false;
+
+                internal DOM.Navigation navigation;
+
+		internal Platform platform;
+		internal Platform enginePlatform;
+		System.ComponentModel.EventHandlerList events;
+		System.ComponentModel.EventHandlerList domEvents;
+
+		string statusText;
+
+		bool streamingMode;
+		
+		internal Hashtable documents;
+
+		int width;
+		int height;
+		bool isDirty;
+		
+		public WebBrowser (Platform platform)
+		{
+			this.platform = platform;
+			loaded = Base.Init (this, platform);
+			documents = new Hashtable ();
+		}
+
+		public bool Load (IntPtr handle, int width, int height)
+		{
+			loaded = Base.Bind (this, handle, width, height);
+			return loaded;
+		}
+
+		bool Created {
+			get {
+				if (!creating && !created) {
+					creating = true;
+					created = Base.Create (this);
+					if (created && isDirty) {
+						isDirty = false;
+						Base.Resize (this, width, height);
+					}
+				}
+				return created;
+			}
+		}
+
+		public void Shutdown ()
+		{
+			Base.Shutdown (this);
+		}
+		
+		internal void Reset ()
+		{
+			this.DomEvents.Dispose ();
+			this.domEvents = null;
+			this.documents.Clear ();
+		}
+
+		public bool Initialized {
+			get { return this.loaded; }
+		}
+		
+		public IWindow Window {
+			get {
+				return null;
+			}
+		}
+
+		public IDocument Document {
+			get {
+				return null;
+			}
+		}
+
+		public INavigation Navigation {
+			get {
+                                if (!Created) return null;
+
+                                if (navigation == null) {
+
+                                        navigation = new DOM.Navigation ();
+                                }
+                                return navigation as INavigation;
+			}
+		}
+		
+		public string StatusText {
+			get { return statusText; }
+		}
+		
+		public bool Offline {
+			get {
+				return false;
+			}
+			set {
+			}
+		}
+		
+		internal System.ComponentModel.EventHandlerList DomEvents {
+			get {
+				if (domEvents == null)
+					domEvents = new System.ComponentModel.EventHandlerList();
+
+				return domEvents;
+			}
+		}
+
+		internal System.ComponentModel.EventHandlerList Events {
+			get {
+				if (events == null)
+					events = new System.ComponentModel.EventHandlerList();
+
+				return events;
+			}
+		}
+		
+		#region Layout
+		public void FocusIn (FocusOption focus)
+		{
+			if (!created) return;
+			Base.Focus (this, focus);
+		}
+		public void FocusOut ()
+		{
+			if (!created) return;
+			Base.Blur (this);
+		}
+		
+		public void Activate ()
+		{
+			if (!Created) return;
+			Base.Activate (this);
+		}
+		public void Deactivate ()
+		{
+			if (!created) return;
+			Base.Deactivate (this);
+		}
+
+		public void Resize (int width, int height)
+		{
+			this.width = width;
+			this.height = height;
+			isDirty = true;
+			if (!created) return;
+			Base.Resize (this, width, height);			
+		}
+
+		public void Render (byte[] data)
+		{
+			if (!Created) return;
+			if (data == null)
+				throw new ArgumentNullException ("data");
+			string html = System.Text.ASCIIEncoding.UTF8.GetString (data);
+			Render (html);
+		}
+
+		public void Render (string html)
+		{
+			if (!Created) return;
+			Render (html, "file:///", "text/html");
+		}
+
+				
+		public void Render (string html, string uri, string contentType)
+		{
+			if (!Created) return;
+			throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.Navigation);
+
+			IntPtr native_html = Marshal.StringToHGlobalAnsi (html);
+			Marshal.FreeHGlobal (native_html);
+
+
+		}
+		
+		public void ExecuteScript (string script) {
+			if (!Created) return;
+			Base.EvalScript (this, script);
+		}
+				
+		internal void AttachEvent (INode node, string eve, EventHandler handler) {
+			string key = String.Intern (node.GetHashCode() + ":" + eve);
+#if debug
+			Console.Error.WriteLine ("Event Attached: " + key);
+#endif
+			DomEvents.AddHandler (key, handler);
+		}
+
+		internal void DetachEvent (INode node, string eve, EventHandler handler) {
+			string key = String.Intern (node.GetHashCode() + ":" + eve);
+#if debug			
+			Console.Error.WriteLine ("Event Detached: " + key);
+#endif			
+			DomEvents.RemoveHandler (key, handler);
+		}
+		
+		#endregion
+
+		#region Events
+		internal static object KeyDownEvent = new object ();
+		internal static object KeyPressEvent = new object ();
+		internal static object KeyUpEvent = new object ();
+		internal static object MouseClickEvent = new object ();
+		internal static object MouseDoubleClickEvent = new object ();
+		internal static object MouseDownEvent = new object ();
+		internal static object MouseEnterEvent = new object ();
+		internal static object MouseLeaveEvent = new object ();
+		internal static object MouseMoveEvent = new object ();
+		internal static object MouseUpEvent = new object ();
+		internal static object FocusEvent = new object ();
+		internal static object BlurEvent = new object ();
+		internal static object CreateNewWindowEvent = new object ();
+		internal static object AlertEvent = new object ();
+			
+		internal static object LoadStartedEvent = new object ();
+		internal static object LoadCommitedEvent = new object ();
+		internal static object ProgressChangedEvent = new object ();
+		internal static object LoadFinishedEvent = new object ();	
+		
+		internal static object LoadEvent = new object ();
+		internal static object UnloadEvent = new object ();
+		internal static object StatusChangedEvent = new object ();
+		internal static object SecurityChangedEvent = new object ();
+		internal static object ProgressEvent = new object ();
+		internal static object ContextMenuEvent = new object ();
+		
+		internal static object NavigationRequestedEvent = new object ();
+		
+		public event NodeEventHandler KeyDown
+		{
+			add { Events.AddHandler (KeyDownEvent, value); }
+			remove { Events.RemoveHandler (KeyDownEvent, value); }
+		}
+
+		public event NodeEventHandler KeyPress
+		{
+			add { Events.AddHandler (KeyPressEvent, value); }
+			remove { Events.RemoveHandler (KeyPressEvent, value); }
+		}
+		public event NodeEventHandler KeyUp
+		{
+			add { Events.AddHandler (KeyUpEvent, value); }
+			remove { Events.RemoveHandler (KeyUpEvent, value); }
+		}
+		public event NodeEventHandler MouseClick
+		{
+			add { Events.AddHandler (MouseClickEvent, value); }
+			remove { Events.RemoveHandler (MouseClickEvent, value); }
+		}
+		public event NodeEventHandler MouseDoubleClick
+		{
+			add { Events.AddHandler (MouseDoubleClickEvent, value); }
+			remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
+		}
+		public event NodeEventHandler MouseDown
+		{
+			add { Events.AddHandler (MouseDownEvent, value); }
+			remove { Events.RemoveHandler (MouseDownEvent, value); }
+		}
+		public event NodeEventHandler MouseEnter
+		{
+			add { Events.AddHandler (MouseEnterEvent, value); }
+			remove { Events.RemoveHandler (MouseEnterEvent, value); }
+		}
+		public event NodeEventHandler MouseLeave
+		{
+			add { Events.AddHandler (MouseLeaveEvent, value); }
+			remove { Events.RemoveHandler (MouseLeaveEvent, value); }
+		}
+		public event NodeEventHandler MouseMove
+		{
+			add { Events.AddHandler (MouseMoveEvent, value); }
+			remove { Events.RemoveHandler (MouseMoveEvent, value); }
+		}
+		public event NodeEventHandler MouseUp
+		{
+			add { Events.AddHandler (MouseUpEvent, value); }
+			remove { Events.RemoveHandler (MouseUpEvent, value); }
+		}
+		public event EventHandler Focus
+		{
+			add { Events.AddHandler (FocusEvent, value); }
+			remove { Events.RemoveHandler (FocusEvent, value); }
+		}
+		public event EventHandler Blur
+		{
+			add { Events.AddHandler (BlurEvent, value); }
+			remove { Events.RemoveHandler (BlurEvent, value); }
+		}
+		public event CreateNewWindowEventHandler CreateNewWindow
+		{
+			add { Events.AddHandler (CreateNewWindowEvent, value); }
+			remove { Events.RemoveHandler (CreateNewWindowEvent, value); }
+		}
+		public event AlertEventHandler Alert
+		{
+			add { Events.AddHandler (AlertEvent, value); }
+			remove { Events.RemoveHandler (AlertEvent, value); }
+		}
+		public event EventHandler Loaded
+		{
+			add { Events.AddHandler (LoadEvent, value); }
+			remove { Events.RemoveHandler (LoadEvent, value); }
+		}
+		public event EventHandler Unloaded
+		{
+			add { Events.AddHandler (UnloadEvent, value); }
+			remove { Events.RemoveHandler (UnloadEvent, value); }
+		}
+
+ 		public event StatusChangedEventHandler StatusChanged
+		{
+			add { Events.AddHandler (StatusChangedEvent, value); }
+			remove { Events.RemoveHandler (StatusChangedEvent, value); }
+		}
+		
+ 		public event SecurityChangedEventHandler SecurityChanged
+		{
+			add { Events.AddHandler (SecurityChangedEvent, value); }
+			remove { Events.RemoveHandler (SecurityChangedEvent, value); }
+		}
+
+		public event LoadStartedEventHandler LoadStarted
+		{
+			add { Events.AddHandler (LoadStartedEvent, value); }
+			remove { Events.RemoveHandler (LoadStartedEvent, value); }
+		}
+		
+		public event LoadCommitedEventHandler LoadCommited
+		{
+			add { Events.AddHandler (LoadCommitedEvent, value); }
+			remove { Events.RemoveHandler (LoadCommitedEvent, value); }
+		}		
+		
+		public event ProgressChangedEventHandler ProgressChanged
+		{
+			add { Events.AddHandler (ProgressChangedEvent, value); }
+			remove { Events.RemoveHandler (ProgressChangedEvent, value); }
+		}
+		
+		public event LoadFinishedEventHandler LoadFinished
+		{
+			add { Events.AddHandler (LoadFinishedEvent, value); }
+			remove { Events.RemoveHandler (LoadFinishedEvent, value); }
+		}
+
+		public event ContextMenuEventHandler ContextMenuShown
+		{
+			add { Events.AddHandler (ContextMenuEvent, value); }
+			remove { Events.RemoveHandler (ContextMenuEvent, value); }
+		}
+
+		public event NavigationRequestedEventHandler NavigationRequested
+		{
+			add { }
+			remove { }
+		}
+
+		internal static object GenericEvent = new object ();
+		internal event EventHandler Generic
+		{
+			add { Events.AddHandler (GenericEvent, value); }
+			remove { Events.RemoveHandler (GenericEvent, value); }
+		}
+
+		#endregion
+
+
+	}
+}
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/Mono.WebBrowser/Mono.NullBrowser/Base.cs
@@ -0,0 +1,174 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//
+
+using System;
+using System.Text;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+using Mono.WebBrowser;
+
+namespace Mono.NullBrowser
+{
+	internal class Base
+	{
+		private static Hashtable boundControls;
+		private static bool initialized;
+		private static object initLock = new object ();
+		private static string monoMozDir;
+
+		private static bool isInitialized ()
+		{
+			if (!initialized)
+				return false;
+			return true;
+		}
+
+		static Base ()
+		{
+			boundControls = new Hashtable ();
+		}
+
+		public Base () { }
+
+		public static bool Init (WebBrowser control, Platform platform)
+		{
+			lock (initLock) {
+				if (!initialized) {
+				
+					initialized = true;
+				}
+			}
+			return initialized;
+		}
+
+		public static bool Bind (WebBrowser control, IntPtr handle, int width, int height)
+		{
+			if (!isInitialized ())
+				return false;
+
+			
+			return true;
+		}
+
+		public static bool Create (IWebBrowser control) {
+			if (!isInitialized ())
+				return false;
+
+			return true;
+		}
+
+		public static void Shutdown (IWebBrowser control)
+		{
+			lock (initLock) {
+				if (!initialized)
+					return;
+					
+				
+				boundControls.Remove (control);
+				if (boundControls.Count == 0) {
+					initialized = false;
+				}
+			}
+		}
+
+		// layout
+		public static void Focus (IWebBrowser control, FocusOption focus)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+
+		public static void Blur (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Activate (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Deactivate (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Resize (IWebBrowser control, int width, int height)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		// navigation
+		public static void Home (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+
+		public static IntPtr StringInit ()
+		{
+			return IntPtr.Zero;
+		}
+
+		public static void StringFinish (HandleRef str)
+		{
+		}
+
+		public static string StringGet (HandleRef str)
+		{
+			return String.Empty;
+		}
+
+		public static void StringSet (HandleRef str, string text)
+		{
+		}
+
+
+		public static object GetProxyForObject (IWebBrowser control, Guid iid, object obj)
+		{
+			return null;
+		}
+
+		public static string EvalScript (IWebBrowser control, string script)
+		{
+			return null;
+		}
+
+
+	}
+}
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/Mono.WebBrowser/Mono.NullBrowser/DOM/Navigation.cs
@@ -0,0 +1,127 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//
+
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+using Mono.WebBrowser;
+using Mono.WebBrowser.DOM;
+
+namespace Mono.NullBrowser.DOM
+{
+	internal class Navigation: INavigation
+	{
+
+
+		#region INavigation Members
+
+		public bool CanGoBack {
+			get {
+				return false;
+			}
+		}
+
+		public bool CanGoForward {
+			get {
+				return false;
+			}
+		}
+
+		public bool Back ()
+		{
+			return false;
+		}
+
+		public bool Forward ()
+		{
+			return false;
+		}
+
+		public void Home ()
+		{
+		}
+
+		public void Reload ()
+		{
+		}
+
+		public void Reload (ReloadOption option)
+		{
+		}
+
+		public void Stop ()
+		{
+		}
+		
+		
+		/// <summary>
+		/// Navigate to the page in the history, by index.
+		/// </summary>
+		/// <param name="index">
+		/// A <see cref="System.Int32"/> representing an absolute index in the 
+		/// history (that is, > -1 and < history length
+		/// </param>
+		public void Go (int index)
+		{
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="index">
+		/// A <see cref="System.Int32"/> representing an index in the 
+		/// history, that can be relative or absolute depending on the relative argument
+		/// </param>
+		/// <param name="relative">
+		/// A <see cref="System.Boolean"/> indicating whether the index is relative to 
+		/// the current place in history or not (i.e., if relative = true, index can be
+		/// positive or negative, and index=-1 means load the previous page in the history.
+		/// if relative = false, index must be > -1, and index = 0 means load the first
+		/// page of the history.
+		/// </param>
+		public void Go (int index, bool relative) {
+		}
+		
+		public void Go (string url)
+		{
+		}
+
+		public void Go (string url, LoadFlags flags) 
+		{
+		}
+
+		public int HistoryCount {
+			get {
+				return 0;
+			}
+		}
+
+		#endregion
+
+		public override int GetHashCode () {
+			return 0;
+		}		
+	}
+}
--- mono-3.0.6+dfsg2.orig/mcs/class/corlib/System.Reflection/MethodBase.cs
+++ mono-3.0.6+dfsg2/mcs/class/corlib/System.Reflection/MethodBase.cs
@@ -88,8 +88,17 @@ namespace System.Reflection {
 		// This is a quick version for our own use. We should override
 		// it where possible so that it does not allocate an array.
 		//
-		internal abstract ParameterInfo[] GetParametersInternal ();
-		internal abstract int GetParametersCount ();
+		internal virtual ParameterInfo[] GetParametersInternal ()
+		{
+			// Override me
+			return GetParameters ();
+		}
+
+		internal virtual int GetParametersCount ()
+		{
+			// Override me
+			return GetParametersInternal ().Length;
+		}
 
 		internal virtual Type GetParameterType (int pos) {
 			throw new NotImplementedException ();
--- mono-3.0.6+dfsg2.orig/mcs/class/corlib/Test/System.Reflection/BinderTests.cs
+++ mono-3.0.6+dfsg2/mcs/class/corlib/Test/System.Reflection/BinderTests.cs
@@ -101,6 +101,80 @@ namespace MonoTests.System.Reflection
 		}
 	}
 
+	class MethodInfoWrapper : MethodInfo
+	{
+		private readonly MethodInfo method;
+		
+		public MethodInfoWrapper (MethodInfo method)
+		{
+			this.method = method;
+		}
+		
+		public override object[] GetCustomAttributes (bool inherit)
+		{
+			return method.GetCustomAttributes (inherit);
+		}
+		
+		public override bool IsDefined (Type attributeType, bool inherit)
+		{
+			return method.IsDefined (attributeType, inherit);
+		}
+		
+		public override ParameterInfo[] GetParameters ()
+		{
+			return method.GetParameters ();
+		}
+		
+		public override MethodImplAttributes GetMethodImplementationFlags ()
+		{
+			return method.GetMethodImplementationFlags ();
+		}
+		
+		public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
+		{
+			return method.Invoke (obj, invokeAttr, binder, parameters, culture);
+		}
+		
+		public override MethodInfo GetBaseDefinition ()
+		{
+			return method.GetBaseDefinition ();
+		}
+		
+		public override ICustomAttributeProvider ReturnTypeCustomAttributes {
+			get { return method.ReturnTypeCustomAttributes; }
+		}
+		
+		public override string Name {
+			get { return method.Name; }
+		}
+		
+		public override Type ReturnType {
+			get { return method.ReturnType; }
+		}
+		
+		public override Type DeclaringType {
+			get { return method.DeclaringType; }
+		}
+		
+		public override Type ReflectedType {
+			get { return method.ReflectedType; }
+		}
+		
+		public override RuntimeMethodHandle MethodHandle {
+			get { return method.MethodHandle; }
+		}
+		
+		public override MethodAttributes Attributes {
+			get { return method.Attributes; }
+		}
+		
+		public override object[] GetCustomAttributes (Type attributeType, bool inherit)
+		{
+			return method.GetCustomAttributes (attributeType, inherit);
+		}
+	}
+
+
 	[TestFixture]
 	public class BinderTest
 	{
@@ -1395,5 +1469,18 @@ namespace MonoTests.System.Reflection
 				null, // target
 				new object [] { CultureInfo.CurrentCulture, "foo{0}{1}", "bar", "baz" }));
 		}
+
+		public static void CustomMethodType_Helper ()
+		{
+		}
+
+		[Test]
+		public void CustomMethodType ()
+		{
+			var method = new MethodInfoWrapper (GetType ().GetMethod ("CustomMethodType_Helper"));
+
+			var res = Type.DefaultBinder.SelectMethod (BindingFlags.Static | BindingFlags.Public, new[] { method }, Type.EmptyTypes, new ParameterModifier[0]);
+			Assert.AreSame (method, res);
+		}
 	}
 }
--- mono-3.0.6+dfsg2.orig/mcs/class/corlib/System/Console.cs
+++ mono-3.0.6+dfsg2/mcs/class/corlib/System/Console.cs
@@ -133,8 +133,7 @@ namespace System
 				int code_page = 0;
 				Encoding.InternalCodePage (ref code_page);
 
-				if (code_page != -1 && ((code_page & 0x0fffffff) == 3 // UTF8Encoding.UTF8_CODE_PAGE
-					|| ((code_page & 0x10000000) != 0)))
+				if (code_page == UTF8Encoding.UTF8_CODE_PAGE || ((code_page & 0x10000000) != 0))
 					inputEncoding = outputEncoding = Encoding.UTF8Unmarked;
 				else
 					inputEncoding = outputEncoding = Encoding.Default;
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Runtime.Remoting/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Runtime.Remoting/Properties/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Runtime.Remoting/Reactive/Linq/Observable.Remoting.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Runtime.Remoting/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Experimental/System.Reactive.Experimental.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Experimental/System.Reactive.Experimental.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Experimental/ExperimentalAttribute.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Experimental/InternalsVisibleTo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Experimental/Properties/AssemblyInfo.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Experimental/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Core/System.Reactive.Core.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Core/System.Reactive.Core.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Core/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Core/InternalsVisibleTo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Core/NamespaceDocs.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Core/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Debugger/System.Reactive.Debugger.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Debugger/System.Reactive.Debugger.dll.sources
@@ -1,2 +1,3 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Debugger/Properties/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Debugger/Reactive/Linq/QueryDebugger.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Debugger/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Linq/System.Reactive.Linq.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Linq/System.Reactive.Linq.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Linq/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Linq/NamespaceDocs.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Linq/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
+++ mono-3.0.6+dfsg2/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
@@ -553,14 +553,16 @@ namespace Microsoft.Build.BuildEngine {
 
 		public string DefaultToolsVersion {
 			get {
-				// This is used as the fall back version if the
-				// project can't find a version to use
-				// Hard-coded to 2.0, so it allows even vs2005 projects
-				// to build correctly, as they won't have a ToolsVersion
-				// set!
-				return String.IsNullOrEmpty (defaultToolsVersion)
-						? "2.0"
-						: defaultToolsVersion;
+				if (String.IsNullOrEmpty (defaultToolsVersion))
+#if NET_4_0
+					return "4.0";
+#elif NET_3_5
+					return "3.5";
+#else
+					return "2.0";
+#endif
+				
+				return defaultToolsVersion;
 			}
 			set {
 				if (Toolsets [value] == null)
--- mono-3.0.6+dfsg2.orig/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs
+++ mono-3.0.6+dfsg2/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs
@@ -466,10 +466,11 @@ namespace Monodoc.Providers
 				break;
 			// binary operators: overloading is possible [ECMA-335 §10.3.2]
 			default:
-				memberSignature =
-					nicename + "("
-					+ string.Join (",", member.Element ("Parameters").Elements ("Parameter").Select (p => (string)p.Attribute ("Type")))
-					+ ")";
+				if (member.Element ("Parameters") != null)
+					memberSignature =
+						nicename + "("
+						+ string.Join (",", member.Element ("Parameters").Elements ("Parameter").Select (p => (string)p.Attribute ("Type")))
+						+ ")";
 				break;
 			}
 
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Threading/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Threading/Reactive/Concurrency/CoreDispatcherScheduler.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Windows.Threading/Reactive/Internal/Constants.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Windows.Threading/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.PlatformServices/System.Reactive.PlatformServices.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.PlatformServices/System.Reactive.PlatformServices.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.PlatformServices/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.PlatformServices/Properties/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.Windows.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.PlatformServices/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Providers/System.Reactive.Providers.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Providers/System.Reactive.Providers.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Providers/GlobalSuppressions.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Providers/Properties/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Providers/Reactive/Internal/Constants.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Providers/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- mono-3.0.6+dfsg2.orig/mcs/class/System.Reactive.Interfaces/System.Reactive.Interfaces.dll.sources
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Interfaces/System.Reactive.Interfaces.dll.sources
@@ -1,3 +1,4 @@
+Assembly/AssemblyInfo.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Interfaces/AssemblyFileVersionAttribute.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Interfaces/DateTimeOffset.cs
 ../../../external/rx/Rx/NET/Source/System.Reactive.Interfaces/GlobalSuppressions.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/System.Reactive.Interfaces/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/Mono.Reactive.Testing/Mono.Reactive.Testing.dll.sources
@@ -0,0 +1,14 @@
+Assembly/AssemblyInfo.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/ColdObservable.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/GlobalSuppressions.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/HotObservable.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/ITestObservable.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/ITestObserver.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/MockObserver.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/NamespaceDoc.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/Properties/AssemblyInfo.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/ReactiveAssert.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/ReactiveTest.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/Recorded.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/Subscription.cs
+../../../external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/TestScheduler.cs
--- /dev/null
+++ mono-3.0.6+dfsg2/mcs/class/Mono.Reactive.Testing/Assembly/AssemblyInfo.cs
@@ -0,0 +1,2 @@
+[assembly:System.Reflection.AssemblyVersion ("2.1.30214.0")]
+[assembly:System.Reflection.AssemblyFileVersion ("2.1.30214.0")]
