Index: trunk/src/VBox/Devices/Network/slirp/debug.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/debug.c	(revision 38402)
+++ trunk/src/VBox/Devices/Network/slirp/debug.c	(revision 38492)
@@ -30,4 +30,6 @@
 #include <iprt/string.h>
 #include <iprt/stream.h>
+#include <iprt/critsect.h>
+#include "zone.h"
 
 #ifdef DEBUG
@@ -362,4 +364,44 @@
 }
 
+/*
+ * Prints zone state
+ */
+static DECLCALLBACK(size_t)
+printMbufZone(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
+                 const char *pszType, void const *pvValue,
+                 int cchWidth, int cchPrecision, unsigned fFlags,
+                 void *pvUser)
+{
+    size_t cb = 0;
+    const uma_zone_t zone = (const uma_zone_t)pvValue;
+    AssertReturn(RTStrCmp(pszType, "mzone") == 0, 0);
+    if (!zone)
+        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:NULL]");
+    else
+        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:%p name:%s, master_zone:%R[mzone]]",
+                          zone, zone->name, zone->master_zone);
+    return cb;
+}
+
+/*
+ * Prints zone's item state
+ */
+static DECLCALLBACK(size_t)
+printMbufZoneItem(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
+                 const char *pszType, void const *pvValue,
+                 int cchWidth, int cchPrecision, unsigned fFlags,
+                 void *pvUser)
+{
+    size_t cb = 0;
+    const struct item *it = (const struct item *)pvValue;
+    AssertReturn(RTStrCmp(pszType, "mzoneitem") == 0, 0);
+    if (!it)
+        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[item:NULL]");
+    else
+        cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[iptem:%p ref_count:%d, zone:%R[mzone]]",
+                          it, it->ref_count, it->zone);
+    return cb;
+}
+
 static DECLCALLBACK(size_t)
 print_networkevents(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
@@ -420,17 +462,13 @@
     {
 
-        rc = RTStrFormatTypeRegister("natsock", print_socket, NULL);
-        AssertRC(rc);
+        rc = RTStrFormatTypeRegister("natsock", print_socket, NULL);            AssertRC(rc);
         rc = RTStrFormatTypeRegister("natwinnetevents",
-                                     print_networkevents, NULL);
-        AssertRC(rc);
-        rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL);
-        AssertRC(rc);
-        rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL);
-        AssertRC(rc);
-        rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL);
-        AssertRC(rc);
-        rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL);
-        AssertRC(rc);
+                                     print_networkevents, NULL);                AssertRC(rc);
+        rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL);       AssertRC(rc);
+        rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL); AssertRC(rc);
+        rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL);          AssertRC(rc);
+        rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL);                  AssertRC(rc);
+        rc = RTStrFormatTypeRegister("mzone", printMbufZone, NULL);             AssertRC(rc);
+        rc = RTStrFormatTypeRegister("mzoneitem", printMbufZoneItem, NULL);     AssertRC(rc);
         g_fFormatRegistered = 1;
     }
Index: trunk/src/VBox/Devices/Network/slirp/misc.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/misc.c	(revision 38402)
+++ trunk/src/VBox/Devices/Network/slirp/misc.c	(revision 38492)
@@ -27,4 +27,5 @@
 #define WANT_SYS_IOCTL_H
 #include <slirp.h>
+#include "zone.h"
 
 #ifndef HAVE_INET_ATON
