[Mono-winforms-list] Monostub for Wine SWF

John Sohn jsohn@columbus.rr.com
11 Mar 2003 02:22:49 -0500

Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is great news! This is quite an accomplishment. I have been trying
to get Wine to work with the Boehm garbage collector. I was taking the
same approach you did with the sem_ functions matching
scheduler/pthread.c from the Wine project but you definitely made more
progress on this than I was able to.

I was able to get the Boehm GC library to compile and install under
WineLib by making some minor changes to the header files and source. The
#ifdef's basically were not aware of _LINUX and _WIN32 being defined at
the same time. Running winemaker in the gc6.1 directory then generated
the configure;make install scripts. I have this for download at:
http://www.geocities.com/john_sohn/gc6.1-wine.tar.gz. Running the
./configure;make;make install on this project will then install the
Boehm GC WineLib DLL into the Wine environment.

I also added monogc.c to the latest monostub application in CVS which is
attached to this message. With these changes I was able to get the
latest monostub application to work with garbage collection enabled. It
may be possible to get the monostub and GC-enabled Mono to work without
these changes but currently it segfaults for me. I think there is still
some work required but perhaps this can be of some of use.


> I've checked in modifications to monostub. Wine/SWF applications should 
> start now under Linux. Better to redirect stderr, due to output from 
> Wine's pthread_cond*.
> I was interested in running Mono Interpreter to debug SWF apps, 
> so I added an implementation of pthreads functions sem* and
> pthread_cond*.
> Currently, the functions are inside monostub and it's necessarily 
> to comment them in Wine's scheduler/phreads.c to let them work.
> May be it will be logical to put the functions into separate 
> library and use LD_PRELOAD ?
> Alexandre Pigolkine
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Content-Disposition: attachment; filename=monogc.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c; name=monogc.c; charset=UTF-8

#include <windows.h>
#include <stdio.h>
#include <gc/gc.h>
#include <pthread.h>

int GC_finalize_on_demand =3D -1;
void (* GC_finalizer_notifier)() =3D (void (*) GC_PROTO((void)))0;

