diff --git a/src/dmalloc.h b/src/dmalloc.h
index fc85185454e541645b04382655eb5c4418c0e10a..27fa204dcf9e2b0dd222a99e9f02c691543247d1 100644
--- a/src/dmalloc.h
+++ b/src/dmalloc.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: dmalloc.h,v 1.60 2006/08/05 21:00:40 mast Exp $
+|| $Id: dmalloc.h,v 1.61 2006/08/05 22:30:15 mast Exp $
 */
 
 #ifndef DMALLOC_H
@@ -59,35 +59,35 @@ void really_free_memhdr(struct memhdr *mh);
 void add_marks_to_memhdr(struct memhdr *to,void *ptr);
 
 extern int verbose_debug_malloc;
-extern void dmalloc_trace(void *);
-extern void dmalloc_register(void *, int, LOCATION);
-extern int dmalloc_unregister(void *, int);
-extern void *debug_malloc(size_t, LOCATION);
-extern void *debug_calloc(size_t, size_t, LOCATION);
-extern void *debug_realloc(void *, size_t, LOCATION);
-extern void debug_free(void *, LOCATION, int);
-extern char *debug_strdup(const char *, LOCATION);
+PMOD_EXPORT void dmalloc_trace(void *);
+PMOD_EXPORT void dmalloc_register(void *, int, LOCATION);
+PMOD_EXPORT int dmalloc_unregister(void *, int);
+PMOD_EXPORT void *debug_malloc(size_t, LOCATION);
+PMOD_EXPORT void *debug_calloc(size_t, size_t, LOCATION);
+PMOD_EXPORT void *debug_realloc(void *, size_t, LOCATION);
+PMOD_EXPORT void debug_free(void *, LOCATION, int);
+PMOD_EXPORT char *debug_strdup(const char *, LOCATION);
 void reset_debug_malloc(void);
-int dmalloc_check_allocated (void *p, int must_be_freed);
+PMOD_EXPORT int dmalloc_check_allocated (void *p, int must_be_freed);
 #if 0
 void dmalloc_check_block_free(void *, LOCATION, char *, describe_block_fn *);
 #endif
-extern void dmalloc_free(void *p);
-extern int debug_malloc_touch_fd(int, LOCATION);
-extern int debug_malloc_register_fd(int, LOCATION);
-extern void debug_malloc_accept_leak_fd(int);
-extern int debug_malloc_close_fd(int, LOCATION);
-extern int dmalloc_mark_as_free(void*,int);
-
-void *debug_malloc_update_location(void *, LOCATION);
-void *debug_malloc_update_location_ptr(void *, ptrdiff_t, LOCATION);
+PMOD_EXPORT void dmalloc_free(void *p);
+PMOD_EXPORT int debug_malloc_touch_fd(int, LOCATION);
+PMOD_EXPORT int debug_malloc_register_fd(int, LOCATION);
+PMOD_EXPORT void debug_malloc_accept_leak_fd(int);
+PMOD_EXPORT int debug_malloc_close_fd(int, LOCATION);
+PMOD_EXPORT int dmalloc_mark_as_free(void*,int);
+
+PMOD_EXPORT void *debug_malloc_update_location(void *, LOCATION);
+PMOD_EXPORT void *debug_malloc_update_location_ptr(void *, ptrdiff_t, LOCATION);
 void search_all_memheaders_for_references(void);
 void cleanup_memhdrs(void);
 void cleanup_debug_malloc(void);
 
 /* Beware! names of named memory regions are never ever freed!! /Hubbe */
-void *debug_malloc_name(void *p, const char *fn, int line);
-int debug_malloc_copy_names(void *p, void *p2);
+PMOD_EXPORT void *debug_malloc_name(void *p, const char *fn, int line);
+PMOD_EXPORT int debug_malloc_copy_names(void *p, void *p2);
 char *dmalloc_find_name(void *p);
 
 /* glibc 2.1 defines this as a macro. */
@@ -111,7 +111,7 @@ char *dmalloc_find_name(void *p);
 
 #define xalloc(X) ((void *)debug_malloc_update_location((void *)debug_xalloc(X), DMALLOC_NAMED_LOCATION(" xalloc")))
 #define xfree(X) debug_xfree(debug_malloc_update_location((X), DMALLOC_NAMED_LOCATION(" free")))