@@ -97,37 +98,4 @@
 
 
-#define ITEM_MAGIC 0xdead0001
-struct item
-{
-    uint32_t magic;
-    uma_zone_t zone;
-    uint32_t ref_count;
-    LIST_ENTRY(item) list;
-};
-
-#define ZONE_MAGIC 0xdead0002
-struct uma_zone
-{
-    uint32_t magic;
-    PNATState pData; /* to minimize changes in the rest of UMA emulation code */
-    RTCRITSECT csZone;
-    const char *name;
-    size_t size; /* item size */
-    ctor_t pfCtor;
-    dtor_t pfDtor;
-    zinit_t pfInit;
-    zfini_t pfFini;
-    uma_alloc_t pfAlloc;
-    uma_free_t pfFree;
-    int max_items;
-    int cur_items;
-    LIST_HEAD(RT_NOTHING, item) used_items;
-    LIST_HEAD(RT_NOTHING, item) free_items;
-    uma_zone_t master_zone;
-    void *area;
-    /** Needs call pfnXmitPending when memory becomes available if @c true.
-     * @remarks Only applies to the master zone (master_zone == NULL) */
-    bool fDoXmitPending;
-};
 
 
@@ -143,4 +111,5 @@
 DECLINLINE(void) slirp_zone_check_and_send_pending(uma_zone_t zone)
 {
+    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
     if (   zone->fDoXmitPending
         && zone->master_zone == NULL)
@@ -154,4 +123,5 @@
         rc2 = RTCritSectEnter(&zone->csZone); AssertRC(rc2);
     }
+    LogFlowFuncLeave();
 }
 
@@ -164,4 +134,5 @@
     int rc;
 
+    LogFlowFunc(("ENTER: %R[mzone], size:%d, pflags:%p, %RTbool\n", zone, size, pflags, fWait));
     RTCritSectEnter(&zone->csZone);
     for (;;)
@@ -229,4 +200,5 @@
     }
     RTCritSectLeave(&zone->csZone);
+    LogFlowFunc(("LEAVE: %p\n", ret));
     return ret;
 }
@@ -240,4 +212,5 @@
     Assert(item);
     it = &((struct item *)item)[-1];
+    LogFlowFunc(("ENTER: item:%p(%R[mzoneitem]), size:%d, flags:%RX8\n", item, it, size, flags));
     Assert(it->magic == ITEM_MAGIC);
     zone = it->zone;
@@ -260,4 +233,5 @@
     slirp_zone_check_and_send_pending(zone); /* may exit+enter the cs! */
     RTCritSectLeave(&zone->csZone);
+    LogFlowFuncLeave();
 }
 
@@ -265,5 +239,8 @@
                        ctor_t ctor, dtor_t dtor, zinit_t init, zfini_t fini, int flags1, int flags2)
 {
-    uma_zone_t zone = RTMemAllocZ(sizeof(struct uma_zone));
+    uma_zone_t zone = NULL;
+    LogFlowFunc(("ENTER: name:%s size:%d, ctor:%p, dtor:%p, init:%p, fini:%p, flags1:%RX32, flags2:%RX32\n",
+                name, ctor, dtor, init, fini, flags1, flags2));
+    zone = RTMemAllocZ(sizeof(struct uma_zone));
     Assert((pData));
     zone->magic = ZONE_MAGIC;
@@ -278,4 +255,5 @@
     zone->pfFree = slirp_uma_free;
     RTCritSectInit(&zone->csZone);
+    LogFlowFunc(("LEAVE: %R[mzone]\n", zone));
     return zone;
 
@@ -286,7 +264,12 @@
     uma_zone_t zone;
     Assert(master);
+    LogFlowFunc(("ENTER: name:%s ctor:%p, dtor:%p, init:%p, fini:%p, master:%R[mzone]\n",
+                name, ctor, dtor, init, fini, master));
     zone = RTMemAllocZ(sizeof(struct uma_zone));
     if (zone == NULL)
+    {
+        LogFlowFunc(("LEAVE: %R[mzone]\n", NULL));
         return NULL;
+    }
 
     Assert((master && master->pData));
@@ -303,4 +286,5 @@
     zone->master_zone = master;
     RTCritSectInit(&zone->csZone);
+    LogFlowFunc(("LEAVE: %R[mzone]\n", zone));
     return zone;
 }
@@ -310,4 +294,5 @@
     int i = 0;
     struct item *it;
+    LogFlowFunc(("ENTER: zone:%R[mzone], max:%d\n", zone, max));
     zone->max_items = max;
     zone->area = RTMemAllocZ(max * (sizeof(struct item) + zone->size + sizeof(uint32_t)));
@@ -320,15 +305,19 @@
         LIST_INSERT_HEAD(&zone->free_items, it, list);
     }
