Changeset 6efc831 in rtems for cpukit


Ignore:
Timestamp:
Nov 9, 2018, 11:11:11 AM (11 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
9a029ce
Parents:
c1f3c2b8
git-author:
Sebastian Huber <sebastian.huber@…> (11/09/18 11:11:11)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/12/18 12:26:22)
Message:

Add rtems_malloc() and rtems_calloc()

Close #3583.

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/malloc.h

    rc1f3c2b8 r6efc831  
    143143
    144144/**
     145 * @brief Allocates a memory area of the specified size from the heap.
     146 *
     147 * This function is almost identical to malloc(). The only exception is that
     148 * errno is not set in case of a memory allocation failure.
     149 *
     150 * @param[in] size The memory area size in bytes.
     151 *
     152 * @retval NULL The memory allocation failed or @a size is zero.
     153 * @retval otherwise The begin address of the allocated memory area.
     154 */
     155void *rtems_malloc(size_t size)
     156  RTEMS_MALLOCLIKE RTEMS_ALLOC_SIZE(1) RTEMS_WARN_UNUSED_RESULT;
     157
     158/**
     159 * @brief Allocates a memory area for the specified count of elements from the
     160 * heap.
     161 *
     162 * The allocated memory area is fully filled with zero bits.
     163 *
     164 * This function is almost identical to calloc(). The only exception is that
     165 * errno is not set in case of a memory allocation failure.
     166 *
     167 * @param[in] nelem The count of elements.
     168 * @param[in] elsize The size of each elements.
     169 *
     170 * @retval NULL The memory allocation failed or @a nelem is zero or @a elsize
     171 *   is zero.
     172 * @retval otherwise The begin address of the allocated memory area.
     173 */
     174void *rtems_calloc(size_t nelem, size_t elsize)
     175  RTEMS_MALLOCLIKE RTEMS_ALLOC_SIZE_2(1, 2) RTEMS_WARN_UNUSED_RESULT;
     176
     177/**
    145178 * @brief Extends the memory available for the heap using the memory area
    146179 * starting at @a area_begin of size @a area_size bytes.
  • cpukit/libcsupport/src/malloc_deferred.c

    rc1f3c2b8 r6efc831  
    2424#ifdef RTEMS_NEWLIB
    2525#include <stdlib.h>
     26#include <string.h>
    2627
    2728#include "malloc_p.h"
     
    137138  rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context );
    138139}
     140
     141void *rtems_malloc( size_t size )
     142{
     143  if ( size == 0 ) {
     144    return NULL;
     145  }
     146
     147  return rtems_heap_allocate_aligned_with_boundary( size, 0, 0 );
     148}
     149
     150void *rtems_calloc( size_t nelem, size_t elsize )
     151{
     152  size_t  length;
     153  void   *p;
     154
     155  length = nelem * elsize;
     156  p = rtems_malloc( length );
     157  RTEMS_OBFUSCATE_VARIABLE( p );
     158  if ( RTEMS_PREDICT_FALSE( p == NULL ) ) {
     159    return p;
     160  }
     161
     162  return memset( p, 0, length );
     163}
    139164#endif
Note: See TracChangeset for help on using the changeset viewer.