Changeset be31de7 in rtems


Ignore:
Timestamp:
May 25, 2006, 5:36:31 PM (14 years ago)
Author:
Eric Norum <WENorum@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
ebbe2af2
Parents:
4bee7d9c
Message:

Provide customisable mbuf allocation.
Patch from Steven Johnson <sjohnson@…>

Location:
cpukit
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r4bee7d9c rbe31de7  
     12006-05-25      Eric Norum <norume@aps.anl.gov>
     2
     3    * libnetworking/Makefile.am,
     4    libnetworking/Makefile.in,
     5    libnetworking/rtems/rtems_bsdnet.h,
     6    libnetworking/rtems/rtems_glue.c,
     7    libnetworking/rtems/rtems_malloc_mbuf.c: Provide customisable mbuf
     8        allocation.  Patch from Steven Johnson <sjohnson@sakuraindustries.com>
     9
    1102006-05-16      Ralf Corsépius <ralf.corsepius@rtems.org>
    211
  • cpukit/libcsupport/src/malloc.c

    r4bee7d9c rbe31de7  
    3636#include <rtems/chain.h>
    3737
     38#ifdef MALLOC_ARENA_CHECK
     39#define SENTINELSIZE    12
     40#define SENTINEL       "\xD1\xAC\xB2\xF1" "BITE ME"
     41#define CALLCHAINSIZE 5
     42struct mallocNode {
     43    struct mallocNode *back;
     44    struct mallocNode *forw;
     45    int                callChain[CALLCHAINSIZE];
     46    size_t             size;
     47    void              *memory;
     48};
     49static struct mallocNode mallocNodeHead = { &mallocNodeHead, &mallocNodeHead };
     50void reportMallocError(const char *msg, struct mallocNode *mp)
     51{
     52    unsigned char *sp = (unsigned char *)mp->memory + mp->size;
     53    int i, ind = 0;
     54    static char cbuf[500];
     55    ind += sprintf(cbuf+ind, "Malloc Error: %s\n", msg);
     56    if ((mp->forw->back != mp) || (mp->back->forw != mp))
     57        ind += sprintf(cbuf+ind, "mp:0x%x  mp->forw:0x%x  mp->forw->back:0x%x  mp->back:0x%x  mp->back->forw:0x%x\n",
     58                        mp, mp->forw, mp->forw->back, mp->back, mp->back->forw);
     59    if (mp->memory != (mp + 1))
     60        ind += sprintf(cbuf+ind, "mp+1:0x%x  ", mp + 1);
     61    ind += sprintf(cbuf+ind, "mp->memory:0x%x  mp->size:%d\n", mp->memory, mp->size);
     62    if (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0) {
     63        ind += sprintf(cbuf+ind, "mp->sentinel: ");
     64        for (i = 0 ; i < SENTINELSIZE ; i++)
     65            ind += sprintf(cbuf+ind, " 0x%x", sp[i]);
     66        ind += sprintf(cbuf+ind, "\n");
     67    }
     68    ind += sprintf(cbuf+ind, "Call chain:");
     69    for (i = 0 ; i < CALLCHAINSIZE ; i++) {
     70        if (mp->callChain[i] == 0)
     71            break;
     72        ind += sprintf(cbuf+ind, " 0x%x", mp->callChain[i]);
     73    }
     74    printk("\n\n%s\n\n", cbuf);
     75}
     76#endif
     77
    3878Chain_Control RTEMS_Malloc_GC_list;
    3979
     
    191231   */
    192232
     233#ifdef MALLOC_ARENA_CHECK
     234  size += sizeof(struct mallocNode) + SENTINELSIZE;
     235#endif
    193236  status = rtems_region_get_segment(
    194237    RTEMS_Malloc_Heap,
     
    262305#endif
    263306
     307#ifdef MALLOC_ARENA_CHECK
     308  {
     309  struct mallocNode *mp = (struct mallocNode *)return_this;
     310  int key, *fp, *nfp, i;
     311  rtems_interrupt_disable(key);
     312  mp->memory = mp + 1;
     313  return_this = mp->memory;
     314  mp->size = size - (sizeof(struct mallocNode) + SENTINELSIZE);
     315  fp = (int *)&size - 2;
     316  for (i = 0 ; i < CALLCHAINSIZE ; i++) {
     317    mp->callChain[i] = fp[1];
     318    nfp = (int *)(fp[0]);
     319    if((nfp <= fp) || (nfp > (int *)(1 << 24)))
     320     break;
     321    fp = nfp;
     322  }
     323  while (i < CALLCHAINSIZE)
     324    mp->callChain[i++] = 0;
     325  memcpy((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE);
     326  mp->forw = mallocNodeHead.forw;
     327  mp->back = &mallocNodeHead;
     328  mallocNodeHead.forw->back = mp;
     329  mallocNodeHead.forw = mp;
     330  rtems_interrupt_enable(key);
     331  }
     332#endif
    264333  return return_this;
    265334}
     
    319388  }
    320389
     390#ifdef MALLOC_ARENA_CHECK
     391  {
     392  void *np;
     393  np = malloc(size);
     394  if (!np) return np;
     395  memcpy(np,ptr,size);
     396  free(ptr);
     397  return np;
     398  }
     399#endif
    321400  status =
    322401    rtems_region_resize_segment( RTEMS_Malloc_Heap, ptr, size, &old_size );
     
    379458  }
    380459
     460#ifdef MALLOC_ARENA_CHECK
     461  {
     462  struct mallocNode *mp = (struct mallocNode *)ptr - 1;
     463  struct mallocNode *mp1;
     464  int key;
     465  rtems_interrupt_disable(key);
     466  if ((mp->memory != (mp + 1))
     467   || (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
     468    reportMallocError("Freeing with inconsistent pointer/sentinel", mp);
     469  mp1 = mallocNodeHead.forw;
     470  while (mp1 != &mallocNodeHead) {
     471    if (mp1 == mp)
     472      break;
     473    mp1 = mp1->forw;
     474  }
     475  if (mp1 != mp)
     476    reportMallocError("Freeing, but not on allocated list", mp);
     477  mp->forw->back = mp->back;
     478  mp->back->forw = mp->forw;
     479  mp->back = mp->forw = NULL;
     480  ptr = mp;
     481  rtems_interrupt_enable(key);
     482  }
     483#endif
    381484#ifdef MALLOC_STATS
    382485  {
     
    395498  }
    396499}
     500
     501#ifdef MALLOC_ARENA_CHECK
     502void checkMallocArena(void)
     503{
     504    struct mallocNode *mp = mallocNodeHead.forw;
     505    int key;
     506    rtems_interrupt_disable(key);
     507    while (mp != &mallocNodeHead) {
     508        if ((mp->forw->back != mp)
     509         || (mp->back->forw != mp))
     510            reportMallocError("Pointers mangled", mp);
     511        if((mp->memory != (mp + 1))
     512         || (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
     513            reportMallocError("Inconsistent pointer/sentinel", mp);
     514        mp = mp->forw;
     515    }
     516    rtems_interrupt_enable(key);
     517}
     518#endif
     519
    397520/* end if RTEMS_NEWLIB */
    398521#endif
  • cpukit/libnetworking/Makefile.am

    r4bee7d9c rbe31de7  
    119119
    120120libnetworking_a_SOURCES += rtems/sghostname.c rtems/issetugid.c \
    121     rtems/rtems_glue.c rtems/rtems_syscall.c \
     121    rtems/rtems_glue.c rtems/rtems_malloc_mbuf.c rtems/rtems_syscall.c \
    122122    rtems/rtems_bootp.c rtems/rtems_dhcp.c \
    123123    rtems/rtems_showmbuf.c rtems/rtems_showroute.c rtems/rtems_showifstat.c \
  • cpukit/libnetworking/rtems/rtems_bsdnet.h

    r4bee7d9c rbe31de7  
    261261void rtems_bsdnet_malloc_starvation(void);
    262262
     263/*
     264 * mbuf malloc interface to enable custom allocation of mbuf's
     265 *
     266 * May be declared in user code.  If not, then the default is to
     267 * malloc.
     268 */
     269void* rtems_bsdnet_malloc_mbuf(size_t size, int type);
     270
     271/*
     272 * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist
     273 * in allocation of the structure.
     274 */
     275#define MBUF_MALLOC_NMBCLUSTERS (0)
     276#define MBUF_MALLOC_MCLREFCNT   (1)
     277#define MBUF_MALLOC_MBUF        (2)
     278
    263279#endif /* _RTEMS_BSDNET_H */
  • cpukit/libnetworking/rtems/rtems_glue.c

    r4bee7d9c rbe31de7  
    150150         * Set up mbuf cluster data strutures
    151151         */
    152         p = malloc ((nmbclusters*MCLBYTES)+MCLBYTES-1);
     152        p = rtems_bsdnet_malloc_mbuf ((nmbclusters*MCLBYTES)+MCLBYTES-1, MBUF_MALLOC_NMBCLUSTERS);
    153153        if (p == NULL) {
    154154                printf ("Can't get network cluster memory.\n");
     
    164164        }
    165165        mbstat.m_clusters = nmbclusters;
    166         mclrefcnt = malloc (nmbclusters);
     166        mclrefcnt = rtems_bsdnet_malloc_mbuf (nmbclusters, MBUF_MALLOC_MCLREFCNT);
    167167        if (mclrefcnt == NULL) {
    168168                printf ("Can't get mbuf cluster reference counts memory.\n");
     
    175175         */
    176176
    177         p = malloc(nmbuf * MSIZE + MSIZE - 1);
     177        p = rtems_bsdnet_malloc_mbuf(nmbuf * MSIZE + MSIZE - 1,MBUF_MALLOC_MBUF);
    178178        p = (char *)(((unsigned int)p + MSIZE - 1) & ~(MSIZE - 1));
    179179        if (p == NULL) {
Note: See TracChangeset for help on using the changeset viewer.