-
+    LogFlowFuncLeave();
 }
 
 void uma_zone_set_allocf(uma_zone_t zone, uma_alloc_t pfAlloc)
 {
-   zone->pfAlloc = pfAlloc;
+    LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfAlloc));
+    zone->pfAlloc = pfAlloc;
+    LogFlowFuncLeave();
 }
 
 void uma_zone_set_freef(uma_zone_t zone, uma_free_t pfFree)
 {
-   zone->pfFree = pfFree;
+    LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfFree));
+    zone->pfFree = pfFree;
+    LogFlowFuncLeave();
 }
 
@@ -337,9 +326,12 @@
     /** @todo (vvl) this function supposed to work with special zone storing
     reference counters */
-    struct item *it = (struct item *)mem; /* 1st element */
+    struct item *it = NULL;
+    LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p\n", zone, mem));
+    it = (struct item *)mem; /* 1st element */
     Assert(mem != NULL);
     Assert(zone->magic == ZONE_MAGIC);
     /* for returning pointer to counter we need get 0 elemnt */
     Assert(it[-1].magic == ITEM_MAGIC);
+    LogFlowFunc(("LEAVE: %p\n", &it[-1].ref_count));
     return &it[-1].ref_count;
 }
@@ -349,6 +341,10 @@
     void *mem;
     Assert(zone->magic == ZONE_MAGIC);
+    LogFlowFunc(("ENTER: zone:%R[mzone], args:%p, how:%RX32\n", zone, args, how));
     if (zone->pfAlloc == NULL)
+    {
+        LogFlowFunc(("LEAVE: NULL\n"));
         return NULL;
+    }
     RTCritSectEnter(&zone->csZone);
     mem = zone->pfAlloc(zone, zone->size, NULL, 0);
@@ -359,4 +355,5 @@
     }
     RTCritSectLeave(&zone->csZone);
+    LogFlowFunc(("LEAVE: %p\n", mem));
     return mem;
 }
@@ -364,5 +361,7 @@
 void uma_zfree(uma_zone_t zone, void *item)
 {
+    LogFlowFunc(("ENTER: zone:%R[mzone], item:%p\n", zone, item));
     uma_zfree_arg(zone, item, NULL);
+    LogFlowFuncLeave();
 }
 
@@ -373,4 +372,5 @@
     Assert((zone->pfFree));
     Assert((mem));
+    LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p, flags:%p\n", zone, mem, flags));
 
     RTCritSectEnter(&zone->csZone);
@@ -381,4 +381,5 @@
     zone->pfFree(mem,  0, 0);
     RTCritSectLeave(&zone->csZone);
+    LogFlowFuncLeave();
 }
 
@@ -386,7 +387,9 @@
 {
     int fExhausted;
+    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
     RTCritSectEnter(&zone->csZone);
     fExhausted = (zone->cur_items == zone->max_items);
     RTCritSectLeave(&zone->csZone);
+    LogFlowFunc(("LEAVE: %RTbool\n", fExhausted));
     return fExhausted;
 }
@@ -399,4 +402,5 @@
     /* vvl: Huh? What to do with zone which hasn't got backstore ? */
     Assert((zone->master_zone));
+    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
     master_zone = zone->master_zone;
     while (!LIST_EMPTY(&zone->free_items))
@@ -418,4 +422,5 @@
         RTCritSectLeave(&master_zone->csZone);
     }
+    LogFlowFuncLeave();
 }
 
@@ -423,10 +428,14 @@
 {
     /** @todo (vvl) make it wiser  */
+    LogFlowFunc(("ENTER: mem:%p, arg:%p\n", mem, arg));
     Assert(mem);
     RTMemFree(mem);
+    LogFlowFuncLeave();
 }
 
 void *uma_zalloc(uma_zone_t zone, int len)
 {
+    LogFlowFunc(("ENTER: zone:%R[mzone], len:%d\n", zone, len));
+    LogFlowFunc(("LEAVE: NULL"));
     return NULL;
 }
