summaryrefslogtreecommitdiffstats
path: root/cpukit/libnetworking/rtems
diff options
context:
space:
mode:
authorEric Norum <WENorum@lbl.gov>2006-05-25 17:36:31 +0000
committerEric Norum <WENorum@lbl.gov>2006-05-25 17:36:31 +0000
commitbe31de713feda36d1da3771df5decaa96088713a (patch)
treed0e0a94c3e92658edad482effc4b086674267069 /cpukit/libnetworking/rtems
parent2006-05-16 Ralf Corsépius <ralf.corsepius@rtems.org> (diff)
downloadrtems-be31de713feda36d1da3771df5decaa96088713a.tar.bz2
Provide customisable mbuf allocation.
Patch from Steven Johnson <sjohnson@sakuraindustries.com>
Diffstat (limited to 'cpukit/libnetworking/rtems')
-rw-r--r--cpukit/libnetworking/rtems/rtems_bsdnet.h16
-rw-r--r--cpukit/libnetworking/rtems/rtems_glue.c6
-rw-r--r--cpukit/libnetworking/rtems/rtems_malloc_mbuf.c33
3 files changed, 52 insertions, 3 deletions
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet.h b/cpukit/libnetworking/rtems/rtems_bsdnet.h
index 7c7c2c8df4..3112779078 100644
--- a/cpukit/libnetworking/rtems/rtems_bsdnet.h
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet.h
@@ -260,4 +260,20 @@ int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority);
*/
void rtems_bsdnet_malloc_starvation(void);
+/*
+ * mbuf malloc interface to enable custom allocation of mbuf's
+ *
+ * May be declared in user code. If not, then the default is to
+ * malloc.
+ */
+void* rtems_bsdnet_malloc_mbuf(size_t size, int type);
+
+/*
+ * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist
+ * in allocation of the structure.
+ */
+#define MBUF_MALLOC_NMBCLUSTERS (0)
+#define MBUF_MALLOC_MCLREFCNT (1)
+#define MBUF_MALLOC_MBUF (2)
+
#endif /* _RTEMS_BSDNET_H */
diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
index dc9fa4bd68..657a2f862e 100644
--- a/cpukit/libnetworking/rtems/rtems_glue.c
+++ b/cpukit/libnetworking/rtems/rtems_glue.c
@@ -149,7 +149,7 @@ bsd_init (void)
/*
* Set up mbuf cluster data strutures
*/
- p = malloc ((nmbclusters*MCLBYTES)+MCLBYTES-1);
+ p = rtems_bsdnet_malloc_mbuf ((nmbclusters*MCLBYTES)+MCLBYTES-1, MBUF_MALLOC_NMBCLUSTERS);
if (p == NULL) {
printf ("Can't get network cluster memory.\n");
return -1;
@@ -163,7 +163,7 @@ bsd_init (void)
mbstat.m_clfree++;
}
mbstat.m_clusters = nmbclusters;
- mclrefcnt = malloc (nmbclusters);
+ mclrefcnt = rtems_bsdnet_malloc_mbuf (nmbclusters, MBUF_MALLOC_MCLREFCNT);
if (mclrefcnt == NULL) {
printf ("Can't get mbuf cluster reference counts memory.\n");
return -1;
@@ -174,7 +174,7 @@ bsd_init (void)
* Set up mbuf data structures
*/
- p = malloc(nmbuf * MSIZE + MSIZE - 1);
+ p = rtems_bsdnet_malloc_mbuf(nmbuf * MSIZE + MSIZE - 1,MBUF_MALLOC_MBUF);
p = (char *)(((unsigned int)p + MSIZE - 1) & ~(MSIZE - 1));
if (p == NULL) {
printf ("Can't get network memory.\n");
diff --git a/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c
new file mode 100644
index 0000000000..d5654c8297
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c
@@ -0,0 +1,33 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define RTEMS_FAST_MUTEX
+
+#ifdef RTEMS_FAST_MUTEX
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+
+/*
+ * Default allocator for mbuf data. Over-ride in user code to change
+ * the way mbuf's are allocated.
+ */
+
+void* rtems_bsdnet_malloc_mbuf(size_t size, int type)
+{
+ return malloc(size);
+}
+
+