Re: out-of-mem handler
- From: Sebastian Wilhelmi <wilhelmi ira uka de>
- To: gtk-devel-list redhat com
- Subject: Re: out-of-mem handler
- Date: Wed, 16 Feb 2000 17:43:54 +0000
Hi Havoc,
> Yes, you're right, stupid of me, but please wait a bit, I'm just making
> a patch against HEAD gnome-session, that might solve, what you want...
> It's a special purpose, so a special solutions fits well.
Ok, here we go, attached is a patch against HEAD gnome-core, that makes
intercepting of malloc possible on many platforms (they need to have ldd and a
g_module implementation), specifaclly Linux and Solaris are working. I tried
it here.
TODO:
* remove the debug printf's.
* also intercept realloc and maybe calloc.
* refrain from adding g_malloc interceptors to GLib ;-)
Bye,
Sebastian
--
Sebastian Wilhelmi | här ovanför alla molnen
mailto:wilhelmi@ira.uka.de | är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi |
Index: acconfig.h
===================================================================
RCS file: /cvs/gnome/gnome-core/acconfig.h,v
retrieving revision 1.22
diff -u -b -B -a -u -r1.22 acconfig.h
--- acconfig.h 1999/10/20 00:56:52 1.22
+++ acconfig.h 2000/02/16 17:38:08
@@ -44,3 +44,5 @@
#undef HAVE_ZVT_TERM_RESET
#undef HAVE_HOSTS_ACCESS
+
+#undef LIBCNAME
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-core/configure.in,v
retrieving revision 1.225
diff -u -b -B -a -u -r1.225 configure.in
--- configure.in 2000/02/15 08:18:57 1.225
+++ configure.in 2000/02/16 17:38:09
@@ -86,6 +86,22 @@
dnl
dnl gnome-session
dnl
+
+AC_MSG_CHECKING("for the dynamic libc")
+echo "main(){}" >conftest.c
+eval $ac_link 2>&5
+LIBCNAME=`ldd conftest 2>/dev/null| grep 'libc\.' | sed 's:.*=>::;s:(.*::;'`
+# get rid of the whitespace padding
+LIBCNAME=`echo $LIBCNAME`
+rm -rf conftest*
+if test "x$LIBCNAME" = x; then
+ AC_MSG_RESULT(not found)
+else
+ AC_MSG_RESULT($LIBCNAME)
+ # get rid of the padding
+ AC_DEFINE_UNQUOTED(LIBCNAME,"$LIBCNAME")
+fi
+
dnl $GNOME_HAVE_SM comes from GNOME_X_CHECKS
AM_CONDITIONAL(SESSION, test "$GNOME_HAVE_SM" = true)
Index: gsm/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/Makefile.am,v
retrieving revision 1.38
diff -u -b -B -a -u -r1.38 Makefile.am
--- gsm/Makefile.am 2000/01/27 04:04:03 1.38
+++ gsm/Makefile.am 2000/02/16 17:38:09
@@ -17,7 +17,7 @@
endif
gnome_session_SOURCES = manager.c manager.h ice.c main.c prop.c save.c \
- command.c session.h remote.c logout.c splash.h splash.c
+ command.c session.h remote.c logout.c splash.h splash.c malloc.c
gnome_session_LDADD=$(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(INTLLIBS) @LIBWRAP_LIBS@
Index: gsm/main.c
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/main.c,v
retrieving revision 1.17
diff -u -b -B -a -u -r1.17 main.c
--- gsm/main.c 1999/12/29 07:15:45 1.17
+++ gsm/main.c 2000/02/16 17:38:09
@@ -90,6 +90,8 @@
char **leftovers;
Session *the_session;
+ malloc_init();
+
/* We do this as a separate executable, and do it first so that we
* make sure we have a absolutely clean setup if the user blows
* their configs away with the Ctrl-Shift hotkey.
Index: gsm/malloc.c
===================================================================
RCS file: malloc.c
diff -N malloc.c
--- /dev/null Tue May 5 16:32:27 1998
+++ malloc.c Wed Feb 16 12:38:09 2000
@@ -0,0 +1,66 @@
+#include <config.h>
+#include <glib.h>
+#include <gmodule.h>
+#include <stdio.h>
+#include <malloc.h>
+
+#ifdef LIBCNAME
+static gpointer (*libc_malloc)(guint size) = NULL;
+static void (*libc_free)(gpointer addr) = NULL;
+
+static gchar buffer[10000];
+static guint buffer_size = sizeof (buffer) / sizeof (buffer[0]);
+static guint buffer_next_free = 0;
+
+gpointer
+malloc (guint size)
+{
+ if (libc_malloc)
+ {
+ printf ("using builtin malloc.\n");
+ /* Your intercepting code here */
+ return libc_malloc (size);
+ }
+ else
+ {
+ gpointer retval = buffer + buffer_next_free;
+ printf("Allocating buffer pos: %d, Size %d\n", buffer_next_free, size);
+ if (buffer_next_free + size > buffer_size)
+ {
+ printf ("malloc: Error while bootstrapping glibc malloc.\n");
+ abort ();
+ }
+ buffer_next_free += size;
+ return retval;
+ }
+}
+
+void
+free (gpointer addr)
+{
+ /* This function is needed, even when not intercepted */
+ if (libc_free && ((guchar*)addr < (guchar*)buffer ||
+ (guchar*)addr > ((guchar*)buffer + buffer_size)) )
+ {
+ printf ("using builtin free.\n");
+ libc_free (addr);
+ }
+ else
+ printf("Freeing buffer pos: %d", (guchar*)addr - (guchar*)buffer);
+}
+
+
+#endif /* LIBCNAME */
+
+void
+malloc_init()
+{
+#ifdef LIBCNAME
+ gpointer addr;
+ GModule *module = g_module_open (LIBCNAME, 0);
+ g_assert (g_module_symbol (module, "malloc", &libc_malloc));
+ g_assert (g_module_symbol (module, "free", &libc_free));
+ g_module_close (module);
+#endif /* LIBCNAME */
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]