void InitGC ()
	printf ("Initializing Boehm GC library...\n");
	moduleGC =3D LoadLibraryA ("gc.dll");

	if (moduleGC =3D=3D NULL) {
		exit (1);


GC_PTR GC_malloc (size_t lb)
	GC_PTR (*gc_malloc)(size_t lb);
	GC_PTR status =3D NULL;
	gc_malloc =3D GetProcAddress (moduleGC, "GC_malloc");

	printf ("GC_malloc start\n");
	status =3D gc_malloc (lb);
	printf ("GC_malloc end\n");
	return status;

void GC_register_finalizer (GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
		GC_finalization_proc *ofn, GC_PTR *ocd)
	void (*gc_register_finalizer)(GC_PTR obj, GC_finalization_proc fn,=20
			GC_PTR cd, GC_finalization_proc *ofn, GC_PTR *ocd);
	printf ("GC_register_finalizer\n");
	gc_register_finalizer =3D=20
		GetProcAddress (moduleGC, "GC_register_finalizer");
	gc_register_finalizer (obj, fn, cd, ofn, ocd);
	printf ("GC_register_finalizer end\n");

void GC_register_finalizer_no_order (GC_PTR obj, GC_finalization_proc fn,
				     GC_PTR cd, GC_finalization_proc *ofn,=20
				     GC_PTR *ocd)
	void (*gc_register_finalizer_no_order)(GC_PTR obj,=20
			GC_finalization_proc fn, GC_PTR cd,=20
			GC_finalization_proc *ofn, GC_PTR *ocd);
	gc_register_finalizer_no_order =3D=20
		GetProcAddress (moduleGC, "GC_register_finalizer");
	printf ("GC_register_finalizer_no_order\n");
	gc_register_finalizer_no_order (obj, fn, cd, ofn, ocd);
	printf ("GC_register_finalizer_no_order end\n");

GC_PTR GC_debug_malloc (size_t size_in_bytes, GC_EXTRA_PARAMS)
	return GC_malloc (size_in_bytes);

GC_PTR GC_malloc_atomic (size_t size_in_bytes)
	GC_PTR (*gc_malloc_atomic)(size_t lb);
	GC_PTR status =3D NULL;
	gc_malloc_atomic =3D GetProcAddress (moduleGC, "GC_malloc_atomic");

	printf ("GC_malloc_atomic start\n");
	status =3D gc_malloc_atomic (size_in_bytes);
	printf ("GC_malloc_atomic end\n");
	return status;

GC_PTR GC_realloc (GC_PTR old_object, size_t new_size_in_bytes)
	GC_PTR (*gc_realloc)(GC_PTR old_object, size_t new_size_in_bytes);
	GC_PTR status =3D NULL;
	gc_realloc =3D GetProcAddress (moduleGC, "GC_realloc");

	printf ("GC_realloc start\n");
	status =3D gc_realloc (old_object, new_size_in_bytes);
	printf ("GC_realloc end\n");
	return status;

GC_PTR GC_base (GC_PTR displaced_pointer)
	GC_PTR (*gc_base)(GC_PTR displaced_pointer);
	GC_PTR status =3D NULL;

	printf ("in GC_base\n");
	gc_base =3D GetProcAddress (moduleGC, "GC_base");
	printf ("GC_base start\n");
	status =3D gc_base (displaced_pointer);
	printf ("GC_base end\n");
	return status;

void GC_free (GC_PTR object_addr)
	GC_PTR (*gc_free)(GC_PTR object_addr);
	printf ("GC_free start\n");
	gc_free =3D GetProcAddress (moduleGC, "GC_free");
	gc_free (object_addr);
	printf ("GC_free end\n");

void GC_gcollect ()
	GC_PTR (*gc_gcollect)();
	printf ("GC_gcollect start\n");
	gc_gcollect =3D GetProcAddress (moduleGC, "GC_gcollect");
	gc_gcollect ();
	printf ("GC_gcollect end\n");

size_t GC_get_heap_size ()
	size_t (*gc_get_heap_size)();
	size_t status =3D 0;

	printf ("in GC_get_heap_size\n");
	gc_get_heap_size =3D GetProcAddress (moduleGC, "GC_get_heap_size");
	printf ("GC_get_heap_size start\n");
	status =3D gc_get_heap_size ();
	printf ("GC_get_heap_size end\n");
	return status;

int GC_invoke_finalizers ()
	int (*gc_invoke_finalizers)();
	int status =3D 0;

	gc_invoke_finalizers =3D GetProcAddress (moduleGC, "GC_invoke_finalizers")=
	printf ("GC_invoke_finalizers start\n");
	status =3D gc_invoke_finalizers ();
	printf ("GC_invoke_finalizers end\n");
	return status;

int GC_unregister_disappearing_link (GC_PTR *link)
	printf ("GC_unregister_disappearing_link (not implenented)\n");
	return 0;

int GC_general_register_disappearing_link (GC_PTR *link, GC_PTR obj)
	printf ("GC_general_register_disappearing_link (not implemented)\n");
	return 0;

// GC pthread wrapper
int GC_pthread_create (pthread_t *new_thread,
		       const pthread_attr_t *attr,
		       void *(*start_routine)(void *), void *arg)
	printf ("GC_pthread_create\n");
	return pthread_create (new_thread, attr, start_routine, arg);

int GC_pthread_sigmask (int how, const sigset_t *set, sigset_t *oset)
	printf ("GC_pthread_sigmask\n");
	pthread_sigmask (how, set, oset);

int GC_pthread_join (pthread_t thread, void **retval)
	printf ("GC_pthread_join\n");
	return pthread_join (thread, retval);

int GC_pthread_detach (pthread_t thread)
	printf ("GC_pthread_detach\n");
	return pthread_detach (thread);