-void debug_malloc_dump_references(void *x, int indent, int depth, int flags);
+PMOD_EXPORT void debug_malloc_dump_references(void *x, int indent, int depth, int flags);
 #define dmalloc_touch(TYPE,X) ((TYPE) debug_malloc_pass (X))
 #define dmalloc_touch_named(TYPE,X,NAME) ((TYPE) debug_malloc_pass_named (X, NAME))
 void debug_malloc_dump_fd(int fd);
@@ -121,7 +121,7 @@ void debug_malloc_dump_fd(int fd);
 #define DMALLOC_LINE_ARGS ,char * dmalloc_location
 #define DMALLOC_POS ,DMALLOC_LOCATION()
 #define DMALLOC_PROXY_ARGS ,dmalloc_location
-void dmalloc_accept_leak(void *);
+PMOD_EXPORT void dmalloc_accept_leak(void *);
 #define dmalloc_touch_fd(X) debug_malloc_touch_fd((X),DMALLOC_LOCATION())
 #define dmalloc_register_fd(X) debug_malloc_register_fd((X),DMALLOC_LOCATION())
 #define dmalloc_accept_leak_fd(X) debug_malloc_accept_leak_fd(X)
diff --git a/src/gc.c b/src/gc.c
index 529cda439af27ee3fc23d6332f84d265fdf4aba8..34b70999495538eaa46973918bdeaef58b86eb24 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: gc.c,v 1.276 2006/07/05 02:17:09 mast Exp $
+|| $Id: gc.c,v 1.277 2006/08/05 22:30:14 mast Exp $
 */
 
 #include "global.h"
@@ -332,15 +332,28 @@ static void gc_cycle_pop(void *a);
   (X)->frame = 0;
 #endif
 
-#ifdef PIKE_DEBUG
 #undef get_marker
 #define get_marker debug_get_marker
 #undef find_marker
 #define find_marker debug_find_marker
-#endif
 
 PTR_HASH_ALLOC_FIXED_FILL_PAGES(marker,2)
 
+#undef get_marker
+#define get_marker(X) ((struct marker *) debug_malloc_pass(debug_get_marker(X)))
+#undef find_marker
+#define find_marker(X) ((struct marker *) debug_malloc_pass(debug_find_marker(X)))
+
+PMOD_EXPORT struct marker *pmod_get_marker (void *p)
+{
+  return debug_get_marker (p);
+}
+
+PMOD_EXPORT struct marker *pmod_find_marker (void *p)
+{
+  return debug_find_marker (p);
+}
+
 #if defined (PIKE_DEBUG) || defined (GC_MARK_DEBUG)
 void *gc_found_in = NULL;
 int gc_found_in_type = PIKE_T_UNKNOWN;
@@ -355,11 +368,6 @@ PMOD_EXPORT int gc_external_refs_zapped = 0;
 
 #ifdef PIKE_DEBUG
 
-#undef get_marker
-#define get_marker(X) ((struct marker *) debug_malloc_pass(debug_get_marker(X)))
-#undef find_marker
-#define find_marker(X) ((struct marker *) debug_malloc_pass(debug_find_marker(X)))
-
 int gc_in_cycle_check = 0;
 static unsigned delayed_freed, weak_freed, checked, marked, cycle_checked, live_ref;
 static unsigned max_gc_stack_frames, live_rec, frame_rot, link_search;
diff --git a/src/gc.h b/src/gc.h
index 21d72184366f24730f996c2ea27723724be64ec1..f261defde9b8bbae0a137eb346420d607b0299bf 100644
--- a/src/gc.h
+++ b/src/gc.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: gc.h,v 1.121 2006/03/10 06:58:03 mast Exp $
+|| $Id: gc.h,v 1.122 2006/08/05 22:30:13 mast Exp $
 */
 
 #ifndef GC_H
@@ -254,18 +254,23 @@ struct marker
  * references were lost. */
 #endif
 
-#ifdef PIKE_DEBUG
+PMOD_EXPORT struct marker *pmod_get_marker (void *p);
+PMOD_EXPORT struct marker *pmod_find_marker (void *p);
+
 #define get_marker debug_get_marker
 #define find_marker debug_find_marker
