source: rtems/cpukit/libcsupport/src/rtems_memalign.c @ e0a66c15

4.104.114.95
Last change on this file since e0a66c15 was e0a66c15, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 17:28:27

2008-01-29 Joel Sherrill <joel.sherrill@…>

  • libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h, libcsupport/src/malloc_walk.c, libcsupport/src/posix_memalign.c, libcsupport/src/realloc.c, score/src/heapwalk.c: Add rtems_memalign as helper and as exposed nmemalign variant with few restrictions. Also turn on compilation of _Heap_Walk but make forced calls to it conditionally compiled. This should allow more flexibility to the user as to run-time checking of the heap.
  • libcsupport/src/rtems_memalign.c: New file.
  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[e0a66c15]1/*
2 *  rtems_memalign() - Raw aligned allocate from Protected Heap
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#ifdef RTEMS_NEWLIB
19#include "malloc_p.h"
20
21#include <stdlib.h>
22#include <errno.h>
23
24int rtems_memalign(
25  void   **pointer,
26  size_t   alignment,
27  size_t   size
28)
29{
30  void *return_this;
31
32  /*
33   *  Parameter error checks
34   */
35  if ( !pointer )
36    return EINVAL;
37
38  *pointer = NULL;
39
40  /*
41   *  Do not attempt to allocate memory if not in correct system state.
42   */
43  if ( _System_state_Is_up(_System_state_Get()) &&
44       !malloc_is_system_state_OK() )
45    return EINVAL;
46
47  /*
48   *
49   *  If some free's have been deferred, then do them now.
50   */
51  malloc_deferred_frees_process();
52
53  #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
54    /*
55     *  If the support for a boundary area at the end of the heap
56     *  block allocated is turned on, then adjust the size.
57     */
58    if (rtems_malloc_boundary_helpers)
59      size += (*rtems_malloc_boundary_helpers->overhead)();
60  #endif
61
62  /*
63   *  Perform the aligned allocation requested
64   */
65
66  return_this = _Protected_heap_Allocate_aligned(
67    &RTEMS_Malloc_Heap,
68    size,
69    alignment
70  );
71  if ( !return_this )
72    return ENOMEM;
73
74  /*
75   *  If configured, update the more involved statistics
76   */
77  if ( rtems_malloc_statistics_helpers )
78    (*rtems_malloc_statistics_helpers->at_malloc)(pointer);
79
80  #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
81    /*
82     * If configured, set the boundary area
83     */
84    if (rtems_malloc_boundary_helpers)
85      (*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);
86  #endif
87
88  *pointer = return_this;
89  return 0;
90}
91#endif
Note: See TracBrowser for help on using the repository browser.