@@ -436,4 +445,5 @@
     struct mbuf *m;
     size_t size = MCLBYTES;
+    LogFlowFunc(("ENTER: cbMin:%d, ppvBuf:%p, pcbBuf:%p\n", cbMin, ppvBuf, pcbBuf));
     if (cbMin < MSIZE)
         size = MCLBYTES;
@@ -452,4 +462,5 @@
         *ppvBuf = NULL;
         *pcbBuf = 0;
+        LogFlowFunc(("LEAVE: NULL\n"));
         return NULL;
     }
@@ -457,4 +468,5 @@
     *ppvBuf = mtod(m, void *);
     *pcbBuf = size;
+    LogFlowFunc(("LEAVE: %p\n", m));
     return m;
 }
@@ -463,8 +475,10 @@
 {
 
+    LogFlowFunc(("ENTER: m:%p, pu8Buf:%p\n", m, pu8Buf));
     if (   !pu8Buf
         && pu8Buf != mtod(m, uint8_t *))
         RTMemFree(pu8Buf); /* This buffer was allocated on heap */
     m_freem(pData, m);
+    LogFlowFuncLeave();
 }
 
@@ -472,4 +486,5 @@
 {
     RTCritSectEnter(&zone->csZone);
+    LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone));
     LogRel(("NAT: zone(nm:%s, used:%d)\n", zone->name, zone->cur_items));
     if (zone->master_zone)
@@ -478,8 +493,10 @@
     RTCritSectDelete(&zone->csZone);
     RTMemFree(zone);
+    LogFlowFuncLeave();
 }
 
 void m_fini(PNATState pData)
 {
+    LogFlowFuncEnter();
     zone_destroy(pData->zone_mbuf);
     zone_destroy(pData->zone_clust);
@@ -489,4 +506,5 @@
     zone_destroy(pData->zone_jumbo16);
     /** @todo do finalize here.*/
+    LogFlowFuncLeave();
 }
 
Index: trunk/src/VBox/Devices/Network/slirp/misc.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/misc.h	(revision 38402)
+++ trunk/src/VBox/Devices/Network/slirp/misc.h	(revision 38492)
@@ -44,4 +44,5 @@
 struct uma_zone;
 typedef struct uma_zone *uma_zone_t;
+
 typedef void *(*uma_alloc_t)(uma_zone_t, int, u_int8_t *, int);
 typedef void (*uma_free_t)(void *, int, u_int8_t);
Index: trunk/src/VBox/Devices/Network/slirp/zone.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/zone.h	(revision 38492)
+++ trunk/src/VBox/Devices/Network/slirp/zone.h	(revision 38492)
@@ -0,0 +1,54 @@
+/* $Id$ */
+/** @file
+ * NAT - this file is for sharing zone declaration with emu emulation and logging routines.
+ */
+
+/*
+ * Copyright (C) 2006-2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef __ZONE_H__
+# define __ZONE_H__
+
+# define ITEM_MAGIC 0xdead0001
+struct item
+{
+    uint32_t magic;
+    uma_zone_t zone;
+    uint32_t ref_count;
+    LIST_ENTRY(item) list;
+};
+
+# define ZONE_MAGIC 0xdead0002
+struct uma_zone
+{
+    uint32_t magic;
+    PNATState pData; /* to minimize changes in the rest of UMA emulation code */
+    RTCRITSECT csZone;
+    const char *name;
+    size_t size; /* item size */
+    ctor_t pfCtor;
+    dtor_t pfDtor;
+    zinit_t pfInit;
+    zfini_t pfFini;
+    uma_alloc_t pfAlloc;
+    uma_free_t pfFree;
+    int max_items;
+    int cur_items;
+    LIST_HEAD(RT_NOTHING, item) used_items;
+    LIST_HEAD(RT_NOTHING, item) free_items;
+    uma_zone_t master_zone;
+    void *area;
+    /** Needs call pfnXmitPending when memory becomes available if @c true.
+     * @remarks Only applies to the master zone (master_zone == NULL) */
+    bool fDoXmitPending;
+};
+#endif