-#endif
 
 #include "block_alloc_h.h"
 PTR_HASH_ALLOC_FIXED_FILL_PAGES(marker, n/a);
 
-#ifdef PIKE_DEBUG
 #undef get_marker
-#define get_marker(X) ((struct marker *) debug_malloc_pass(debug_get_marker(X)))
 #undef find_marker
+
+#ifdef DYNAMIC_MODULE
+#define get_marker(X) ((struct marker *) debug_malloc_pass(pmod_get_marker(X)))
+#define find_marker(X) ((struct marker *) debug_malloc_pass(pmod_find_marker(X)))
+#else
+#define get_marker(X) ((struct marker *) debug_malloc_pass(debug_get_marker(X)))
 #define find_marker(X) ((struct marker *) debug_malloc_pass(debug_find_marker(X)))
 #endif
 
diff --git a/src/pike_memory.c b/src/pike_memory.c
index b2b11b3b1f83bed0dd432f0e9c8f133ed3095ca4..857685eeba71d626e11f1ef405342e66d516478d 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: pike_memory.c,v 1.180 2006/08/05 21:00:40 mast Exp $
+|| $Id: pike_memory.c,v 1.181 2006/08/05 22:30:15 mast Exp $
 */
 
 #include "global.h"
@@ -1926,7 +1926,7 @@ static struct memhdr *low_make_memhdr(void *p, int s, LOCATION location)
   return mh;
 }
 
-void dmalloc_trace(void *p)
+PMOD_EXPORT void dmalloc_trace(void *p)
 {
   struct memhdr *mh = my_find_memhdr(p, 0);
   if (mh) {
@@ -1934,14 +1934,14 @@ void dmalloc_trace(void *p)
   }
 }
 
-void dmalloc_register(void *p, int s, LOCATION location)
+PMOD_EXPORT void dmalloc_register(void *p, int s, LOCATION location)
 {
   mt_lock(&debug_malloc_mutex);
   low_make_memhdr(p, s, location);
   mt_unlock(&debug_malloc_mutex);
 }
 
-void dmalloc_accept_leak(void *p)
+PMOD_EXPORT void dmalloc_accept_leak(void *p)
 {
   if(p)
   {
@@ -1998,7 +1998,7 @@ static int low_dmalloc_unregister(void *p, int already_gone)
   return 0;
 }
 
-int dmalloc_unregister(void *p, int already_gone)
+PMOD_EXPORT int dmalloc_unregister(void *p, int already_gone)
 {
   int ret;
   mt_lock(&debug_malloc_mutex);
@@ -2026,7 +2026,7 @@ static int low_dmalloc_mark_as_free(void *p, int already_gone)
   return 0;
 }
 
-int dmalloc_mark_as_free(void *p, int already_gone)
+PMOD_EXPORT int dmalloc_mark_as_free(void *p, int already_gone)
 {
   int ret;
   mt_lock(&debug_malloc_mutex);
@@ -2065,7 +2065,7 @@ static void flush_blocks_to_free(void)
   }
 }
 
-void *debug_malloc(size_t s, LOCATION location)
+PMOD_EXPORT void *debug_malloc(size_t s, LOCATION location)
 {
   char *m;
 
@@ -2098,7 +2098,7 @@ void *debug_malloc(size_t s, LOCATION location)
   return m;
 }
 
-void *debug_calloc(size_t a, size_t b, LOCATION location)
+PMOD_EXPORT void *debug_calloc(size_t a, size_t b, LOCATION location)
 {
   void *m=debug_malloc(a*b,location);
   if(m)
@@ -2113,7 +2113,7 @@ void *debug_calloc(size_t a, size_t b, LOCATION location)
   return m;
 }
 
-void *debug_realloc(void *p, size_t s, LOCATION location)
+PMOD_EXPORT void *debug_realloc(void *p, size_t s, LOCATION location)
 {
   char *m,*base;
   struct memhdr *mh = 0;
@@ -2146,7 +2146,7 @@ void *debug_realloc(void *p, size_t s, LOCATION location)
   return m;
 }
 
-void debug_free(void *p, LOCATION location, int mustfind)
+PMOD_EXPORT void debug_free(void *p, LOCATION location, int mustfind)
 {
   struct memhdr *mh;
   if(!p) return;
@@ -2218,7 +2218,7 @@ void debug_free(void *p, LOCATION location, int mustfind)
 /* Return true if a block is allocated. If must_be_freed is set,
  * return true if the block is allocated and leaking it is not
  * accepted. */
-int dmalloc_check_allocated (void *p, int must_be_freed)
+PMOD_EXPORT int dmalloc_check_allocated (void *p, int must_be_freed)
 {
   int res;
   struct memhdr *mh;
@@ -2257,12 +2257,12 @@ void dmalloc_check_block_free(void *p, LOCATION location,
 }
 #endif
 
-void dmalloc_free(void *p)
+PMOD_EXPORT void dmalloc_free(void *p)
 {
   debug_free(p, DMALLOC_LOCATION(), 0);
 }
 
-char *debug_strdup(const char *s, LOCATION location)
+PMOD_EXPORT char *debug_strdup(const char *s, LOCATION location)
 {
   char *m;
   long length;
@@ -2534,7 +2534,7 @@ void *dmalloc_find_memblock_base(void *ptr)
 }
 
 /* FIXME: lock the mutex */
-void debug_malloc_dump_references(void *x, int indent, int depth, int flags)
+PMOD_EXPORT void debug_malloc_dump_references(void *x, int indent, int depth, int flags)
 {
   struct memhdr *mh=my_find_memhdr(x,0);
   if(!mh) return;
@@ -2870,7 +2870,7 @@ void initialize_dmalloc(void)
   }
 }
 
-void * debug_malloc_update_location(void *p,LOCATION location)
+PMOD_EXPORT void * debug_malloc_update_location(void *p,LOCATION location)
 {
   if(p)
   {
@@ -2887,9 +2887,9 @@ void * debug_malloc_update_location(void *p,LOCATION location)
   return p;
 }
 
-void * debug_malloc_update_location_ptr(void *p,
-					ptrdiff_t offset,
-					LOCATION location)
+PMOD_EXPORT void * debug_malloc_update_location_ptr(void *p,
+						    ptrdiff_t offset,
+						    LOCATION location)
 {
   if(p)
     debug_malloc_update_location(*(void **)(((char *)p)+offset), location);
@@ -2951,7 +2951,7 @@ LOCATION dynamic_location(const char *file, int line)
 }
 
 
-void * debug_malloc_name(void *p,const char *file, int line)
+PMOD_EXPORT void * debug_malloc_name(void *p,const char *file, int line)
 {
   if(p)
   {
@@ -2973,7 +2973,7 @@ void * debug_malloc_name(void *p,const char *file, int line)
  * one pointer to another. Used by clone() to copy
  * the name(s) of the program.
  */
-int debug_malloc_copy_names(void *p, void *p2)
+PMOD_EXPORT int debug_malloc_copy_names(void *p, void *p2)
 {
   int names=0;
   if(p)
@@ -3025,14 +3025,14 @@ char *dmalloc_find_name(void *p)
   return name;
 }
 
-int debug_malloc_touch_fd(int fd, LOCATION location)
+PMOD_EXPORT int debug_malloc_touch_fd(int fd, LOCATION location)
 {
   if(fd==-1) return fd;
   debug_malloc_update_location( FD2PTR(fd), location);
   return fd;
 }
 
-int debug_malloc_register_fd(int fd, LOCATION location)
+PMOD_EXPORT int debug_malloc_register_fd(int fd, LOCATION location)
 {
   if(fd==-1) return fd;
   dmalloc_unregister( FD2PTR(fd), 1);
@@ -3040,12 +3040,12 @@ int debug_malloc_register_fd(int fd, LOCATION location)
   return fd;
 }
 
-void debug_malloc_accept_leak_fd(int fd)
+PMOD_EXPORT void debug_malloc_accept_leak_fd(int fd)
 {
   dmalloc_accept_leak(FD2PTR(fd));
 }
 
-int debug_malloc_close_fd(int fd, LOCATION location)
+PMOD_EXPORT int debug_malloc_close_fd(int fd, LOCATION location)
 {
   if(fd==-1) return fd;
 #ifdef DMALLOC_TRACK_FREE